Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec 09 Counters Outline.

Similar documents
Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec09 Counters Outline.

EECS150 - Digital Design Lecture 18 - Counters

EECS150 - Digital Design Lecture 18 - Counters

EECS150 - Digital Design Lecture 17 - Sequential Circuits 3 (Counters)

EECS150 - Digital Design Lecture 11 - Shifters & Counters. Register Summary

EECS150 - Digital Design Lecture 16 Counters. Announcements

EECS150 - Digital Design Lecture 23 - FSMs & Counters

EECS150 - Digital Design Lecture 25 Shifters and Counters. Recap

EECS Components and Design Techniques for Digital Systems. FSMs 9/11/2007

Introduction EE 224: INTRODUCTION TO DIGITAL CIRCUITS & COMPUTER DESIGN. Lecture 6: Sequential Logic 3 Registers & Counters 5/9/2010

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

Parity Checker Example. EECS150 - Digital Design Lecture 9 - Finite State Machines 1. Formal Design Process. Formal Design Process

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

ECE 341. Lecture # 3

Models for representing sequential circuits

Ch 7. Finite State Machines. VII - Finite State Machines Contemporary Logic Design 1

Generalized FSM model: Moore and Mealy

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 9 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

CSE140: Components and Design Techniques for Digital Systems. Midterm Information. Instructor: Mohsen Imani. Sources: TSR, Katz, Boriello & Vahid

CHW 261: Logic Design

LOGIC CIRCUITS. Basic Experiment and Design of Electronics

COE 202: Digital Logic Design Sequential Circuits Part 4. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Digital Circuits ECS 371

LOGIC CIRCUITS. Basic Experiment and Design of Electronics. Ho Kyung Kim, Ph.D.

CSE140: Digital Logic Design Registers and Counters

Logic Design II (17.342) Spring Lecture Outline

Digital Fundamentals

Appendix B. Review of Digital Logic. Baback Izadi Division of Engineering Programs

L4: Sequential Building Blocks (Flip-flops, Latches and Registers)

Chapter #7: Sequential Logic Case Studies Contemporary Logic Design

L4: Sequential Building Blocks (Flip-flops, Latches and Registers)

EECS150 - Digital Design Lecture 24 - Arithmetic Blocks, Part 2 + Shifters

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

FSM model for sequential circuits

ALU, Latches and Flip-Flops

Example: vending machine

10/12/2016. An FSM with No Inputs Moves from State to State. ECE 120: Introduction to Computing. Eventually, the States Form a Loop

EXPERIMENT Bit Binary Sequential Multiplier

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Digital Techniques

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

Spiral 2-1. Datapath Components: Counters Adders Design Example: Crosswalk Controller

Topics for Lecture #9. Button input processor

Professor Fearing EECS150/Problem Set Solution Fall 2013 Due at 10 am, Thu. Oct. 3 (homework box under stairs)

Preparation of Examination Questions and Exercises: Solutions

EECS Components and Design Techniques for Digital Systems. Lec 26 CRCs, LFSRs (and a little power)

Digital Electronics Circuits 2017

Lecture 10: Synchronous Sequential Circuits Design

EECS150 - Digital Design Lecture 23 - FFs revisited, FIFOs, ECCs, LSFRs. Cross-coupled NOR gates

Last lecture Counter design Finite state machine started vending machine example. Today Continue on the vending machine example Moore/Mealy machines

Counters. We ll look at different kinds of counters and discuss how to build them

Chapter 6. Synchronous Sequential Circuits

EE 209 Spiral 1 Exam Solutions Name:

Present Next state Output state w = 0 w = 1 z A A B 0 B A C 0 C A C 1

Synchronous Sequential Circuit Design. Digital Computer Design

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI

CPE100: Digital Logic Design I

ELEC Digital Logic Circuits Fall 2014 Sequential Circuits (Chapter 6) Finite State Machines (Ch. 7-10)

Roger L. Tokheim. Chapter 8 Counters Glencoe/McGraw-Hill

ELCT201: DIGITAL LOGIC DESIGN

PGT104 Digital Electronics. PGT104 Digital Electronics

Analysis of clocked sequential networks

Chapter 7. Sequential Circuits Registers, Counters, RAM

EE40 Lec 15. Logic Synthesis and Sequential Logic Circuits

BER KELEY D AV IS IR VINE LOS AN GELES RIVERS IDE SAN D IEGO S AN FRANCISCO

University of Toronto Faculty of Applied Science and Engineering Edward S. Rogers Sr. Department of Electrical and Computer Engineering

EECS150 - Digital Design Lecture 15 SIFT2 + FSM. Recap and Outline

Design at the Register Transfer Level

Sample Test Paper - I

SYNCHRONOUS SEQUENTIAL CIRCUITS

S.Y. Diploma : Sem. III [DE/ED/EI/EJ/EN/ET/EV/EX/IC/IE/IS/IU/MU] Principles of Digital Techniques

Lecture 7: Logic design. Combinational logic circuits

Fundamentals of Boolean Algebra

Reg. No. Question Paper Code : B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER Second Semester. Computer Science and Engineering

Digital Electronics Sequential Logic

Computers also need devices capable of Storing data and information Performing mathematical operations on such data

Sequential vs. Combinational

Sequential Logic Worksheet


課程名稱 : 數位邏輯設計 P-1/ /6/11

Synchronous Sequential Circuit Design. Dr. Ehab A. H. AL-Hialy Page 1

Counters. Clocked sequential circuit whose state diagram contains a single cycle. Modulus number of states in the cycle. Counters with nonpower

Ch 9. Sequential Logic Technologies. IX - Sequential Logic Technology Contemporary Logic Design 1

Appendix A: Digital Logic. Principles of Computer Architecture. Principles of Computer Architecture by M. Murdocca and V. Heuring

Digital Design. Sequential Logic

Stop Watch (System Controller Approach)

COE 202: Digital Logic Design Sequential Circuits Part 3. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

EECS150 - Digital Design Lecture 22 - Arithmetic Blocks, Part 1

CS221: Digital Design. Dr. A. Sahu. Indian Institute of Technology Guwahati

CHW 261: Logic Design

Vidyalankar S.E. Sem. III [EXTC] Digital Electronics Prelim Question Paper Solution ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD = B

Digital Fundamentals

Finite State Machine (FSM)

EE 209 Logic Cumulative Exam Name:

Example: A vending machine

Review for Final Exam

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences

Different encodings generate different circuits

Time Allowed 3:00 hrs. April, pages

Lecture 14: State Tables, Diagrams, Latches, and Flip Flop

Written exam with solutions IE Digital Design Friday 21/

Transcription:

Review: esigning with FSM EECS 150 - Components and esign Techniques for igital Systems Lec 09 Counters 9-28-0 avid Culler Electrical Engineering and Computer Sciences University of California, Berkeley http://www.eecs.berkeley.edu/~culler http://www-inst.eecs.berkeley.edu/~cs150 FSMs are critical tool in your design toolbox Adapters, Protocols, atapath 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/0 EECS150 Fa0 Lec9 Counters 2 Outline Review Registers Simple, important FSMs Ring counters Binary Counters Universal Shift Register Using Counters to build controllers ifferent approach to FSM design 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 9/28/0 EECS150 Fa0 Lec9 Counters 3 9/28/0 EECS150 Fa0 Lec9 Counters Shift-registers Parallel load shift register: Shift Register module shift_reg (out, out3, out2, out1, in, clk); output out, out3, out2, out1; reg out, out3, out2, out1; 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/0 EECS150 Fa0 Lec9 Counters 5 out <= out3; out3 <= out2; out2 <= out1; out1 <= in; What does this shift register do? What is it good for? 9/28/0 EECS150 Fa0 Lec9 Counters 6 1

Shift Register Verilog module shift_reg (out, in, clk); output [:1] out; reg [:1] out; out <= {out[3:1], in}; Shift Register Application Parallel-to-serial conversion for serial transmission 9/28/0 EECS150 Fa0 Lec9 Counters 7 9/28/0 EECS150 Fa0 Lec9 Counters 8 Register with selective load IQ: esign Register with Set/Reset We often use registers to hold values for multiple clocks Wait until needed Used multiple times How do we modify our flipflop so that it holds the value till we are done with it? A very simple FSM En State Next S R Q S R State Next 0 0 Q Q 0 1 Q 0 1 0 Q 1 1 1 Q X Q 0 Q Q 1 Q Set forces state to 1 Reset forces state to 0 Q clk enable enable clk 9/28/0 EECS150 Fa0 Lec9 Counters 9 What might be a useful fourth option? 9/28/0 EECS150 Fa0 Lec9 Counters 10 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:,,, 1000,,, BC counter: 0000,,,, 1001, 0000, pseudo-random sequence generators: 10, 01, 00, 11, 10, 01, 00,... Moore machines with ring structure to ST: What are they used? Examples: Clock divider circuits elays, Timing Protocols 16MHz 6 Counters simplify controller design» More on this later S3 S0 S2 S1 9/28/0 EECS150 Fa0 Lec9 Counters 11 9/28/0 EECS150 Fa0 Lec9 Counters 12 2

How do we design counters? For binary counters (most common case) incrementer circuit would work: 1 + register 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 9/28/0 EECS150 Fa0 Lec9 Counters 13 Counters Sequences through a fixed set of patterns In this case, 1000,,, 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,,, 0000 9/28/0 EECS150 Fa0 Lec9 Counters 1 Ring Counters getting started Ring Counters (cont) one-hot counters,,, 1000,, q 3 q 2 q 1 q 0 reset Q Q Q Q S R S R S R S R 0 0 0 0 Self-starting version: What are these good for? q 3 q 2 q 1 q 0 Q Q Q Q 9/28/0 EECS150 Fa0 Lec9 Counters 15 9/28/0 EECS150 Fa0 Lec9 Counters 16 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 (current) is a good exercise HW 5 (out thurs) will be light Synchronous Counters All outputs change with clock edge. Binary Counter esign: 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 a + b + c + 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 a b c 9/28/0 EECS150 Fa0 Lec9 Counters 17 9/28/0 EECS150 Fa0 Lec9 Counters 18 3

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 Binary Counter Verilog module counter (out, out3, out2, out1, clk); output out, out3, out2, out1; reg out, out3, out2, out1; out <= (out1 & out2 & out3) ^ out; out3 <= (out1 & out2) ^ out3; out2 <= out1 ^ out2; out1 <= out1 ^ 1b 1; 9/28/0 EECS150 Fa0 Lec9 Counters 19 9/28/0 EECS150 Fa0 Lec9 Counters 20 Binary Counter Verilog module counter (out, out3, out2, out1, clk); output [:1] out; reg [:1] out; out <= out + 1; Synchronous Counters How do we ext to n-bits? Extrapolate c + : d + = d abc, e + = e abcd a + b + c + a b c d Has difficulty scaling (AN gate inputs grow with n) d + CE Tb=CE*A Tc=CE*A*B Td=CE*A*B*C a + b + c + d + 9/28/0 EECS150 Fa0 Lec9 Counters 21 a b c d CE is count enable, allows external control of counting, is terminal count, is asserted on highest value, allows 9/28/0 cascading, external sensing EECS150 Fa0 of occurrence Lec9 Countersof max value. 22 Synchronous Counters CE a + b + a b c d How does this one scale? Generation of signals very similar elay grows α n to generation of carry signals in adder. Parallel Prefix circuit reduces delay: a b c d e f g h c + d + 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, 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 AN gate log 2 n log 2 n (2) RCO goes high (3) High order -bits are incremented (1) Low order -bits = 1111 EN C RCO B A Q QC LOA QB QA CLR 9/28/0 a b EECS150 c c Fa0 d Lec9 e Counters f g 23 9/28/0 EECS150 Fa0 Lec9 Counters 2

Ripple counters A 3 A 2 A 1 A 0 0000 time 0111 1000 1001 1010 1011 1100 1101 1110 1111 iscouraged Know it exists on t use it 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. 9/28/0 EECS150 Fa0 Lec9 Counters 25 A 0 A 1 A 2 A 3 Up-own 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 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 own-count Note: correct clocking 9/28/0 EECS150 Fa0 Lec9 Counters 26 Odd Counts Extra combinational logic can be added to terminate count before max value is reached: Example: count to 12 reset -bit binary counter = 11? = 11? Alternative: load -bit binary counter 9/28/0 EECS150 Fa0 Lec9 Counters 27 Offset Counters Starting offset counters use of synchronous load e.g.,, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1111,,... Ending offset counter comparator for ing value e.g., 0000,,,..., 1100, 1101, 0000 Combinations of the above (start and stop value) CLR 9/28/0 EECS150 Fa0 Lec9 Counters 28 EN C B A LOA CLR EN C B A LOA RCO Q QC QB QA RCO Q QC QB QA Universal Shift Register $& $& Holds values Serial or parallel inputs Serial or parallel outputs Permits shift left or right Shift in new values from left or right "!& "!& '!" # ##!!$$ $!#!$"!!$$ #% esign of Universal Shift Register Consider one of the four flip-flops New value at next clock cycle: %1 2 2 1$33$.!$"!/ 1$33"!.!$$/,! +,-.$/! )* # ( +- 0! +0-."!/ 9/28/0 EECS150 Fa0 Lec9 Counters 29 9/28/0 EECS150 Fa0 Lec9 Counters 30 5

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) 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; case 9/28/0 EECS150 Fa0 Lec9 Counters 31 Pattern Recognizer Combinational function of input samples In this case, recognizing the pattern 1001 on the single input signal 9/28/0 EECS150 Fa0 Lec9 Counters 32 Counters for Control Big idea: to solve a big controller problem, build a very simple controller and then use it as a tool. atapath Controller 9/28/0 EECS150 Fa0 Lec9 Counters 33 Recall: Byte-bit stream with Rate Matching Byte FIFO init / L bit 0/pop bit 0 bit 1 pop bit 2 controller bit 3 Shift register L bit Serial link bit 5 bit 6 How would you implement this FSM? bit 7 / L 9/28/0 EECS150 Fa0 Lec9 Counters 3 Counter for Sequencing States init / L Binary Counter bit 0 bit 0/pop init / L bit 0 Shift Reg bit 0/pop 0000 0111 / L 0000 / L 9/28/0 EECS150 Fa0 Lec9 Counters 35 Or Ring Counter 0000 0000 0000 0000 0000 CLR for back to top init / L 0000/pop 0000/pop bit 0 bit 0 Binary Counter 0111 / L, clr init 0111 / L, clr 9/28/0 EECS150 Fa0 Lec9 Counters 36 6

Count_Enable for Self-loop Branch with L (jump counter) 0000/pop bit 0 CE = or (state == 0000) n-bit counter L CE init 0111 / L, clr 9/28/0 EECS150 Fa0 Lec9 Counters 37 X ~in in y X+1 n-bit counter L CE ~selfloop in 9/28/0 EECS150 Fa0 Lec9 Counters 38 Jumping 0000/pop L = (State === 0000 & ) or (state == 1111) S = (state == 0000) 1111 0 1111 1 s init 0111 / L, clr L CE 9/28/0 EECS150 Fa0 Lec9 Counters 39 Another Controller using Counters Example, Bit-serial multiplier: shifta shiftb A register B register Control Algorithm: FA sum carry -FF reset 0 1 HI register selectsum shifthi shiftlow LOW register 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/0 EECS150 Fa0 Lec9 Counters 0 Counter provides subsidiary state Summary State Transition iagram: Assume presence of two binary counters. An i counter for the outer loop and j counter for inner loop. START CE RST counter 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. ILE CE i,ce j RST i i OUTER <outer contol> CE i,ce j RST j i START INNER <inner contol> CE i,ce j j j Basic registers 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/0 EECS150 Fa0 Lec9 Counters 1 9/28/0 EECS150 Fa0 Lec9 Counters 2 7