Altera_Forum
Honored Contributor
13 years agoheadache with 2 process state machine
Hi everyone,
below is the code from a state machine. It is a intended emulate one part of a system to test the other part, so all it is doing is sending rows and columns of data (and looking for some special cases while its at it) to the system downstream nearly all of the signals are reported as having unsafe behaviour, and, although it builds, it doesn't work (as well as unsafe behavior, it is throwing up inferred latches all over the place) I think this is probably relatively elementary to those who are wiser than me in this field, Am I trying to do too much in each of the states, should I be creating some other code to do the donkey work? Hope one of you can steer me back on right path- I think I have been here before, but was a simpler system I have tried changing to a one process machine, but that didn't especially help Regards Pete B (code attached) process (nReset,Clock50) begin if (nReset ='0') then CurrentState <= InReset; elsif (rising_edge (Clock50)) then CurrentState <= NextState; end if; end process; process (CurrentState) begin case CurrentState is ------------------------ when InReset => CurrentFreqBin<="00000"; TargetBin<="00000"; TargBinInt<=0; index <= 0; InterFrameDelay<="000000000000000000000000"; ---------------------- NextState <= StartCol; ------------------------ ------------------------ when StartCol => TargBinInt<=FreqTable(index); --my_slv <= std_logic_vector(to_unsigned(my_integer, my_slv'length)); -- if TargetBin <= std_logic_vector(to_unsigned(TargBinInt,5)); ----------------------- NextState <= WriteFreq; ------------------------ ------------------------ when WriteFreq => FreqSlot<=CurrentFreqBin; if (CurrentFreqBin=TargetBin) then Amplitude<="11111111"; else Amplitude<="00000000"; end if; Strobe<='1'; ---------------------- NextState <= StrobeOff; ------------------------ ------------------------ when StrobeOff => Strobe<='0'; CurrentFreqBin<=CurrentFreqBin+1; if (CurrentFreqBin="00000") then NextState <= ColumnFinished; else NextState <= WriteFreq; end if; ------------------------ ------------------------ when ColumnFinished => ColumnDone<='1'; index<=index+1; NextState <= ColFinStrobeOff; ------------------------ ------------------------ when ColFinStrobeOff => if (index = 256) then NextState <= AllDone; InterFrameDelay <="000001111010000100100000"; else NextState <=StartCol; ColumnDone<='0'; end if; ------------------------ ------------------------ when AllDone => ColumnDone<='1'; NextState <= AllDoneLoop; ------------------------ ------------------------ when AllDoneLoop => ColumnDone<='0'; InterFrameDelay <=InterFrameDelay-1; if (InterFrameDelay < "000000000000000000000010") then NextState <= AllDone; else NextState <= AllDoneLoop; end if; ------------------------ end case; end process;