I am a novice in VHDL. In one of my assignments I needed to implement a state machine in a State Table method using VHDL. So i wrote the following code for the architechture entity :
X,Y are input bits basically this is a moore machine which accepts two inputs and outputs a bit.
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 reports an error: Integer literal 3 is not of type sub-array #3 of StateTable.
I have googled extensively and am not able to find a solution for this. How do I use multidimensional arrays in VHDL?
The StateTable
type is declared as multi-dimentional array of integer
type:
type StateTable is array(integer range<>,bit range<>,bit range<>) of integer;
The the constant created from this type is assigned with an array that does not have the required levels in:
constant ST : StateTable(0 to 3,'0' to '1','0' to '1') := ( (3,0,1,0), ...
So try adding levels in the constant value, like:
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)));
The index value may be used when creating the constant, to make it clearer what values are assigned to different elements in the array:
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)));