Modeling Sequential Hardware
Modeling Sequential Hardware
▪ Synchronous sequential logic circuits rely on storage elements for their operations.
▪ One-bit storage elements.
▸ Latches
▸ Flips-flops (FFs)
▪ Multibit
▸ Registers
▸ Shift registers
▸ Counters.
▪ Only synchronous sequential logic is considered.
2
Latches, Flip-Flops
4
Mux à Latch?
reg f; reg f;
always @ (sel, a, b) always @ (sel or a or b)
begin : if_else begin : pure_if
if (sel == 1) f = b;
f = a; if (sel == 1)
else f = a;
f = b; end
end
▪ if-else ▪ Simple if
Incomplete Assignment
reg f;
always @ (sel, a)
begin : latching_if
if (sel == 1)
f = a;
end
▪ The always blocks are sensitiveto the levels of the signals that appear in the
sensitivity list.
▪ FF changes only as a result of a clock transition of the clock signal, rather than its
level.
▪ e.g.,
always @ (posedge clock)
Signal edge detection
▪ Should be written as :
module DFF (
input CLK, D,
output reg Q );
10
Negative-edge triggered D flip-flop
module FF (
input CLK, d,
output reg q ) ;
d D
always @ (negedge CLK) f/f Q q
q = d ; CLK
endmodule
D flip-flop
clk
Q (+ve Flip-flop)
Q (-ve Flip-flop)
Blocking Assignments
module shiftregY (
▪ In a sequential block, input D, clk ,
blocking assignment output reg A, B,
statements (=) are C ) ;
evaluated immediately in
the order they are always @ (posedge clk)
specified. begin
C = D ;
▪ Called blocked B = C ;
assignments because a A = B ;
end
statement must complete endmodule
execution (i.e. update
memory) before the next
statement can execute.
D A
d q
clk
Non-blocking assignment
clk
Effect of sequential execution
▪ Order is important
module shiftregX1 ( module shiftregY1 (
input D, clk, input D, clk,
output reg A, B, C); output reg A, B, C );
15
Effect of concurrent execution
▪ Order is not important
module shiftregX2 ( module shiftregY2 (
input D, clk, input D, clk,
output reg A, B, C ); output reg A, B, C );
always @ (posedge clk) always @ (posedge clk)
begin begin
A <= B ; C <= D ;
B <= C ; B <= C ;
C <= D ; A <= B ;
end end
endmodule endmodule
16
Recommendations
module DFF2 (
input CLK, Data_in, RST, Data_in D
output reg Data_out); f/f Q Data_out
CLK
clr
always @ (posedge RST, posedge CLK)
if ( RST ) Data_out <= 0 ;
RST
else Data_out <= Data_in ;
endmodule
DFF with active low asynchronous reset
module DFF2 (
input CLK, D, RST,
output reg Q ); Data_in
D D
f/f Q Q
Data_o ut
always @ (negedge RST, posedge CLK) CLK
clr
if ( !RST )
Q <= 0 ; RST
else
Q <= D ;
endmodule
Exercise:
Modify to have sync active-low reset
Exercise
▪ Modify to include negative-
edge triggered, active-high for
both asynchronous reset Dff3
PST
inputs. clr
RST
clk
pst
rst
load
d a ta d a ta 1 d a ta 2 d a ta 3
Q
Result :
module tri_DFF (
Temp
input CLK, EN, OE, Data_In, Data_In D
Q
output Data_Out , EN f/f Data_out
pst
rst
load
Q
Binary Counter
module binarycounter (
input rst, clk,
output reg [7:0] count );