Chapter 9: Sequential Logic Modules

Slides:



Advertisements
Similar presentations
Synchronous Sequential Logic
Advertisements

Table 7.1 Verilog Operators.
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
ELEN 468 Advanced Logic Design
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Sequential Circuit Introduction to Counter
Registers and Counters
A State Element “Zoo”.
1 Sequential Circuits Registers and Counters. 2 Master Slave Flip Flops.
Figure 7.1. Control of an alarm system. Memory element Alarm Sensor Reset Set OnOff 
Registers & Counters M. Önder Efe
ECE 2372 Modern Digital System Design
Figure A flip-flop with an enable input. D Q Q Q R Clock E 0 1.
SEQUENTIAL CIRCUITS Component Design and Use. Register with Parallel Load  Register: Group of Flip-Flops  Ex: D Flip-Flops  Holds a Word of Data 
Copyright © 2007 Elsevier3- Ders-6: Ardışıl Mantık Devreleri Tasarımı.
Registers and Counters Chapter 6. Digital Circuits 2 Clocked sequential circuits a group of flip-flops and combinational gates connected to form a feedback.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
Digital Electronics.
Copyright © 2007 Elsevier3- Sequential Logic Circuits Design.
ECE/CS 352 Digital System Fundamentals© T. Kaminski & C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Fall 2000 Chapter 5 – Part 2 Tom Kaminski & Charles.
SYEN 3330 Digital SystemsJung H. Kim 1 SYEN 3330 Digital Systems Chapter 7 – Part 2.
ECE 545—Digital System Design with VHDL Lecture 1
Chapter 6: Hierarchical Structural Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 6-1 Chapter 6: Hierarchical.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Design of Datapath Controllers Speaker: Shao-Wei Feng Adviser:
Fuw-Yi Yang1 數位系統 Digital Systems Department of Computer Science and Information Engineering, Chaoyang University of Technology 朝陽科技大學資工系 Speaker: Fuw-Yi.
Counters and registers Eng.Maha Alqubali. Registers Registers are groups of flip-flops, where each flip- flop is capable of storing one bit of information.
1 Modeling Synchronous Logic Circuits Debdeep Mukhopadhyay Associate Professor Dept of Computer Science and Engineering NYU Shanghai and IIT Kharagpur.
EMT 351/4 DIGITAL IC DESIGN Verilog Behavioral Modeling  Finite State Machine -Moore & Mealy Machine -State Encoding Techniques.
Overview Logistics Last lecture Today HW5 due today
Supplement on Verilog FF circuit examples
Class Exercise 1B.
Figure 8.1. The general form of a sequential circuit.
Verilog Modules for Common Digital Functions
Homework Reading Machine Projects Labs Tokheim Chapter 9.1 – 9.6
Registers and Counters
Lecture 11 Registers and Counters
Electronics Technology
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
HDL for Sequential Circuits
Advance Skills TYWu.
Prof. Hsien-Hsin Sean Lee
Sequential Logic Counters and Registers
3.2 Shift Register Basic shift register function
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Chapter 5: Tasks, Functions, and UDPs
CS Fall 2005 – Lec. #5 – Sequential Logic - 1
Chapter 3: Dataflow Modeling
SYNTHESIS OF SEQUENTIAL LOGIC
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN
ECE 545—Digital System Design with VHDL Lecture 1
CSE 370 – Winter Sequential Logic-2 - 1
332:437 Lecture 8 Verilog and Finite State Machines
EET107/3 DIGITAL ELECTRONICS 1
Chapter 4: Behavioral Modeling
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
COE 202 Introduction to Verilog
Chapter 8: Combinational Logic Modules
6. Registers and Counters
Register-Transfer Level Components in Verilog
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
CS M51A/EE M16 Winter’05 Section 1 Logic Design of Digital Systems Lecture 16 March 14 W’05 Yutao He 4532B Boelter Hall
Sequential Logic.
Switching Theory and Logic Design Chapter 5:
Digital Logic Department of CNET Chapter-6
Digital Logic Department of CNET Chapter-6
The Verilog Hardware Description Language
14 Digital Systems.
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
332:437 Lecture 8 Verilog and Finite State Machines
Sequntial-Circuit Building Blocks
Presentation transcript:

Chapter 9: Sequential Logic Modules Prof. Ming-Bo Lin Department of Electronic Engineering National Taiwan University of Science and Technology

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Objectives After completing this chapter, you will be able to: Describe how to model asynchronous and synchronous D-type flip-flops Describe how to model registers (data register, register file, and synchronous RAM) Describe how to model shift registers Describe how to model counters (ripple/synchronous counters and modulo r counters) Describe how to model sequence generators Describe how to model timing generators

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Basic Sequential Logic Modules Synchronizer Finite state machine Sequence detector Data register Shift register CRC generator Register file Counters (binary, BCD, Johnson) Timing generator Clock generator Pulse generator

Options for Modeling Sequential Logic Behavioral statement Task with delay or event control Sequential UDP Instantiated library register cell Instantiated modules

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Asynchronous Reset D-Type Flip-Flops module DFF_async_reset (clk, reset_n, d, q); … output reg q; always @(posedge clk or negedge reset_n) if (!reset_n) q <= 0; else q <= d; Q: How would you model a D-type latch?

Synchronous Reset D-Type Flip-Flops module DFF_sync_reset (clk, reset, d, q); … output reg q; always @(posedge clk) if (reset) q <= 0; else q <= d;

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Types of Memory Elements Data registers Register files Synchronous RAMs

Registers Registers (or data registers) A flip-flop In Xilinx FPGAs Area: 10 to 20x of an SRAM cell In Xilinx FPGAs Flip-flops Distributed memory Block memory

Data Registers // an n-bit data register module register(clk, din, qout); parameter N = 4; // number of bits … input [N-1:0] din; output reg [N-1:0] qout; always @(posedge clk) qout <= din;

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 [N-1:0] din; output reg [N-1:0] qout; always @(posedge clk or negedge reset_n) if (!reset_n) qout <= {N{1'b0}}; else qout <= din;

Data Registers // an N-bit data register with synchronous load and // asynchronous reset parameter N = 4; // number of bits input clk, load, reset_n; input [N-1:0] din; output reg [N-1:0] qout; always @(posedge clk or negedge reset_n) if (!reset_n) qout <= {N{1'b0}}; else if (load) qout <= din;

A Register File // an N-word register file with one-write and two-read ports 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]; … assign douta = reg_file[rd_addra], doutb = reg_file[rd_addrb]; always @(posedge clk) if (wr_enable) reg_file[wr_addr] <= din; Try to synthesize it and see what happens!!

An Synchronous RAM // a synchronous RAM module example parameter N = 16; // number of words parameter A = 4; // number of address bits parameter W = 4; // number of wordsize in bits input [A-1:0] addr; input [W-1:0] din; input cs, wr, clk; // chip select, read-write control, and clock signals output reg [W-1:0] dout; reg [W-1:0] ram [N-1:0]; // declare an N * W memory array always @(posedge clk) if (cs) if (wr) ram[addr] <= din; else dout <= ram[addr]; Try to synthesize it and see what happens!!

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Shift Registers Shift registers Parallel/serial format conversion SISO (serial in serial out) SIPO (serial in parallel out) PISO (parallel in serial out) PIPO (parallel in parallel out)

Shift Registers

Shift Registers // a shift register module example module shift_register(clk, reset_n, din, qout); Parameter N = 4; // number of bits …. output reg [N-1:0] qout; always @(posedge clk or negedge reset_n) if (!reset_n) qout <= {N{1'b0}}; else qout <= {din, qout[N-1:1]};

A Shift Register with Parallel Load // a shift register with parallel load module example module shift_register_parallel_load (clk, load, reset_n, din, sin, qout); parameter N = 8; // number of bits …. input [N-1:0] din; output reg [N-1:0] qout; always @(posedge clk or negedge reset_n) if (!reset_n) qout <= {N{1'b0}}; else if (load) qout <= din; else qout <= {sin, qout[N-1:1]};

Universal Shift Registers A universal shift register can carry out SISO SIPO PISO PIPO The register must have the following capabilities Parallel load Serial in and serial out Shift left and shift right

Universal Shift Registers

Universal Shift Registers // a universal shift register module module universal_shift_register (clk, reset_n, s1, s0, …); parameter N = 4; // define the default size … always @(posedge clk or negedge reset_n) if (!reset_n) qout <= {N{1'b0}}; else case ({s1,s0}) 2'b00: ; // qout <= qout; // No change 2'b01: qout <= {lsi, qout[N-1:1]}; // Shift right 2'b10: qout <= {qout[N-2:0], rsi}; // Shift left 2'b11: qout <= din; // Parallel load endcase

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Counters Counter Types Counters Timers

Types of Counters Types of counters Asynchronous (ripple) counters Binary counter (up/down counters) Synchronous counters BCD counter (up/down counters) Gray counters (up/down counters)

Binary Ripple Counters

Binary Ripple Counters // a 3-bit ripple counter module example module ripple_counter(clk, qout); … output reg [2:0] qout; wire c0, c1; // the body of the 3-bit ripple counter assign c0 = qout[0], c1 = qout[1]; always @(negedge clk) qout[0] <= ~qout[0]; always @(negedge c0) qout[1] <= ~qout[1]; always @(negedge c1) qout[2] <= ~qout[2]; Try to synthesize it and see what happens!! The output cannot be observed from simulators due to lacking initial values of qout.

Binary Ripple Counters // a 3-bit ripple counter with enable control module ripple_counter_enable(clk, enable, reset_n, qout); … output reg [2:0] qout; wire c0, c1; assign c0 = qout[0], c1 = qout[1]; always @(posedge clk or negedge reset_n) if (!reset_n) qout[0] <= 1'b0; else if (enable) qout[0] <= ~qout[0]; always @(posedge c0 or negedge reset_n) if (!reset_n) qout[1] <= 1'b0; else if (enable) qout[1] <= ~qout[1]; always @(posedge c1 or negedge reset_n) if (!reset_n) qout[2] <= 1'b0; else if (enable) qout[2] <= ~qout[2];

A Binary Ripple Counter // an N-bit ripple counter using generate blocks parameter N = 4; // define the size of counter … output reg [N-1:0] qout; genvar i; generate for (i = 0; i < N; i = i + 1) begin: ripple_counter if (i == 0) // specify LSB always @(negedge clk or negedge reset_n) if (!reset_n) qout[0] <= 1'b0; else qout[0] <= ~qout[0]; else // specify the rest bits always @(negedge qout[i-1]or negedge reset_n) if (!reset_n) qout[i] <= 1'b0; else qout[i] <= ~qout[i]; end endgenerate

A Binary Counter Example module binary_counter(clk, enable, reset, qout, cout); parameter N = 4; … output reg [N-1:0] qout; output cout; // carry output always @(posedge clk) if (reset) qout <= {N{1’b0}}; else if (enable) qout <= qout + 1; // generate carry output assign #2 cout = &qout; // Why #2 is required ?

Binary Up/Down Counters --- version 1 module binary_up_down_counter_reset (clk, enable, reset, upcnt, qout, cout, bout); parameter N = 4; … output reg [N-1:0] qout; output cout, bout; // carry and borrow outputs always @(posedge clk) if (reset) qout <= {N{1'b0}}; else if (enable) begin if (upcnt) qout <= qout + 1; else qout <= qout - 1; end assign #2 cout = &qout; // Why #2 is required ? assign #2 bout = |qout;

Binary Up/Down Counters --- version 2 module up_dn_bin_counter (clk, reset, eup, edn, qout, cout, bout); Parameter N = 4; … output reg [N-1:0] qout; output cout, bout; always @(posedge clk) if (reset) qout <= {N{1'b0}}; // synchronous reset else if (eup) qout <= qout + 1; else if (edn) qout <= qout - 1; assign #1 cout = (&qout)& eup; // generate carry out assign #1 bout = (~|qout)& edn; // generate borrow out

Binary Up/Down Counters --- version 2 // the cascade of two up/down counters module up_dn_bin_counter_cascaded(clk, reset,eup, …); parameter N = 4; … output [2*N-1:0] qout; output cout, bout; wire cout1, bout1; up_dn_bin_counter #(4) up_dn_cnt1 (clk, reset,eup, edn, …); up_dn_bin_counter #(4) up_dn_cnt2 (clk, reset, …);

A Modulo r Binary Counter module modulo_r_counter(clk, enable, reset, qout, cout); parameter N = 4; parameter R= 10; // BCD counter … output reg [N-1:0] qout; assign cout = (qout == R - 1); always @(posedge clk) if (reset) qout <= {N{1'b0}}; else begin if (enable) if (cout) qout <= 0; else qout <= qout + 1; end

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Sequence Generators We only focus on the following three circuits PR (pseudo random)-sequence generator Ring counter Johnson counter

Primitive Polynomials

Maximal Length Sequence Generators

A PR-Sequence Generator Example A 4-bit example primitive polynomial: 1 + x + x4

A PR-Sequence Generator Example // an N-bit pr_sequence generator module --- in standard form module pr_sequence_generate (clk, qout); parameter N = 4; // define the default size parameter [N:0] tap = 5'b10011; … output reg [N-1:0] qout = 4’b0100; wire d; assign d = ^(tap[N-1:0] & qout[N-1:0]); always @(posedge clk) qout <= {d, qout[N-1:1]}; Q: Write an N-bit pr_sequence generator in modular form.

A PR-Sequence Generator Example // an N-bit pr_sequence generator module --- in standard form module pr_sequence_generate (clk, start, qout); parameter N = 4; // define the default size parameter [N:0] tap = 5'b10011; … output reg [N-1:0] qout; wire d; assign d = ^(tap[N-1:0] & qout[N-1:0]); always @(posedge clk or posedge start) if (start) qout <= {1'b1, {N-1{1'b0}}}; else qout <= {d, qout[N-1:1]};

Ring Counters // a ring counter with initial value module ring_counter(clk, start, qout); parameter N = 4; … output reg [0:N-1] qout; always @(posedge clk or posedge start) if (start) qout <= {1'b1,{N-1{1'b0}}}; else qout <= {qout[N-1], qout[0:N-2]};

Johnson Counters // Johnson counter with initial value module ring_counter(clk, start, qout); parameter N = 4; // define the default size … output reg [0:N-1] qout; always @(posedge clk or posedge start) if (start) qout <= {N{1'b0}}; else qout <= {~qout[N-1], qout[0:N-2]};

Syllabus Objectives Fundamentals of sequential logic modules Flip-flops Memory elements Shift registers Counters Sequence generators Timing generators

Timing Generators A timing generator Multiphase clock signals Ring counter Binary counter with decoder Digital monostable circuits Retriggerable Nonretriggerable

Multiphase Clock Signals Ways of generation Ring counter approach Binary counter with decoder approach

Multiphase Clock Generators Binary counter with decoder approach n = 4 and m =2

Multiphase Clock Generators // a binary counter with decoder serve as a timing generator module binary_counter_timing_generator(clk, reset, enable, qout); parameter N = 8; // the number of phases parameter M = 3; // the bit number of binary counter … output reg [N-1:0] qout; reg [M-1:0] bcnt_out; always @(posedge clk or posedge reset) if (reset) bcnt_out <= {M{1'b0}}; else if (enable) bcnt_out <= bcnt_out + 1; always @(bcnt_out) qout = {N-1{1'b0},1'b1} << bcnt_out;