Classroom 12
Classroom 12
• State Processes
• State Coding
• FSM Types
• Medvedev
• Moore
• Mealy
• Registered Output
• The standard versions known in theory
are Medvedev, Moore and Mealy
machines. However, there are far more
versions than these three. It is for example
recommended for several reasons to
place storing elements (registers, Flip
Flops) at the module outputs. By doing
this, additional versions of finite state
machines can be built
One "State" Process
• FSM_FF: process (CLK, RESET)
• begin
• if RESET='1' then
• STATE <= START ;
• elsif CLK'event and CLK='1' then
• case STATE is
• when START => if X=GO_MID then
• STATE <= MIDDLE ;
• end if ;
• when MIDDLE => if X=GO_STOP then
• STATE <= STOP ;
• end if ;
• when STOP => if X=GO_START then
• STATE <= START ;
• end if ;
• when others => STATE <= START ;
• end case ;
• end if ;
• end process FSM_FF ;
•
Two "State" Processes
FSM_FF: process (CLK, RESET) begin
• if RESET='1' then
• STATE <= START ;
• elsif CLK'event and CLK='1' then
• STATE <= NEXT_STATE ;
• end if;
• end process FSM_FF ;
end case ;
• The most obvious method to intercept invalid states is to
insert a 'when others' branch in the CASE statement.
With this branch, all values of the examined expression
(here: STATE) that are not included in the other
branches of the CASE statement are covered. The
intention is to intercept all illegal states and to restart the
automaton with its reset state (here: START).
• end case ;
• The second way is to define additional
values for the enumeration type. So many
values have to be added that after state
encoding invalid values can no longer
occur. If an automaton contains for
example 20 states, 5 Flip Flops are
needed with a binary code. With 5 FFs
one can distinguish 32 values (2^5=32).
Thus, 12 additional values have to be
added to the enumeration type of the state
machine.
• By adding additional values to the enumeration
type, one gets a state machine whose behaviour
in case of errors can now be simulated.
• The synthesis also results in a safe circuit
representing the original state machine.
However this method is somewhat awkward as
one has to insert many so called dummy states
eventually.
• Furthermore, this method is only suitable when
binary coding for the states of the automaton is
used. If one has added for example these 12
additional values for a safe state machine, he
will get 12 redundant Flip Flop when he switches
the state encoding to the one hot code as an
extra bit is needed for every state.
• It is impossible to make a state machine safe by
inserting additional values for dummy states if a
one hot code is used. Every new value would
lead to an additional FF and therefore would
only increase the amount of invalid state values
after synthesis.
Y <= S ;
end RTL ;
Two Processes
• architecture RTL of MEDVEDEV is
• ...
• begin
• REG: process (CLK, RESET)
• begin
• -- State Registers Inference
• end process REG ;
• Y <= S ;
• end RTL ;
Medvedev Example
• architecture RTL of MEDVEDEV_TEST is
• signal STATE,NEXTSTATE : STATE_TYPE ;
• begin
• REG: process (CLK, RESET)
• begin
• if RESET=`1` then
• STATE <= START ;
• elsif CLK`event and CLK=`1` then
• STATE <= NEXTSTATE ;
• end if ;
• end process REG;
•
• CMB: process (A,B,STATE) begin
• NEXT_STATE <= STATE;
• case STATE is
• when START => if (A or B)=`0` then
• NEXTSTATE <= MIDDLE ;
• end if ;
• when MIDDLE => if (A and B)=`1` then
• NEXTSTATE <= STOP ;
• end if ;
• when STOP => if (A xor B)=`1` then
• NEXTSTATE <= START ;
• end if ;
• when others => NEXTSTATE <= START ;
• end case ;
• end process CMB ;
• -- concurrent signal assignments for output
• (Y,Z) <= STATE ;
• end RTL ;
• Defining constants
• Control of encoding
• Safe FSM
• Simulatable
• Portable design
• More effort
Medvedev Example
architecture RTL of MEDVEDEV_TEST is
signal STATE,NEXTSTATE : STATE_TYPE ;
begin
REG: process (CLK, RESET)
begin
if RESET=`1` then
STATE <= START ;
elsif CLK`event and CLK=`1` then
STATE <= NEXTSTATE ;
end if ;
end process REG;
• CMB: process (A,B,STATE) begin
• NEXT_STATE <= STATE;
• case STATE is
• when START => if (A or B)=`0` then
• NEXTSTATE <= MIDDLE ;
• end if ;
• when MIDDLE => if (A and B)=`1` then
• NEXTSTATE <= STOP ;
• end if ;
• when STOP => if (A xor B)=`1` then
• NEXTSTATE <= START ;
• end if ;
• when others => NEXTSTATE <= START ;
• end case ;
• end process CMB ;
• -- concurrent signal assignments for output
• (Y,Z) <= STATE ;
• end RTL ;
(Y,Z) = STATE => Medvedev
machine
• In the waveform one can see the
progression over time of the signal values
of the design during simulation. It is
apparent that it must be a Medvedev
automaton, because the values of the
output vector (represented by the two
singals Y and Z) change synchronously
with the state vector.
FSM: Moore
TWO PROCESSORS