Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20702 Discussions

Down Counting State Machine problem

Altera_Forum
Honored Contributor II
1,049 Views

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
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
344 Views

I assume this process is clocked?

0 Kudos
Altera_Forum
Honored Contributor II
344 Views

Yes, I am counting down from (400) for simulation purposes 

 

Here is my latest... Still having problems with signal tap 

when HighError1 => ErrorLED <= '0'; FLTline <= '1'; shortwait <= shortwait - 1; if (shortwait = 0) then state <= HighError2; shortwait <= halfsecdelay; else state <= HighError1; end if; when HighError2 => if(HighBits = "0000")then state <= waitone; longwait <= twosecdelay; shortwait <= halfsecdelay; elsif(HighBits > "0000")then shortwait <= (shortwait - 1); ErrorLED <= '1'; FLTline <= '1'; if(shortwait = 0)then HighBits <= (HighBits - "0001"); longwait <= twosecdelay; shortwait <= halfsecdelay; state <= HighError1; else state <= HighError2; end if; else state <= HighError2; end if;
0 Kudos
Altera_Forum
Honored Contributor II
344 Views

I dont really understand what you are trying to do. 

 

Where is the input? 

what are you trying to wait on? is it just mean to wait for N seconds where N is the input (that I dont quite understand from your code).
0 Kudos
Reply