Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
PLD State Machine DesignELCTEC-131
State Machine Definitions State Machine:
◦ A synchronous sequential circuit consisting of a sequential logic section and a combinational logic section.
The outputs and internal flip flops (FF) progress through a predictable sequence of states in response to a clock and other control inputs.
22/15/2010 © 2009 Richard Lokken
State Machine Types Moore Machine:
◦ A Finite State Machine (FSM) whose outputs are determined only by the Sequential Logic (FF) of the FSM.
Mealy Machine:
◦ An FSM whose outputs are determined by both the sequential logic and combinational logic of the FSM.
32/15/2010 © 2009 Richard Lokken
State Machine Basics State Variable:
◦ The variable held in the SM (FF) that determines its present state.
A basic FSM has a memory section that holds the present state of the machine (stored in FF) and a control section that controls the next state of the machine (by clocks, inputs, and present state).
42/15/2010 © 2009 Richard Lokken
Basic Block Diagram
2/15/2010 © 2009 Richard Lokken 5
FSM Design Techniques Classical Design:
◦ Makes use of state tables, FF excitation tables, and Karnaugh Mapping to find FF input control logic.
VHDL Design:
◦ Uses case statements or IF THEN ELSE statements to set the design and the logic synthesis tools to define equations.
62/15/2010 © 2009 Richard Lokken
Classical Design Approach Define the actual problem.
Draw a state diagram (bubble) to implement the problem.
Make a state table.
◦ Define all present states and inputs in a binary sequence.
◦ Then define the next states and outputs from the state diagram.
72/15/2010 © 2009 Richard Lokken
Classical Design Approach Use FF excitation tables to determine in
what states the FF inputs must be to cause a present state to next state transition.
Find the output values for each present state/input combination.
Simplify Boolean logic for each FF input and output equations and design logic.
82/15/2010 © 2009 Richard Lokken
FSM Design Example 1
Gray Code Counter that sequences
◦ {000, 001, 011, 010, 110, 111, 101, 100, 000}.
From this the state and excitation table is developed for D flip flops (see Table 10.2 in the textbook).
92/15/2010 © 2009 Richard Lokken
State Diagram
2/15/2010 © 2009 Richard Lokken 10
State Table
2/15/2010 © 2009 Richard Lokken 11
K-Maps
2/15/2010 © 2009 Richard Lokken 12
FSM Design Example 2
From the K-Maps for the inputs D0, D1, and D2, the following equations are developed:
13
12120
02011
02012
QQ QQ D
QQ QQ D
QQ QQ D
+=
+=
+=
2/15/2010 © 2009 Richard Lokken
Simulation
2/15/2010 © 2009 Richard Lokken 14
VHDL FSM Design Uses an enumerated type to declare state
variables.
Enumerated Type: A user-defined type in which all possible values of a named identifier are listed in a type definition.
An FSM uses a CASE statement on the enumerated type state variable.
152/15/2010 © 2009 Richard Lokken
FSM VHDL Example
16
-- gray_ct1.vhd
-- 3-bit Gray code counter
-- (state machine with decoded outputs)
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
2/15/2010 © 2009 Richard Lokken
FSM VHDL Entity
17
ENTITY gray_ct1 IS
PORT(
clk : IN STD_LOGIC;
q : OUT STD_LOGIC_VECTOR(2 downto 0));
END gray_ct1;
2/15/2010 © 2009 Richard Lokken
FSM VHDL Architecture
18
ARCHITECTURE a OF gray_ct1 IS
TYPE STATE_TYPE IS (s0,s1,s2,s3,s4,s5,s6,s7);
SIGNAL state :STATE_TYPE;
BEGIN
PROCESS(clk)
BEGIN
2/15/2010 © 2009 Richard Lokken
FSM VHDL Architecture
19
IF (clk’EVENT AND clk = ‘1’) THEN
CASE state IS
WHEN s0 => state <= s1;
WHEN s1 => state <= s2;
WHEN s2 => state <= s3;
WHEN s3 => state <= s4;
WHEN s4 => state <= s5;
2/15/2010 © 2009 Richard Lokken
FSM VHDL Architecture
20
WHEN s5 => state <= s6;
WHEN s6 => state <= s7;
WHEN s7 => state <= s0;
END CASE;
END IF;
END PROCESS;
2/15/2010 © 2009 Richard Lokken
FSM VHDL Architecture
21
WITH state SELECT
q <= “000” WHEN s0,
“001” WHEN s1,
“011” WHEN s2
“010” WHEN s3,
“110” WHEN s4,
“111” WHEN s5,
“101” WHEN s6,
“100” WHEN s7;
END a;2/15/2010 © 2009 Richard Lokken
VHDL Output Assignment
The output assignment for the following example could have also been in the CASE test statements (in the process).
22
WHEN s0 => state <= s1;
q <= “001”;
WHEN s1 => state <= s2;
q <= “011”;
2/15/2010 © 2009 Richard Lokken
FSM with Control Inputs
Same design approach used for FSM such as counters.
Uses the control inputs and clock to control the sequencing from state to state.
Inputs can also cause output changes not just FF outputs.
232/15/2010 © 2009 Richard Lokken
FSM with Control Inputs
2/15/2010 © 2009 Richard Lokken 24
SM Diagram Notation Bubbles contain the state name and
value (StateName/Value), such as Start/000.
Transitions between states are designated with arrows from one bubble to another.
Each transition has an ordered Input/Output, such as in1/out1.
252/15/2010 © 2009 Richard Lokken
SM Diagram Notation For example, if SM is at State = Start and
if in1 = 0, it then transitions to State = Continue and out1 = 1, out2 = 0.
The arrow is drawn from start bubble to continue bubble.
On the arrow the value 0/10 is given to represent the in1/out1,out2.
262/15/2010 © 2009 Richard Lokken
SM Design
State Table for the State Diagram
27
Present Status Input Next State Sync. InputsQ in1 Q JK out1 out20 0 1 1X 1 00 1 0 0X 0 01 0 0 X1 0 11 1 0 X1 0 1
Outputs
2/15/2010 © 2009 Richard Lokken
SM Design
The State Excitation Tables for the JKInputs
28
Transition JK
0 to 0 0X
0 to 1 1X
1 to 0 X1
1 to 1 X0
2/15/2010 © 2009 Richard Lokken
SM Design
The following equation represents the next state and output logic of the state machine.
29
Qin1Qin1Q out2
in1Q out1
1 Kin1 in1Q in1Q J
=•+•=
•=
==•+•=
2/15/2010 © 2009 Richard Lokken
SM Design
The pulser SM has two outputs that are not always synchronized to clock.
The pulse out2 is always synched to a change in clock, but out1 could change if in1 changes.
The following slides show a BDF implementation of the Pulser SM.
302/15/2010 © 2009 Richard Lokken
SM Design
312/15/2010 © 2009 Richard Lokken
Simluation Results
2/15/2010 © 2009 Richard Lokken 32
SM Pulser Architecture
Uses an enumerated type state listing of start and continue.
33
ARCHITECTURE a OF state_x1 IS
TYPE PULSER IS (start, continue);
SIGNAL sequence : PULSER;
BEGIN
PROCESS(clk)
BEGIN
2/15/2010 © 2009 Richard Lokken
SM Pulser Architecture
A portion of the case statement:
34
IF(clk’EVENT AND clk = ‘1’) THEN
CASE sequence IS
WHEN start =>
IF in1 = ‘1’ THEN
sequence <= start;
out1 <= ‘0’;
out2 <= ‘0’;
2/15/2010 © 2009 Richard Lokken
SM Pulser Architecture In the VHDL case statement, an IF
conditional test statement was used to check the Input Signal (in1) for State = Start.
IF in1 = 1, stay at State = Start; IF in1 = 0, then move to State = Continue (next clk).
If the present state was continue, the next state is always start, so an IF statement is not required.
352/15/2010 © 2009 Richard Lokken