Counters Discussion D8.3.

Slides:



Advertisements
Similar presentations
Digital System Design-II (CSEB312)
Advertisements

D Flip-Flop.
FSM and Efficient Synthesizable FSM Design using Verilog
//HDL Example 8-2 // //RTL description of design example (Fig.8-9) module Example_RTL (S,CLK,Clr,E,F,A);
General Sequential Design
Verilog in transistor level using Microwind
CDA 3100 Recitation Week 11.
Sequential Logic in Verilog
Synchronous Sequential Logic
Multiplication and Division
Verilog Modules for Common Digital Functions
Review for Exam 2 Using MUXs to implement logic
Table 7.1 Verilog Operators.
CSE 201 Computer Logic Design * * * * * * * Verilog Modeling
//HDL Example 5-1 // //Description of D latch (See Fig.5-6) module D_latch (Q,D,control); output Q; input.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
Analysis of Clocked Sequential Circuits
Give qualifications of instructors: DAP
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
How to get a Circuit in verilog converted to hspice, connected to the micron package models, and simulating in hspice and hsimplus.
Registers and Counters. Register Register is built with gates, but has memory. The only type of flip-flop required in this class – the D flip-flop – Has.
Latches and Flip-Flops Discussion D8.1 Section 13-9.
FSM examples.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
Pulse-Width Modulated DAC
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
Logic Design Review – 3 Basic Sequential Circuits Lecture L14.3 Verilog.
Ring Counter Discussion 11.3 Example 32.
Arbitrary Waveform Discussion 12.2 Example 34. Recall Divide-by-8 Counter Use q2, q1, q0 as inputs to a combinational circuit to produce an arbitrary.
Counters Discussion 12.1 Example 33. Counters 3-Bit, Divide-by-8 Counter 3-Bit Behavioral Counter in Verilog Modulo-5 Counter An N-Bit Counter.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Registers and Shift Registers Discussion D8.2. D Flip-Flop X 0 Q 0 ~Q 0 D CLK Q ~Q D gets latched to Q on the rising edge of the clock. Positive.
D Flip-Flops in Verilog Discussion 10.3 Example 27.
CS 140L Lecture 4 Professor CK Cheng 10/22/02. 1)F-F 2)Shift register 3)Counter (Asynchronous) 4)Counter (Synchronous)
Introduction Verilog is a HARDWARE DESCRIPTION LANGUAGE (HDL) A hardware description language is a language or means used to describe or model a digital.
ECE/CS 352 Digital System Fundamentals© 2001 C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Spring 2001 Chapters 3 and 4: Verilog – Part 2 Charles R.
Traffic Lights Discussion D8.3a. Recall Divide-by-8 Counter Use Q2, Q1, Q0 as inputs to a combinational circuit to produce an arbitrary waveform. s0 0.
Digital Electronics.
A sequential logic circuit (a.k.a. state machine) consists of both combinational logic circuit(s) and memory devices (flip flops). The combinational circuits.
D Flip Flop. Also called: Delay FF Data FF D-type Latches ‘Delayed 1 Clock Pulse’
Chapter 8 Solving Larger Sequential Problems.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Supplement on Verilog FF circuit examples
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
Quad D Flip Flop Index Circuit Error Judgment Scenario
D Flip-Flop.
T Flip-Flop A T (toggle) flip-flop is a complementing flip-flop and can be obtained from a JK flip-flop when the two inputs are tied together. When T.
Registers and Counters
CS Fall 2005 – Lec. #5 – Sequential Logic - 1
Counters as State Machines
Pulse-Width Modulation (PWM)
Digital Logic Design Digital Design, M. Morris Mano and Michael D
Recap D flip-flop based counter Flip-flop transition table
Digital Logic & Design Dr. Waseem Ikram Lecture No. 31.
CSE 370 – Winter Sequential Logic-2 - 1
Assignment 1.
Verilog.
Registers and Counters
COE 202 Introduction to Verilog
MTE 202, Summer 2016 Digital Circuits Dr.-Ing. Saleh Hussin
Lecture No. 32 Sequential Logic.
The Verilog Hardware Description Language
SYEN 3330 Digital Systems Chapter 6 – Part 3 SYEN 3330 Digital Systems.
FINITE STATE MACHINES.
ANALYSIS OF SEQUENTIAL CIRCUIT LOGIC DIAGRAM
Registers and Counters
Registers and Counters
Registers and Counters
Presentation transcript:

Counters Discussion D8.3

Counters Divide-by-8 Counter Behavioral Counter in Verilog Counter using One-Hot State Machine

Divide-by-8 Counter A state diagram for a divide by 8 counter

Divide-by-8 Counter s0 0 0 0 0 0 1 s1 0 0 1 0 1 0 s2 0 1 0 0 1 1 State Q2 Q1 Q0 D2 D1 D0 Present state Next state A state-transition table

Divide-by-8 Counter s0 0 0 0 0 0 1 s1 0 0 1 0 1 0 s2 0 1 0 0 1 1 State Q2 Q1 Q0 D2 D1 D0 Present state Next state Q0 Q1 Q2 D0 D1 D2

Divide-by-8 Counter s0 0 0 0 0 0 1 s1 0 0 1 0 1 0 s2 0 1 0 0 1 1 Q1 Q0 s0 0 0 0 0 0 1 s1 0 0 1 0 1 0 s2 0 1 0 0 1 1 s3 0 1 1 1 0 0 s4 1 0 0 1 0 1 s5 1 0 1 1 1 0 s6 1 1 0 1 1 1 s7 1 1 1 0 0 0 State Q2 Q1 Q0 D2 D1 D0 Present state Next state 00 01 11 10 Q2 1 1 1 1 1 D2 D2 = ~Q2 & Q1 & Q0 | Q2 & ~Q1 | Q2 & ~Q0

Divide-by-8 Counter s0 0 0 0 0 0 1 s1 0 0 1 0 1 0 s2 0 1 0 0 1 1 State Q2 Q1 Q0 D2 D1 D0 Present state Next state Q1 Q0 00 01 11 10 Q2 1 1 1 1 1 D1 D1 = ~Q1 & Q0 | Q1 & ~Q0

Divide-by-8 Counter s0 0 0 0 0 0 1 s1 0 0 1 0 1 0 s2 0 1 0 0 1 1 State Q2 Q1 Q0 D2 D1 D0 Present state Next state Q1 Q0 00 01 11 10 Q2 1 1 1 1 1 D0 D0 = ~Q0

Divide-by-8 Counter A Divide by 8 counter Circuit using D Flip-flops

module DFF (D, clk, clr, Q); input clk ; wire clk ; input clr ; wire clr ; input D ; wire D ; output Q ; reg Q ; always @(posedge clk or posedge clr) if(clr == 1) Q <= 0; else Q <= D; endmodule

Q0 Q1 Q2 D0 D1 D2 module count3 ( Q ,clr ,clk ); input clr ; wire clr ; input clk ; wire clk ; output [2:0] Q ; wire [2:0] Q ; wire [2:0] D ; assign D[2] = ~Q[2] & Q[1] & Q[0] | Q[2] & ~Q[1] | Q[2] & ~Q[0]; assign D[1] = ~Q[1] & Q[0] | Q[1] & ~Q[0]; assign D[0] = ~Q[0]; DFF U2(.D(D[2]), .clk(clk), .clr(clr), .Q(Q[2])); DFF U1(.D(D[1]), .clk(clk), .clr(clr), .Q(Q[1])); DFF U0(.D(D[0]), .clk(clk), .clr(clr), .Q(Q[0])); endmodule Q0 Q1 Q2 D0 D1 D2

count3 Simulation

Counters Divide-by-8 Counter Behavioral Counter in Verilog Counter using One-Hot State Machine

3-Bit Counter Behavior clr count3 Q(2 downto 0) clk always @(posedge clk or posedge clr) begin if(clr == 1) Q <= 0; else Q <= Q + 1; end

counter3.v module counter3 (clk, clr, Q ); input clr ; wire clr ; input clk ; wire clk ; output [2:0] Q ; reg [2:0] Q ; // 3-bit counter always @(posedge clk or posedge clr) begin if(clr == 1) Q <= 0; else Q <= Q + 1; end endmodule Asynchronous clear Output count increments on rising edge of clk

counter3 Simulation

Recall Divide-by-8 Counter Q0 Q1 Q2 D0 D1 D2 s0 0 0 0 0 0 1 s1 0 0 1 0 1 0 s2 0 1 0 0 1 1 s3 0 1 1 1 0 0 s4 1 0 0 1 0 1 s5 1 0 1 1 1 0 s6 1 1 0 1 1 1 s7 1 1 1 0 0 0 State Q2 Q1 Q0 D2 D1 D0 Present state Next state Use Q2, Q1, Q0 as inputs to a combinational circuit to produce an arbitrary waveform.

Example State Q2 Q1 Q0 D2 D1 D0 y Q2 Q1 Q0 00 01 11 10 1 s0 0 0 0 0 0 1 1 s1 0 0 1 0 1 0 1 s2 0 1 0 0 1 1 0 s3 0 1 1 1 0 0 0 s4 1 0 0 1 0 1 0 s5 1 0 1 1 1 0 1 s6 1 1 0 1 1 1 0 s7 1 1 1 0 0 0 1 y = ~Q2 & ~Q1 | Q2 & Q0 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1

Counters Divide-by-8 Counter Behavioral Counter in Verilog Counter using One-Hot State Machine

One-Hot State Machines Q0 Q1 Q2 D0 D1 D2 Instead of using the minimum number of flip-flops (3) to implement the state machine, one-hot encoding uses one flip-flop per state (8) to implement the state machine.

Why use One-Hot State Machines? Using one-hot encoding or one flip-flop per state (8) will normally simplify the combinational logic at the expense of more flip-flops. Let's see how for the 3-bit counter

One-Hot Encoding Think of each state as a flip-flop s0 0 0 0 s1 Present state Next state State Q2 Q1 Q0 D[0:7] Think of each state as a flip-flop s0 0 0 0 s1 s1 0 0 1 s2 s2 0 1 0 s3 s3 0 1 1 s4 s4 1 0 0 s5 s5 1 0 1 s6 s6 1 1 0 s7 s7 1 1 1 s0 D[i] = s[i-1] This is just a ring counter!

3-bit Counter State Q2 Q1 Q0 s0 0 0 0 s1 0 0 1 s2 0 1 0 s3 0 1 1 s4 1 0 0 s5 1 0 1 s6 1 1 0 s7 1 1 1 Q2 = s4 | s5 | s6 | s7 Q1 = s2 | s3 | s6 | s7 Q0 = s1 | s3 | s5 | s7

module cnt3hot1(clk,clr,Q); input clk; input clr; output [2:0] Q; wire [2:0] Q; reg [0:7] s; // 8-bit Ring Counter always @(posedge clk or posedge clr) begin if(clr == 1) s <= 8'b10000000; else s[0] <= s[7]; s[1:7] <= s[0:6]; end // 3-bit counter assign Q[2] = s[4] | s[5] | s[6] | s[7]; assign Q[1] = s[2] | s[3] | s[6] | s[7]; assign Q[0] = s[1] | s[3] | s[5] | s[7]; endmodule