Guest
Hello,
I've rather foolishly missed out a "when others" statement in a state
machine that I have recently coded. After reading a few posts in this
group it seems that the "when others" statement was redundant anyway,
due to the coding style I implemented (thanks to a post from Jonathan
Bromley for pointing me in the direction of using variables to define
state transitions).
Have I understood this correctly, do I not need the "when others"
statement as all the state transitions are covered within the code? As
the code does not have 2^n states, does the synthesis tool not require
some form of default statement to get the state machine back to a
known state (in case of electrical problems causing dodgy state
transitions, etc.)
I've posted some sample code below to show what I mean
thanks for any help,
Will
------------------------------------------------------------------------------
process (clk, reset)
type statetype is (aa, bb, cc, dd, ee);
variable state: statetype;
begin
if reset = '1' then
state := aa;
sigout <= "00001";
elsif rising_edge(clock) then
case state is
when aa =>
state := bb;
when bb =>
state := cc;
when cc =>
state := dd;
when dd =>
state := ee;
when ee =>
state := aa;
end case;
case state is
when aa =>
sigout <= "00001";
when bb =>
sigout <= "00001";
when cc =>
sigout <= "00001";
when dd =>
sigout <= "00001";
when ee =>
sigout <= "00001";
when others =>
sigout <= "11111";
end case;
end if;
end process;
I've rather foolishly missed out a "when others" statement in a state
machine that I have recently coded. After reading a few posts in this
group it seems that the "when others" statement was redundant anyway,
due to the coding style I implemented (thanks to a post from Jonathan
Bromley for pointing me in the direction of using variables to define
state transitions).
Have I understood this correctly, do I not need the "when others"
statement as all the state transitions are covered within the code? As
the code does not have 2^n states, does the synthesis tool not require
some form of default statement to get the state machine back to a
known state (in case of electrical problems causing dodgy state
transitions, etc.)
I've posted some sample code below to show what I mean
thanks for any help,
Will
------------------------------------------------------------------------------
process (clk, reset)
type statetype is (aa, bb, cc, dd, ee);
variable state: statetype;
begin
if reset = '1' then
state := aa;
sigout <= "00001";
elsif rising_edge(clock) then
case state is
when aa =>
state := bb;
when bb =>
state := cc;
when cc =>
state := dd;
when dd =>
state := ee;
when ee =>
state := aa;
end case;
case state is
when aa =>
sigout <= "00001";
when bb =>
sigout <= "00001";
when cc =>
sigout <= "00001";
when dd =>
sigout <= "00001";
when ee =>
sigout <= "00001";
when others =>
sigout <= "11111";
end case;
end if;
end process;