T
Thomas Heller
I have a statemachine that needs to maintain each current state for a
certain time, then switch to another state.
To save tedious typing, I wrote a helper procedure that I call
with
- the state signal instance,
- the next state value,
- the counter signal instance which is used to count the remaining
clock cycles,
- and the number of clock cycles to wait.
Here is the procedure:
procedure advance_state (
signal state : inout state_type;
constant next_state : in state_type;
signal counter : inout integer range 0 to 1000;
constant dt : in integer)
is
begin
if counter = dt then
state <= next_state;
counter <= 0;
end if;
end advance_state;
and here a snippet of the state machine code:
process(clock)
begin
if rising_edge(clock) then
case state is
when IDLE =>
if we = '1' then
state <= START_A;
counter <= 0;
end if;
when START_A => advance_state(state, START_B, counter, 2000);
....
when START_B => advance_state(state, START_C, counter, 2000);
....
when START_C => advance_state(state, WRITE_A, counter, 2000);
....
Code like this works fine when synthesized in ISE14.1 for a Spartan6
device, but it does not work for Spartan3.
Does anyone see a problem with the above?
Are there better ways to implement a state machine with state-duration?
Thanks,
Thomas
certain time, then switch to another state.
To save tedious typing, I wrote a helper procedure that I call
with
- the state signal instance,
- the next state value,
- the counter signal instance which is used to count the remaining
clock cycles,
- and the number of clock cycles to wait.
Here is the procedure:
procedure advance_state (
signal state : inout state_type;
constant next_state : in state_type;
signal counter : inout integer range 0 to 1000;
constant dt : in integer)
is
begin
if counter = dt then
state <= next_state;
counter <= 0;
end if;
end advance_state;
and here a snippet of the state machine code:
process(clock)
begin
if rising_edge(clock) then
case state is
when IDLE =>
if we = '1' then
state <= START_A;
counter <= 0;
end if;
when START_A => advance_state(state, START_B, counter, 2000);
....
when START_B => advance_state(state, START_C, counter, 2000);
....
when START_C => advance_state(state, WRITE_A, counter, 2000);
....
Code like this works fine when synthesized in ISE14.1 for a Spartan6
device, but it does not work for Spartan3.
Does anyone see a problem with the above?
Are there better ways to implement a state machine with state-duration?
Thanks,
Thomas