Altera_Forum
Honored Contributor
14 years agoDown Counting State Machine problem
Greetings
I have a state machine that needs to count down from a given number (0-9) while at the same time toggling back and fourth to another state machine. So if I have the number three come in. I need it to go into state 1 count down (1 second), subtract one, go into state 2 where it is delayed one second, return to state 1 where it will delay 1 second, subtract one (It would be 1 now) and return once again to state 2, where it would delay and finally return to state 2 where the last one will be subratected, it will have a final 1 second delay and exit to the next state after hitting zero. Here is my code. apparently if I load three into it. It will delay the one second for the first number but the 2 and the 1 only have one clock pulse before going to zero and exiting.when HighError2 =>
if (shortwait = 0 and HighBits = "0000" ) then
state <= waitone;
longwait <= twosecdelay;
shortwait <= halfsecdelay;
elsif (HighBits > "0000") then
if(shortwait = 0) then
HighBits <= (HighBits - "0001");
else
shortwait <= (shortwait - 1);
ErrorLED <= '1';
FLTline <= '1';
end if;
else state <= HighError2;
end if; does anyone see any blatent errors? Thanks