State machine: how to stay in a state?

D

David Lamb

Hi,
When writing a vhdl state machine, is there an easy way to stay in a given
state for n clock cycles? I always end up having another process with a
counter, enable the counter in that particular state, and having a <if count
= n> statement in the state transition process. However, the counter needs
to be reset in the state before and it ends up being very confusing. Is it
possible to do this directly in the state machine process?

Thanks

Here is the type of state machine I usually use:

FSM_transitions: PROCESS (reset, clock) -- synchronous FSM
BEGIN
If reset = '1' THEN
state <= Rst;
ELSIF(clock'EVENT AND Clock = '1') THEN
CASE state IS
WHEN Rst =>
state <= Idle;
WHEN Finish =>
state <= Idle;
END CASE;
END IF;
END PROCESS;

FSM_OUTPUTS: PROCESS(state)
BEGIN
CASE state IS
WHEN Rst =>
count_reset <= '1';
WHEN Finish =>
Done <= '1';
END CASE;
END PROCESS;
 
M

MM

David,

Here is your code slightly modified:

FSM_transitions: PROCESS (reset, clock) -- synchronous FSM
variable count :integer;
BEGIN
If reset = '1' THEN
state <= Rst;
ELSIF(clock'EVENT AND Clock = '1') THEN
CASE state IS
WHEN Rst =>
count := IDLE_TIME;
state <= Idle;
WHEN Idle =>
count := count -1;
if count=0 then
state <= Finish;
count :=IDLE_TIME;
end if;
WHEN Finish =>
state <= Idle;
END CASE;
END IF;
END PROCESS;

Remember to watch where you reset the counter so it works correctly every
time.


/Mikhail
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top