David Culler Electrical Engineering and Computer Sciences

Slides:



Advertisements
Similar presentations
COUNTERS Counters with Inputs Kinds of Counters Asynchronous vs
Advertisements

Lecture 23: Registers and Counters (2)
Registers and Counters
Table 7.1 Verilog Operators.
Announcements Assignment 7 posted, due Friday 18 th All project components ordered Dates –Thursday 12/1 review lecture –Tuesday 12/6 project demonstrations.
FSMs 1 Sequential logic implementation  Sequential circuits  primitive sequential elements  combinational logic  Models for representing sequential.
Contemporary Logic Design Sequential Case Studies © R.H. Katz Transparency No Chapter #7: Sequential Logic Case Studies 7.1, 7.2 Counters.
Registers and Counters
11/16/2004EE 42 fall 2004 lecture 331 Lecture #33: Some example circuits Last lecture: –Edge triggers –Registers This lecture: –Example circuits –shift.
Logic and Computer Design Fundamentals Registers and Counters
11/15/2004EE 42 fall 2004 lecture 321 Lecture #32 Registers, counters etc. Last lecture: –Digital circuits with feedback –Clocks –Flip-Flops This Lecture:
ENGIN112 L27: Counters November 5, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 27 Counters.
Sequential PLD timing Registers Counters Shift registers
Chapter 7 - Part 2 1 CPEN Digital System Design Chapter 7 – Registers and Register Transfers Part 2 – Counters, Register Cells, Buses, & Serial Operations.
ELEN 468 Advanced Logic Design
ECE C03 Lecture 91 Lecture 9 Registers, Counters and Shifters Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
ENGIN112 L26: Shift Registers November 3, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 26 Shift Registers.
Mantıksal Tasarım – BBM231 M. Önder Efe
1 Digital Design: Sequential Logic Blocks Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals.
Counters and Registers
Lecture 21 Overview Counters Sequential logic design.
1 Lecture 15 Registers Counters Finite State Machine (FSM) design.
A State Element “Zoo”.
Registers and Counters
Chapter 1_4 Part II Counters
Sequential Circuits Chapter 4 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
Registers and Counters
ECE2030 Introduction to Computer Engineering Lecture 15: Registers, Toggle Cells, Counters Prof. Hsien-Hsin Sean Lee School of Electrical and Computer.
Registers and Counters
EE24C Digital Electronics Projects
Figure 7.1. Control of an alarm system. Memory element Alarm Sensor Reset Set OnOff 
Registers & Counters M. Önder Efe
Registers CPE 49 RMUTI KOTAT.
Rabie A. Ramadan Lecture 3
SEQUENTIAL CIRCUITS Component Design and Use. Register with Parallel Load  Register: Group of Flip-Flops  Ex: D Flip-Flops  Holds a Word of Data 
2017/4/24 CHAPTER 6 Counters Chapter 5 (Sections )
Princess Sumaya Univ. Computer Engineering Dept. Chapter 6:
EE365 Adv. Digital Circuit Design Clarkson University Lecture #12 Registers and Counters.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 17 Dr. Shi Dept. of Electrical and Computer Engineering.
1 CSE370, Lecture 15 Lecture 15 u Logistics n HW5 due this Friday n HW6 out today, due Friday Feb 20 n I will be away Friday, so no office hour n Bruce.
7-6 단일 레지스터에서 Microoperation Multiplexer-Based Transfer  Register 가 서로 다른 시간에 둘 이상의 source 에서 data 를 받을 경우 If (K1=1) then (R0 ←R1) else if (K2=1) then.
ENG241 Digital Design Week #8 Registers and Counters.
Registers and Counters Chapter 6. Digital Circuits 2 Clocked sequential circuits a group of flip-flops and combinational gates connected to form a feedback.
Chap 5. Registers and Counters. Chap Definition of Register and Counter l a clocked sequential circuit o consist of a group of flip-flops & combinational.
Registers Page 1. Page 2 What is a Register?  A Register is a collection of flip-flops with some common function or characteristic  Control signals.
Abdullah Said Alkalbani University of Buraimi
Digital Logic Design.
Sequential logic circuits
EE121 John Wakerly Lecture #9
Counters.
Digital System Design using VHDL
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.
Chap 5. Registers and Counters
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Dr. Shi Dept. of Electrical and Computer Engineering.
RTL Hardware Design by P. Chu Chapter 9 – ECE420 (CSUN) Mirzaei 1 Sequential Circuit Design: Practice Shahnam Mirzaei, PhD Spring 2016 California State.
1 Modeling Synchronous Logic Circuits Debdeep Mukhopadhyay Associate Professor Dept of Computer Science and Engineering NYU Shanghai and IIT Kharagpur.
Digital Design: Sequential Logic Blocks
Registers and Counters
Sequential Logic Combinational logic:
EKT 221 – Counters.
Prof. Hsien-Hsin Sean Lee
EKT 221 : Digital 2 COUNTERS.
Typical Timing Specifications
Instructor: Alexander Stoytchev
CS Fall 2005 – Lec. #5 – Sequential Logic - 1
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN
CSE 370 – Winter Sequential Logic-2 - 1
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
Presentation transcript:

EECS 150 - Components and Design Techniques for Digital Systems Lec 09 – Counters 9-28-04 David Culler Electrical Engineering and Computer Sciences University of California, Berkeley http://www.eecs.berkeley.edu/~culler http://www-inst.eecs.berkeley.edu/~cs150

Review: Designing with FSM FSMs are critical tool in your design toolbox Adapters, Protocols, Datapath Controllers, … They often interact with other FSMs Important to design each well and to make them work together well. Keep your verilog FSMs clean Separate combinational part from state update Good state machine design is an iterative process State encoding Reduction Assignment 9/28/04 EECS150 Fa04 Lec9 Counters

Outline Review Registers Simple, important FSMs Ring counters Binary Counters Universal Shift Register Using Counters to build controllers Different approach to FSM design 9/28/04 EECS150 Fa04 Lec9 Counters

Registers Collections of flip-flops with similar controls and logic Stored values somehow related (e.g., form binary value) Share clock, reset, and set lines Similar logic at each stage Examples Shift registers Counters R S D Q OUT1 OUT2 OUT3 OUT4 CLK IN1 IN2 IN3 IN4 "0" 9/28/04 EECS150 Fa04 Lec9 Counters

Shift-registers Parallel load shift register: “Parallel-to-serial converter” Also, works as “Serial-to-parallel converter”, if q values are connected out. Also get used as controllers (ala “ring counters”) 9/28/04 EECS150 Fa04 Lec9 Counters

Shift Register D Q IN OUT1 OUT2 OUT3 OUT4 CLK module shift_reg (out4, out3, out2, out1, in, clk); output out4, out3, out2, out1; input in, clk; reg out4, out3, out2, out1; always @(posedge clk) begin out4 <= out3; out3 <= out2; out2 <= out1; out1 <= in; end endmodule What does this shift register do? What is it good for? 9/28/04 EECS150 Fa04 Lec9 Counters

Shift Register Verilog module shift_reg (out, in, clk); output [4:1] out; input in, clk; reg [4:1] out; always @(posedge clk) begin out <= {out[3:1], in}; end endmodule 9/28/04 EECS150 Fa04 Lec9 Counters

Shift Register Application Parallel-to-serial conversion for serial transmission parallel outputs parallel inputs serial transmission 9/28/04 EECS150 Fa04 Lec9 Counters

Register with selective load We often use registers to hold values for multiple clocks Wait until needed Used multiple times How do we modify our D flipflop so that it holds the value till we are done with it? A very simple FSM En State Next 0 Q Q 1 Q D D Q D Q enable clk enable clk 9/28/04 EECS150 Fa04 Lec9 Counters

IQ: Design Register with Set/Reset S R State Next 0 0 Q Q 0 1 Q 0 1 0 Q 1 1 1 Q X D Q Set forces state to 1 Reset forces state to 0 What might be a useful fourth option? 9/28/04 EECS150 Fa04 Lec9 Counters

Counters Special sequential circuits (FSMs) that repeatedly sequence through a set of outputs. Examples: binary counter: 000, 001, 010, 011, 100, 101, 110, 111, 000, 001, … gray code counter: 000, 010, 110, 100, 101, 111, 011, 001, 000, 010, 110, … one-hot counter: 0001, 0010, 0100, 1000, 0001, 0010, … BCD counter: 0000, 0001, 0010, …, 1001, 0000, 0001 pseudo-random sequence generators: 10, 01, 00, 11, 10, 01, 00, ... Moore machines with “ring” structure to STD: S0 S3 S1 S2 9/28/04 EECS150 Fa04 Lec9 Counters

What are they used? Examples: 16MHz 64 Clock divider circuits Delays, Timing Protocols Counters simplify controller design… More on this later 16MHz 64 9/28/04 EECS150 Fa04 Lec9 Counters

How do we design counters? For binary counters (most common case) incrementer circuit would work: In Verilog, a counter is specified as: x = x+1; This does not imply an adder An incrementer is simpler than an adder And a counter is simpler yet. In general, the best way to understand counter design is to think of them as FSMs, and follow general procedure. Here’s a important examples… 1 + register 9/28/04 EECS150 Fa04 Lec9 Counters

Counters Sequences through a fixed set of patterns In this case, 1000, 0100, 0010, 0001 If one of the patterns is its initial state (by loading or set/reset) Mobius (or Johnson) counter In this case, 1000, 1100, 1110, 1111, 0111, 0011, 0001, 0000 D Q IN OUT1 OUT2 OUT3 OUT4 CLK D Q IN OUT1 OUT2 OUT3 OUT4 CLK 9/28/04 EECS150 Fa04 Lec9 Counters

Ring Counters – getting started “one-hot” counters0001, 0010, 0100, 1000, 0001, … “Self-starting” version: What are these good for? 9/28/04 EECS150 Fa04 Lec9 Counters

Ring Counters (cont) 9/28/04 EECS150 Fa04 Lec9 Counters

Announcements Reading: Katz 7.1, 9.1-2 Midterm Oct 7 (week from thurs) Regular class time and location Covers all material thru oct 5 10/5 lecture will be “putting it all together” Review session evening of Oct 5 See web page for specifics HW 4 (current) is a good exercise HW 5 (out thurs) will be light 9/28/04 EECS150 Fa04 Lec9 Counters

Synchronous Counters All outputs change with clock edge. a+ = a’ b+ = a  b cb a 00 01 11 10 0 0 0 1 1 1 0 1 0 1 c+ = a’c + abc’ + b’c = c(a’+b’) + c’(ab) = c(ab)’ + c’(ab) = c  ab Binary Counter Design: Start with 3-bit version and generalize: c b a c+ b+ a+ 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 0 1 1 1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 0 0 0 9/28/04 EECS150 Fa04 Lec9 Counters

Binary Counter Logic between registers (not just multiplexer) XOR decides when bit should be toggled Always for low-order bit, only when first bit is true for second bit, and so on D Q OUT1 OUT2 OUT3 OUT4 CLK "1" 9/28/04 EECS150 Fa04 Lec9 Counters

Binary Counter Verilog module counter (out4, out3, out2, out1, clk); output out4, out3, out2, out1; input in, clk; reg out4, out3, out2, out1; always @(posedge clk) begin out4 <= (out1 & out2 & out3) ^ out4; out3 <= (out1 & out2) ^ out3; out2 <= out1 ^ out2; out1 <= out1 ^ 1b’1; end endmodule 9/28/04 EECS150 Fa04 Lec9 Counters

Binary Counter Verilog module counter (out4, out3, out2, out1, clk); output [4:1] out; input in, clk; reg [4:1] out; always @(posedge clk) out <= out + 1; endmodule 9/28/04 EECS150 Fa04 Lec9 Counters

Synchronous Counters How do we extend to n-bits? Extrapolate c+: d+ = d  abc, e+ = e  abcd Has difficulty scaling (AND gate inputs grow with n) CE is “count enable”, allows external control of counting, TC is “terminal count”, is asserted on highest value, allows cascading, external sensing of occurrence of max value. Tb=CE*A Tc=CE*A*B Td=CE*A*B*C TC 9/28/04 EECS150 Fa04 Lec9 Counters

Synchronous Counters How does this one scale? Delay grows  n TC How does this one scale? Delay grows  n Generation of TC signals very similar to generation of carry signals in adder. “Parallel Prefix” circuit reduces delay: log2n log2n 9/28/04 EECS150 Fa04 Lec9 Counters

Four-bit Binary Synchronous Up-Counter Standard component with many applications Positive edge-triggered FFs w/ sync load and clear inputs Parallel load data from D, C, B, A Enable inputs: must be asserted to enable counting RCO: ripple-carry out used for cascading counters high when counter is in its highest state 1111 implemented using an AND gate EN D C B A LOAD CLK CLR RCO QD QC QB QA (2) RCO goes high (3) High order 4-bits are incremented (1) Low order 4-bits = 1111 9/28/04 EECS150 Fa04 Lec9 Counters

“Ripple” counters Discouraged 0000 0001 0010 0011 0100 0101 0110 0111 A3 A2 A1 A0 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Each stage is 2 of previous. Look at output waveforms: Often called “asynchronous” counters. A “T” flip-flop is a “toggle” flip-flop. Flips it state on cycles when T=1. time Discouraged Know it exists Don’t use it CLK A0 A1 A2 A3 9/28/04 EECS150 Fa04 Lec9 Counters

Up-Down Counter c b a c+ b+ a+ 0 0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 Down-count Note: correct clocking 9/28/04 EECS150 Fa04 Lec9 Counters

Odd Counts Extra combinational logic can be added to terminate count before max value is reached: Example: count to 12 Alternative: 9/28/04 EECS150 Fa04 Lec9 Counters

Offset Counters Starting offset counters – use of synchronous load e.g., 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1111, 0110, . . . Ending offset counter – comparator for ending value e.g., 0000, 0001, 0010, ..., 1100, 1101, 0000 Combinations of the above (start and stop value) "0" EN D C B A LOAD CLK CLR RCO QD QC QB QA "1" "0" "1" "1" "0" EN D C B A LOAD CLK CLR RCO QD QC QB QA "1" "0" "0" "0" "0" 9/28/04 EECS150 Fa04 Lec9 Counters

Universal Shift Register Holds 4 values Serial or parallel inputs Serial or parallel outputs Permits shift left or right Shift in new values from left or right left_in left_out right_out clear right_in output input s0 s1 clock clear sets the register contents and output to 0 s1 and s0 determine the shift function s0 s1 function 0 0 hold state 0 1 shift right 1 0 shift left 1 1 load new input 9/28/04 EECS150 Fa04 Lec9 Counters

Design of Universal Shift Register Consider one of the four flip-flops New value at next clock cycle: Nth cell to N-1th cell to N+1th cell Q D CLK clear s0 s1 new value 1 – – 0 0 0 0 output 0 0 1 output value of FF to left (shift right) 0 1 0 output value of FF to right (shift left) 0 1 1 input CLEAR s0 and s1 control mux 1 2 3 Q[N-1] (left) Q[N+1] (right) Input[N] 9/28/04 EECS150 Fa04 Lec9 Counters

Universal Shift Register Verilog module univ_shift (out, lo, ro, in, li, ri, s, clr, clk); output [3:0] out; output lo, ro; input [3:0] in; input [1:0] s; input li, ri, clr, clk; reg [3:0] out; assign lo = out[3]; assign ro = out[0]; always @(posedge clk or clr) begin if (clr) out <= 0; else case (s) 3: out <= in; 2: out <= {out[2:0], ri}; 1: out <= {li, out[3:1]}; 0: out <= out; endcase end endmodule 9/28/04 EECS150 Fa04 Lec9 Counters

Pattern Recognizer Combinational function of input samples In this case, recognizing the pattern 1001 on the single input signal D Q IN OUT1 OUT2 OUT3 OUT4 CLK OUT 9/28/04 EECS150 Fa04 Lec9 Counters

Counters for Control Big idea: to solve a big controller problem, build a very simple controller and then use it as a tool. Datapath Controller 9/28/04 EECS150 Fa04 Lec9 Counters

Recall: Byte-bit stream with Rate Matching Byte FIFO init / LD bit 0/pop ~rdy bit 0’ bit 1 ~rdy rdy rdy ~rdy pop bit 2 ~rdy rdy controller Shift register bit 3 ~rdy rdy LD bit 4 ~rdy rdy bit 5 Serial link ~rdy rdy rdy bit 6 ~rdy rdy How would you implement this FSM? bit 7 / LD ~rdy rdy 9/28/04 EECS150 Fa04 Lec9 Counters

Counter for Sequencing States bit 0/pop 01000000 / LD init / LD bit 0’ ~rdy 00000001 rdy 00000010 00000100 00001000 00010000 00100000 Shift Reg Or Ring Counter init / LD bit 0/pop ~rdy bit 0’ 0001 ~rdy rdy rdy ~rdy 0010 ~rdy rdy 0011 ~rdy rdy Binary Counter 0100 ~rdy rdy 0101 ~rdy rdy 0110 ~rdy rdy 0111 / LD 9/28/04 EECS150 Fa04 Lec9 Counters

CLR for “back to top” 0000/pop init / LD 0000/pop ~rdy ~rdy bit 0’ 0001 bit 0’ 0001 ~rdy rdy ~rdy rdy rdy rdy ~rdy ~rdy 0010 0010 ~rdy rdy ~rdy rdy 0011 0011 ~rdy rdy ~rdy rdy Binary Counter 0100 0100 ~rdy rdy ~rdy rdy 0101 0101 ~rdy rdy ~rdy rdy 0110 0110 ~rdy rdy ~rdy rdy init 0111 / LD, clr 0111 / LD, clr 9/28/04 EECS150 Fa04 Lec9 Counters

Count_Enable for Self-loop 0000/pop CE = rdy or (state == 0000) ~rdy rdy bit 0’ 0001 ~rdy rdy rdy ~rdy 0010 ~rdy rdy 0011 ~rdy rdy n-bit counter 0100 ~rdy rdy LD CE 0101 ~rdy rdy 0110 ~rdy rdy rdy init 0111 / LD, clr 9/28/04 EECS150 Fa04 Lec9 Counters

Branch with LD (jump counter) X ~in in y X+1 n-bit counter LD CE ~selfloop in 9/28/04 EECS150 Fa04 Lec9 Counters

Jumping 0000/pop LD = (State === 0000 & ~rdy) or (state == 1111) S = (state == 0000) ~rdy rdy 1111 0001 ~rdy rdy rdy ~rdy 0010 ~rdy rdy 0011 ~rdy rdy 4 0100 ~rdy rdy 0001 4 4 4 0101 ~rdy rdy 1111 1 s 0110 ~rdy rdy 0111 / LD, clr LD CE init 9/28/04 EECS150 Fa04 Lec9 Counters

Another Controller using Counters Example, Bit-serial multiplier: Control Algorithm: repeat n cycles { // outer (i) loop repeat n cycles{ // inner (j) loop shiftA, selectSum, shiftHI } shiftB, shiftHI, shiftLOW, reset Note: The occurrence of a control signal x means x=1. The absence of x means x=0. 9/28/04 EECS150 Fa04 Lec9 Counters

Counter provides subsidiary state State Transition Diagram: Assume presence of two binary counters. An “i” counter for the outer loop and “j” counter for inner loop. TC is asserted when the counter reaches it maximum count value. CE is “clock enable”. The counter increments its value on the rising edge of the clock if CE is asserted. 9/28/04 EECS150 Fa04 Lec9 Counters

Summary Basic registers Simple, important FSMs Common control, MUXes Simple, important FSMs simple internal feedback Ring counters, Pattern detectors Binary Counters Universal Shift Register Using Counters to build controllers Simplify control by controlling simpler FSM 9/28/04 EECS150 Fa04 Lec9 Counters