Chapter 9: Sequential Logic Modules: Prof. Soo-Ik Chae
Chapter 9: Sequential Logic Modules: Prof. Soo-Ik Chae
Objectives
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-2
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-4
Chapter 9: Sequential Logic Modules
Libraries
Parity tree
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-6
Chapter 9: Sequential Logic Modules
Inferred Latch
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-9
Chapter 9: Sequential Logic Modules
Registers
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-10
Chapter 9: Sequential Logic Modules
Data Registers
din[3] din[2] din[1] din[0]
D Q D Q D Q D Q
CK CK CK CK
Q' Q' Q' Q'
clk
qout[3] qout[2] qout[1] qout[0]
Data Registers
// an n-bit data register with asynchronous reset
module register_reset (clk, reset_n, din, qout);
parameter N = 4; // number of bits
input clk, reset_n;
input [N-1:0] din;
output reg [N-1:0] qout;
Coding style:
• For active-low signal, end the signal name with an underscore followed by
a lowercase letter b or n, such as reset_n.
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-12
Chapter 9: Sequential Logic Modules
Data Registers
// an N-bit data register with synchronous load and
// asynchronous reset
module register_load_reset (clk, load, reset_n, din, qout);
parameter N = 4; // number of bits
input clk, load, reset_n;
input [N-1:0] din;
output reg [N-1:0] qout;
Notice that: the else part is a redundant expression for sequential circuit.
Why? Try to explain it.
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-13
Chapter 9: Sequential Logic Modules
A Register File
// an N-word register file with one-write and two-read ports
module register_file(clk, rd_addra, rd_addrb, wr_addr, wr_enable, din, douta, doutb);
parameter M = 4; // number of address bits
parameter N = 16; // number of words, N = 2**M
parameter W = 8; // number of bits in a word
input clk, wr_enable;
input [W-1:0] din;
output [W-1:0] douta, doutb;
input [M-1:0] rd_addra, rd_addrb, wr_addr;
reg [W-1:0] reg_file [N-1:0];
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-14
Chapter 9: Sequential Logic Modules
An Synchronous RAM
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-15
Chapter 9: Sequential Logic Modules
Shift Registers
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-16
Chapter 9: Sequential Logic Modules
Shift Registers
QA QB QC QD
CP
CP
SI
QA 1 1 0 1
QB 0 1 1 0 1
QC 0 0 1 1 0 1
QD 0 0 0 1 1 0 1
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-17
Chapter 9: Sequential Logic Modules
Shift Registers
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-18
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-19
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-20
Chapter 9: Sequential Logic Modules
D Q D Q D Q D Q
CK CK CK CK
Q' Q' Q' Q'
clear clear clear clear
clk
reset
qout[3] qout[2] qout[1] qout[0]
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-21
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-22
Chapter 9: Sequential Logic Modules
Counters
J Q J Q J Q
clk CK CK CK
K Q' K Q' K Q'
1 2 3
clk
qout[0]
qout[1]
qout[2]
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-24
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-25
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-26
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-28
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-30
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-31
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-32
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-34
Chapter 9: Sequential Logic Modules
// the body of modulo r binary counter with synchronous reset and enable control.
module modulo_r_counter(clk, enable, reset, qout, rco);
parameter N = 4;
parameter R= 10; // BCD counter
input clk, enable, reset;
output reg [N-1:0] qout;
output rco; // carry output
// the body of modulo r binary counter.
assign rco = (qout == R - 1);
always @(posedge clk)
if (reset) qout <= {N{1'b0}};
else begin
if (enable) if (rco) qout <= 0;
else qout <= qout + 1;
end
endmodule
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-35
Chapter 9: Sequential Logic Modules
// the body of modulo r binary counter with synchronous reset and enable control.
module modulo_r_counter(clk, enable, reset, qout, rco);
parameter N = 4;
parameter R= 10; // BCD counter
input clk, enable, reset;
output reg [N-1:0] qout;
output rco; // carry output
// the body of modulo r binary counter.
assign rco = (qout == R - 1);
always @(posedge clk)
if (reset) qout <= {N{1'b0}};
else begin
if (enable) qout <= (qout + 1)% R; • Not synthesizable if R is
end not a power of 2.
endmodule
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-36
Chapter 9: Sequential Logic Modules
A Modulo r Binary Counter: revised
// the body of modulo r binary counter with synchronous reset and enable control.
module modulo_r_counter(clk, enable, reset, qout, rco);
parameter N = 4;
parameter R= 10; // BCD counter
input clk, enable, reset;
output reg [N-1:0] qout;
output reg rco; // carry output
wire cout;
// the body of modulo r binary counter.
assign cout = (qout==R-1);
always @(negedge clk)
rco <= cout; // rco will be used as enable if cascaded
always @(posedge clk)
if (reset) qout <= {N{1'b0}};
else begin
if (enable) if (rco) qout <= 0;
else qout <= qout + 1;
end
endmodule
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-37
Chapter 9: Sequential Logic Modules
Sequence Generators
Qn-1 Qn-2 Q1 Q0
Dn-1
D Q D Q ••• D Q D Q z
CK CK CK CK
Q' Q' Q' Q'
n-1 n-2 1 0
clk
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-38
Chapter 9: Sequential Logic Modules
Primitive Polynomials
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-39
Chapter 9: Sequential Logic Modules
D Q D Q D Q D Q
CK CK CK CK
an n-1 Q' an-1 n-2 Q' an-2 1 Q' a1 0 Q' a0
clk
D Q D Q D Q D Q
CK CK CK CK
a0 n-1 Q' a1 n-2 Q' a2 1 Q' an-1 0 Q' an
clk
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-40
Chapter 9: Sequential Logic Modules
• Using start to set the initial to 1000, the circuit will start from state
4’b1000 after reset signal is applied.
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-41
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-42
Chapter 9: Sequential Logic Modules
• Using start to set the initial value to 4’b1000, hence simulators can calculate
qout and hence we could observe the qout values.
• Of course, the circuit will start from state 4’b1000 after reset signal is applied.
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-43
Chapter 9: Sequential Logic Modules
Ring Counters
qout[0] qout[1] qout[2] qout[3]
Johnson Counters
qout[0] qout[1] qout[2] qout[3]
Self-starting counters
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-46
Chapter 9: Sequential Logic Modules
Timing Generators
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-47
Chapter 9: Sequential Logic Modules
clk
T0
T1
T2
T3
T4
T5
T6
T7
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-48
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-49
Chapter 9: Sequential Logic Modules
7 6 5 4 3 2 1 0
3-to-8 decoder
A2 A1 A0
clk
[1:0]
decode
+ [1:0] [1:0]
D[1:0] Q[1:0] [1:0] [1:0]
D[1:0] EQ[3:0] [3:0] [3:0]
qout[3:0]
enable R
bcnt_out_5[1:0] qout[3:0]
reset bcnt_out[1:0]
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-50
Chapter 9: Sequential Logic Modules
Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008, John Wiley 9-51