Beruflich Dokumente
Kultur Dokumente
Agenda
z
z z
Lab3 Counters are FSM Finite State Machine Models to represent FSM Mealy Machine and Moore Machine FSM Design Procedure State Diagram State Transition Table Next State Logic Functions Example One Vending Machine Mealy Machine Implementation Moore Machine Implementation Quartus II Tutorial Finite State Machine Implementation Improved Vending Machine z Moore Machine Implementation Mealy Machine Implementation
Acknowledgement
z z
z z
Materials in this lecture are courtesy of the following people Randy H. Katz (University of California, Berkeley, Department of Electrical Engineering &Computer Science) MIT Prof. Anantha Chandrakasan and Donald E. Troxel Introduction to Digital System Design Lab Professor C.K.Cheng, CSE140L John F. Wakerly, Digital Design, Principles and Practices, 3rd edition
Counters z proceed through well-defined sequence of states in response to enable Many types of counters: binary Up/Down, BCD, Gray-code,Divide-by3, z 3-bit up-counter: 000, 001, 010, 011, 100, 101, 110, 111, 000, ... z 3-bit down-counter: 111, 110, 101, 100, 011, 010, 001, 000, 111, ...
001 010 011
000
3-bit up-counter
100
111
110
101
Finite State Machines (FSMs) are a useful abstraction for sequential circuits with states of operation At each clock edge, combinational logic block computes outputs and next state as a function of inputs and present state
Mealy machines tend to have less states z different outputs on arcs (n2) rather than states (n) Moore machines are safer to use z outputs change at clock edge (always one cycle later) z In Mealy machines, input change can cause output change as soon as logic is done a big problem when two machines are interconnected asynchronous feedback may occur if one isnt careful Mealy machines react faster to inputs z react in same cycle don't need to wait for clock z in Moore machines, more logic may be necessary to decode state into outputs more gate delays after clock edge
Assumption: Starting point is a logic diagram. 1. Determine next-state function and output function 2. Construct state (transition) table
For each state/input combination, determine the excitation value.Using the characteristic equation, determine the corresponding next-state values (trivial with DFFs)
Release one item after 15 cents are deposited Single coin slot for dimes, nickels No change.- not realistic The controllers cause a single item to be released down a chute to the customer -> how to choose different items?
Reset
N Coin Sensor D
Open
Release Mechanism
Clock
Reset
inputs: N, D, reset output: open chute assume N and D asserted for one cycle each state has a self loop for N = D = 0 (no coin)
assumptions:
z
present state 0
0 N 5 N D 10 N+D 15 [open] D
10
15
inputs D N 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 X X
next state 0 5 10 X 5 10 15 X 10 15 15 X 15
output open 0 0 0 X 0 0 0 X 0 0 0 X 1
D1 = Q1 + D + Q0 N D0 = Q0 N + Q0 N + Q1 N + Q1 D OPEN = Q1 Q0
Binary encoding
Requires the least number of FFs. With n FFs, 2n states can be encoded. Disadvantages: require more logic, slower.
One-hotencoding
one FF per state, with n FFs, n states can be encoded. Require the least amount of extra logic and fastest
STATE
BINARY
TWOHOT
ONEHOT (8 bits) 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000
Johnson Code (4 bits) 0000 0001 0011 0111 1111 1110 1100 1000 4
Gray Code (3 bits) 000 001 011 010 110 111 101 100 3
State0 State1 State2 State3 State4 State5 State6 State7 Number of FFs required
One-hot encoding
present state Q3 Q2 Q1 Q0 0 0 0 1
0 0
0 1
1 0
inputs D N 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 - -
D0 = Q0 D N D1 = Q0 N + Q1 D N D2 = Q0 D + Q1 N + Q2 D N D3 = Q1 D + Q2 D + Q2 N + Q3 OPEN = Q3
Moore machine
z
Mealy machine
z
Reset
N D + Reset
Reset/0
(N D + Reset)/0
N D/0
N D/0
10
N D/0
15
Reset/1
N D/0
N D/0
N D/0
next state D1 D0 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 1 1
output open 0 0 0 0 0 1 0 1 1 1
Reset/1
Q1 Open 0 0 1 0 0 0 1 1 D X X 1 X 0 1 1 1 Q0 N
D0 D1 OPEN
10
OPEN = Q1Q0 creates a combinational delay after Q1 and Q0 change in Moore implementation This can be corrected by retiming, i.e., move flip-flops and logic through each other to improve delay OPEN.d = (Q1 + D + Q0N)(Q0'N + Q0N' + Q1N + Q1D) = Q1Q0N' + Q1N + Q1D + Q0'ND + Q0N'D Implementation now looks like a synchronous Mealy machine z it is common for programmable devices to have FF at end of logic
OPEN.d = Q1Q0 + Q1N + Q1D + Q0D OPEN.d = (Q1 + D + Q0N)(Q0'N + Q0N' + Q1N + Q1D) = Q1Q0N' + Q1N + Q1D + Q0'ND + Q0N'D
Q1 Open.d 0 0 1 0 0 0 1 1 D 1 0 1 1 0 1 1 1 Q0 D N Q1 Open.d 0 0 1 0 0 0 1 1 X X 1 X 0 1 1 1 Q0 N
11
pr_state
nx_state
Sequential Logic
Clock Reset
FSM approach => tasks constitute a well-structured list so that All states can be easily enumerated VHDL coding
z
ARCHITECTURE => user defined enumerated data type, containing a list of all possible system states
12
Open the text editor((File -> New, or click on edit icon select VHDL/Verilog) Entering VHDL/Verilog code, save in the extension .vhd or .v Check for syntax errors. Select Processing-> Analyze current File or click on analysis icon
13
QuartusII - Compilation
Select the target device (Assignments -> Devices) To compile VHDL/Verilog Code, select Processing-> Start Compilation, fix all compilation error until successful message window appears
QuartusII - Simulation
Open Waveform Editor, Select File-> New->Other File -> Vector Waveform File
In order to define the size of waveform, Edit -> End Time ( select 500ns, for example) Edit -> Grid Size ( select Period = 50ns, duty cycle = 50%) Select View -> Fit in Window Note: change default, go to Tools->Options->Waveform Editor->general 4. Add the input and output signals to the waveform window. Click the right mouse button inside the white area under Name. Select Insert Node or Bus. In the next box, select Node Finder. Make sure that Filter is set to Pins: all. Click on Start, then on >>, and finally OK. The waveforms window contains all all signals in VHDL/Verilog code. 5. Set the values of the input signals. (clk, rst,d,.) To set up the clock signal, select the entire clk line. A setup box will be displayed, choose period = 100 ns 6. For rst, select only the first portion (from 0 to 25 ns), which will cause change from 0 to 1. 7. Save the waveform file as *.vwf 8. The system is now ready for simulation. Select Processing -> Start Simulation 1. 2. 3.
14
15
16
17
18
19
20
21
Lab 3 Assignment
Two types of Finite State Machines Moore Outputs are a function of current state only Mealy Outputs a function of both the current state and input function Lab 3 assignment please fix the problem in lecture! we need to have capability to select different drinks, and depense the selected drink and changes We will cover how to fix Glitching in FSM? Timing Requirement in FSM, String Pattern Recognizer next week. Final Exam Tuesday, March 21, 2006, 9:00AM- 10:30AM, HSS1330 March 15- Oral exam by TA on Lab 4
22