Finite State Machine (FSM) : Example
Finite State Machine (FSM) : Example
Finite State Machine (FSM) When the sequence of actions in your design depend on the state of sequential elements, a finite state machine (FSM) can be implemented FSMs are widely used in applications that require prescribed sequential activity
Example:
Sequence Detector Fancy counters Traffic Light Controller Data-path Controller Device Interface Controller etc.
Finite State Machine (FSM) (cont.) All state machines have the general feedback structure consisting of:
Combinational logic implements the next state logic
Next state (ns) of the machine is formed from the current state (cs) and the current inputs
Memory
Current State
27/03/2012
Inputs
cs Output Logic
Outputs
Next state depends on the current state and the inputs but the output depends only on the present state
next_state(t) = h(current_state(t), input(t)) output = g(current_state(t))
Inputs
cs
Outputs
Next state and the outputs depend on the current state and the inputs
next_state(t) = h(current_state(t), input(t)) output(t) = g(current_state(t), input(t))
27/03/2012
State Register
out_bit = 0
1
FSM Flow-Chart
out_bit = 0 read_1_zero
0 0 0
read_1_one
out_bit = 0
read_2_zero
read_2_one
out_bit = 1
out_bit = 1
; et at s _t e s er = et at s _t x e n ; e n o _ 1 _ d a er = et at s _t x e n ) 1 = = ti b _ ni ( ; or e z _ 2 _ d a er = et at s _t x e n ) 0 = = ti b _ ni ( : ; et at s _t e s er = et at s _t x e n ; e n o _ 1 _ d a er = et at s _t x e n ) 1 = = ti b _ ni ( ; or e z _ 2 _ d a er = et at s _t x e n ) 0 = = ti b _ ni ( : ; et at s _t e s er = et at s _t x e n ; e n o _ 1 _ d a er = et at s _t x e n ) 1 = = ti b _ ni ( ; or e z _ 1 _ d a er = et at s _t x e n
)ti b _ ni
27/03/2012
4
; 0 : 1 ? ) ) e n o _ 2 _ d a e r = = g e r _ et at s ( || ) o r e z _ 2 _ d a e r = = g e r _ et at s ( ( = ti b _t u o
es es ffffiiii esllll es
; et at s _t e s er = et at s _t x e n ; et at s _t e s er = et at s _t x e n ; e n o _ 2 _ d a er = et at s _t x e n ) 1 = = ti b _ ni ( e ; or e z _ 1 _ d a er = et at s _t x e n ) 0 = = ti b _ ni ( : ; et at s _t e s er = et at s _t x e n ; e n o _ 2 _ d a er = et at s _t x e n ) 1 = = ti b _ ni ( ; or e z _ 1 _ d a er = et at s _t x e n ) 0 = = ti b _ ni ( :
es e es e esllle
fi e sl e
es e es e eslllle es e
)t e s er
) 1 = = t e s e r ( fi egdesop rro egdesop o egdesop @ syaw a egdesop @ syaw a egdesop rro kcolc egdesop( @ syawlllla egdesop o egdesop @ syaw a retsiger etats // ; 0 0 1 b' 3 ; 1 1 0 b' 3 ; 0 1 0 b' 3 ; 1 0 0 b' 3 ; 0 0 0 b' 3 = e n o _ 2 _ d a er = or e z _ 2 _ d a er = e n o _ 1 _ d a er = or e z _ 1 _ d a er = et at s _t e s er
rre emarrap e ema ap rrettttemarrap e ema ap re emarap e ema ap rretttemarrap retemarap rre emarrap e ema ap rrettttemarrap e ema ap rre emarrap e ema ap rrettttemarrap e ema ap noitaralced etatS // gerr ge gerr ge up uo up uo ttttupttttuo up uo upn upn ttttupniiii upn eludom
) 0 = = ti b _ ni ( fi etttattts_ttteserr e a s _ e s er :etats_teser e a s_ ese ) g er _ et at s( e s a c rro o @ syaw a @ syaw a rro ger_etats( @ syawlllla o @ syaw a
27/03/2012
The input (write) and output (read) domains can be synchronized by two separate clocks, allowing the FIFO to act as a buffer between two clock domains (Dual Clock FIFOs) A FIFO can allow simultaneous reading and writing of data (however
synchronization is necessary if read/write parts are different clock domains)
The write signal is synchronized to the read clock using clock synchronizers FIFOs are usually implemented with dual-port RAMs with independent read- and write-address pointers and registered data ports (see www.idt.com)
27/03/2012
FIFO Structure
stack_height -1
FIFO Buffer
rst
clk_read
Internal Signals
write_ptr
0 stack_width -1 0
Input-output Ports
read_ptr
DATA_out
FIFO
{DEPTH, WIDTH}
clk rst
VALID_out stall_in
27/03/2012
FIFO SPECIFICATION Parametric WIDTH PARAMETRIC DEPT ( >= 2) Simple handshake based on stall-go flow control protocol
To push data in the fifo, the valid is must be 1 and stall_out must be 0 To pop data from the fifo, stall_in must be 0, and valid_out ust be 1. When the fifo is FULL the stall_out must be 1; When the fifo is empty, valid_out out must be 0.
The latency of the FIFO must be 1 clock cycle The FIFO must allow simultaneous reading and writing of data Use a FF based asynchronous read-synchronous write dual port RAM
Example: FIFO
P US H P ointer EN 0 1 DATA 2 3 4
P OP P ointe r
DATA
n-1
27/03/2012
testbench. v Stimuli
FIFO
reset
clock