【问题标题】:Multiple Input State Table method多输入状态表法
【发布时间】:2014-11-10 10:41:45
【问题描述】:

我是 VHDL 的新手。在我的一项任务中,我需要使用 VHDL 在状态表方法中实现状态机。所以我为架构实体编写了以下代码:

X,Y 基本上是输入位,这是一个接受两个输入并输出一个位的摩尔机器。

   architecture Table of SM1_2 is
  type StateTable is array(integer range<>,bit range<>,bit range<>) of integer;
  type OutTable is array(integer range<>) of bit;
  signal State,NextState : integer := 0;
  constant ST: StateTable(0 to 3,'0' to '1','0' to '1'):=
    ((3,0,1,0),(2,0,1,1),(3,0,1,1),(2,0,1,0));
  constant OT: OutTable(0 to 3):=
  ('0','1','1','0');
begin                               --Concurrent Statements
  NextState <= ST(State,X,Y);       --Next state from state table
  Z <= OT(State);  

ModelSim 报错:Integer literal 3 is not of type sub-array #3 of StateTable.

我已经广泛搜索,但无法找到解决方案。如何在 VHDL 中使用多维数组?

【问题讨论】:

  • 我的猜测是 X 或 Y 是整数而不是位,但如果没有其余的声明或提示哪一行包含错误,我们只能在黑暗中拍摄。在仍然显示错误的同时尽可能简化您的来源,然后发布。
  • 刚刚编辑。 @BrianDrummond 你能看一下吗?
  • NextState 不应该被初始化,它不是一个寄存器。
  • @Paebbels 你能告诉我为什么吗?我也在哪里初始化它?
  • 信号State映射到一个寄存器,在大多数平台上可以有一个初始值和一个复位值。信号/线NextState 是一个组合信号。这些信号在实际硬件中不能有初始值。您的声明 signal State,NextState : integer := 0; 将值 0 分配给 NextState,但不分配给 State,因此交换名称或每个信号名称使用一行。不默认纯线也更适合模拟:现在可以看到未连接的信号,因为它们是用“U”初始化的。经验法则:只有映射到寄存器的信号才有默认值。

标签: arrays multidimensional-array vhdl state-machine


【解决方案1】:

StateTable 类型被声明为integer 类型的多维数组:

type StateTable is array(integer range<>,bit range<>,bit range<>) of integer;

从此类型创建的常量分配有一个数组,该数组在以下位置没有所需的级别:

constant ST : StateTable(0 to 3,'0' to '1','0' to '1') := ( (3,0,1,0), ...

因此尝试在常量值中添加级别,例如:

constant ST: StateTable(0 to 3,'0' to '1','0' to '1'):=
  (((3, 0), (1, 0)), 
   ((2, 0), (1, 1)), 
   ((3, 0), (1, 1)), 
   ((2, 0), (1, 0)));

在创建常量时可以使用索引值,以便更清楚地为数组中的不同元素分配哪些值:

constant ST: StateTable(0 to 3,'0' to '1','0' to '1'):=
  (0 => ('0' => ('0' => 3, '1' => 0),
         '1' => ('0' => 1, '1' => 0)),
   1 => ('0' => ('0' => 2, '1' => 0),
         '1' => ('0' => 1, '1' => 1)),
   2 => ('0' => ('0' => 3, '1' => 0),
         '1' => ('0' => 1, '1' => 1)),
   3 => ('0' => ('0' => 2, '1' => 0),
         '1' => ('0' => 1, '1' => 0)));

【讨论】:

  • 非常感谢! @MortenZilmer
【解决方案2】:

您还可以使用嵌套数组来构建状态表:

constant state_cnt : positive := 4;
type t_inputtable is array (bit range <>, bit range <>) of natural range 0 to state_cnt-1;
type_t_statetable is array (natural range 0 to state_cnt-1) of t_inputtable;

constant statetable is t_statetable := (
--state   X,   Y   next state
  0 => (('0', '0') => 0,
        ('0', '1') => 1,
        ('1', '0') => 2,
        others => 0),
  1 => (('0', '0') => 0,
        ('0', '1') => 3,
        ('1', '0') => 2,
        others => 1),
  -- ...
  );

 nextState <= statetable(State)(X, Y);

希望我在输入这行时没有记错。
你也可以实现一个输出记录:

type t_outputtable is record
  next : natural range 0 to state_cnt-1;
  O1 : bit;
  O2 : bit;
end record;
type t_inputtable is array (bit range <>, bit range <>) of t_outputtable;
type_t_statetable is array (natural range 0 to state_cnt-1) of t_inputtable;

nextState <= statetable(State)(X, Y).next;
Output1 <= statetable(State)(X, Y).O1;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2018-06-13
    • 1970-01-01
    • 2020-04-13
    • 2019-03-22
    • 1970-01-01
    • 2022-01-12
    相关资源
    最近更新 更多