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

Similar documents
Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec 09 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

CSE140: Digital Logic Design Registers and Counters

Models for representing sequential circuits

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

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

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

ECE 341. Lecture # 3

ALU, Latches and Flip-Flops

Chapter 6. Synchronous Sequential Circuits

Digital Circuits ECS 371

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

CHW 261: Logic Design

Digital Fundamentals

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

LOGIC CIRCUITS. Basic Experiment and Design of Electronics

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

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

Example: vending machine

Logic Design II (17.342) Spring Lecture Outline

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

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

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

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

EXPERIMENT Bit Binary Sequential Multiplier

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

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

Generalized FSM model: Moore and Mealy

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

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

Design of Datapath Controllers

Digital Electronics Circuits 2017

Synchronous Sequential Circuit Design. Digital Computer Design

Chapter #7: Sequential Logic Case Studies Contemporary Logic Design

FSM model for sequential circuits

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI

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

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

Preparation of Examination Questions and Exercises: Solutions

Design at the Register Transfer Level

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

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

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

CSC 322: Computer Organization Lab

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

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

Register Transfer Level

Review for Final Exam

ELCT201: DIGITAL LOGIC DESIGN

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

State and Finite State Machines

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

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI

Review Problem 1. should be on. door state, false if light should be on when a door is open. v Describe when the dome/interior light of the car

PGT104 Digital Electronics. PGT104 Digital Electronics

Finite State Machine (FSM)

Lecture 7: Logic design. Combinational logic circuits

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

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


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

Lecture 10: Synchronous Sequential Circuits Design

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

Analysis of clocked sequential networks

Sample Test Paper - I

Different encodings generate different circuits

Lecture 13: Sequential Circuits, FSM

Chapter 5 Synchronous Sequential Logic

Sequential Logic Worksheet

EE40 Lec 15. Logic Synthesis and Sequential Logic Circuits

EGR224 F 18 Assignment #4

CHW 261: Logic Design

CPE100: Digital Logic Design I

Sequential vs. Combinational

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

The Design Procedure. Output Equation Determination - Derive output equations from the state table

EE 209 Logic Cumulative Exam Name:

Digital Fundamentals

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

Written exam with solutions IE Digital Design Friday 21/

Fundamentals of Boolean Algebra

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) State any two Boolean laws. (Any 2 laws 1 mark each)

COEN 312 DIGITAL SYSTEMS DESIGN - LECTURE NOTES Concordia University

Chapter 7. Sequential Circuits Registers, Counters, RAM

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

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

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

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

Week-5. Sequential Circuit Design. Acknowledgement: Most of the following slides are adapted from Prof. Kale's slides at UIUC, USA.

EET 310 Flip-Flops 11/17/2011 1

Stop Watch (System Controller Approach)

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

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING BENG (HONS) ELECTRICAL & ELECTRONICS ENGINEERING EXAMINATION SEMESTER /2017

Transcription:

Review: Designing with FSM EECS 150 - Components and Design Techniques for Digital Systems Lec09 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 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/18/07 EECS150 Fa07 Lec7 Counters 2 Outline Review Registers Simple, important FSMs Ring counters Binary Counters Universal Shift Register Using Counters to build controllers Different 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 R S R S R S R S 9/18/07 EECS150 Fa07 Lec7 Counters 3 IN1 IN2 IN3 IN4 9/18/07 EECS150 Fa07 Lec7 Counters 4

Shift-registers Parallel load shift register: Shift Register IN module shift_reg (out4, out3, out2, out1, in, clk); output out4, out3, out2, out1; input in, clk; reg out4, 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/18/07 EECS150 Fa07 Lec7 Counters 5 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/18/07 EECS150 Fa07 Lec7 Counters 6 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 Shift Register Application Parallel-to-serial conversion for serial transmission parallel inputs parallel outputs serial transmission 9/18/07 EECS150 Fa07 Lec7 Counters 7 9/18/07 EECS150 Fa07 Lec7 Counters 8

Register with selective load IQ: Design 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 D flipflop so that it holds the value till we are done with it? A very simple FSM En State Next D S R Q S R State Next 0 0 Q Q 0 1 Q 0 1 0 Q 1 1 1 Q X 0 Q Q 1 Q D Set forces state to 1 Reset forces state to 0 D Q clk D Q What might be a useful fourth option? enable enable clk 9/18/07 EECS150 Fa07 Lec7 Counters 9 9/18/07 EECS150 Fa07 Lec7 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: 0001,,, 1000, 0001,, BCD counter: 0000, 0001,,, 1001, 0000, 0001 pseudo-random sequence generators: 10, 01, 00, 11, 10, 01, 00,... Moore machines with ring structure to STD: What are they used? Examples: Clock divider circuits Delays, Timing Protocols 16MHz 64 Counters simplify controller design» More on this later S3 S0 S2 S1 9/18/07 EECS150 Fa07 Lec7 Counters 11 9/18/07 EECS150 Fa07 Lec7 Counters 12

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/18/07 EECS150 Fa07 Lec7 Counters 13 Counters Sequences through a fixed set of patterns In this case, 1000,,, 0001 If one of the patterns is its initial state (by loading or set/reset) IN IN Mobius (or Johnson) counter In this case, 1000, 1100, 1110, 1111, 0111,, 0001, 0000 9/18/07 EECS150 Fa07 Lec7 Counters 14 Ring Counters getting started Ring Counters (cont) one-hot counters0001,,, 1000, 0001, q 3 q 2 q 1 q 0 reset 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 9/18/07 EECS150 Fa07 Lec7 Counters 15 9/18/07 EECS150 Fa07 Lec7 Counters 16

Announcements Reading: K&B 7.1, app C. Midterm 9/27 (week from thurs) Regular class time. In Lab 125 Cory Covers all material thru 9/23» 9/23 lecture will be putting it all together Review session 9/27 8-10 See web page for additional specifics HW 3 (current) is a good exercise (and short) HW 4 (out thurs) will be light, then skip a week Thurs Evening Lab is a problem! Too many people in that section Too many people from other sections Lab DO NOT DISTURB rules You much receive checkoff in your own section (first 30 mins) You are welcome to use the lab outside your section, but if it is during some other lab section, you much let the TA concentrate on their section. TAs will leave promptly at 8 pm It is your job to read lab and write Verilog before you arrive. 9/18/07 EECS150 Fa07 Lec7 Counters 17 Synchronous Counters Binary Counter Design: Start with 3-bit version and generalize: All outputs change with clock edge. 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 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 9/18/07 EECS150 Fa07 Lec7 Counters 18 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 (out4, out3, out2, out1, clk); output out4, out3, out2, out1; input in, clk; reg out4, out3, out2, out1; "1" always @(posedge clk) begin out4 <= (out1 & out2 & out3) ^ out4; out3 <= (out1 & out2) ^ out3; out2 <= out1 ^ out2; out1 <= out1 ^ 1b 1; end endmodule 9/18/07 EECS150 Fa07 Lec7 Counters 19 9/18/07 EECS150 Fa07 Lec7 Counters 20

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 Synchronous Counters How do we extend to n-bits? Extrapolate c + : d + = d abc, e + = e abcd a + b + c + a b c d Has difficulty scaling (AND gate inputs grow with n) CE a + Tb=CE*A Tc=CE*A*B Td=CE*A*B*C b + c + d + d + TC 9/18/07 EECS150 Fa07 Lec7 Counters 21 a b c d 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. 9/18/07 EECS150 Fa07 Lec7 Counters 22 Synchronous Counters CE How does this one scale? Delay grows α n a + a b + b c + c d + d TC Generation of TC signals very similar to generation of carry signals in adder. Parallel Prefix circuit reduces delay: a b c d e f g h log 2 n log 2 n 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 (2) RCO goes high (3) High order 4-bits are incremented (1) Low order 4-bits = 1111 EN D C B A LOAD CLR RCO QD QC QB QA TC a TC b TC c TC c TC d TC e TC f TC g 9/18/07 EECS150 Fa07 Lec7 Counters 23 9/18/07 EECS150 Fa07 Lec7 Counters 24

Ripple counters Up-Down Counter A 3 A 2 A 1 A 0 0000 0001 0111 1000 1001 1010 1011 1100 1101 1110 1111 time Discouraged Know it exists Don t use it Each stage is 2 of previous. Look at output waveforms: A 0 A 1 A 2 A 3 Often called asynchronous counters. A T flip-flop is a toggle flip-flop. Flips it state on cycles when T=1. 9/18/07 EECS150 Fa07 Lec7 Counters 25 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 Down-count Note: correct clocking 9/18/07 EECS150 Fa07 Lec7 Counters 26 Odd Counts Extra combinational logic can be added to terminate count before max value is reached: Example: count to 12 reset 4-bit binary counter = 11? = 11? Alternative: 4 load 4-bit binary counter 9/18/07 EECS150 Fa07 Lec7 Counters 27 TC Offset Counters Starting offset counters use of synchronous load e.g.,, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1111,,... Ending offset counter comparator for ending value e.g., 0000, 0001,,..., 1100, 1101, 0000 Combinations of the above (start and stop value) EN RCO D QD C QC B QB A QA LOAD CLR 9/18/07 EECS150 Fa07 Lec7 Counters 28 "1" "1" "1" "1" EN RCO D QD C QC B QB A QA LOAD CLR

Universal Shift Register Design of Universal Shift Register left_in left_out clear s0 s1 Holds 4 values Serial or parallel inputs Serial or parallel outputs Permits shift left or right Shift in new values from left or right output input right_out right_in 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 Consider one of the four flip-flops New value at next clock cycle: 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 to N-1th cell Q[N-1] (left) Q D Nth cell CLEAR 0 1 2 3 s0 and s1 control mux Input[N] to N+1th cell Q[N+1] (right) 9/18/07 EECS150 Fa07 Lec7 Counters 29 9/18/07 EECS150 Fa07 Lec7 Counters 30 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]; Pattern Recognizer Combinational function of input samples In this case, recognizing the pattern 1001 on the single input signal OUT 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 IN 9/18/07 EECS150 Fa07 Lec7 Counters 31 9/18/07 EECS150 Fa07 Lec7 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. Datapath Controller 9/18/07 EECS150 Fa07 Lec7 Counters 33 Recall: Byte-bit stream with Rate Matching Byte FIFO init / LD bit 0/pop ~ bit 0 bit 1 ~ ~ pop bit 2 ~ controller bit 3 Shift register ~ LD bit 4 ~ Serial link bit 5 ~ bit 6 How would you implement this FSM? ~ subtle bug here bit 7 / LD 9/18/07 EECS150 Fa07 Lec7 Counters ~ 34 Counter for Sequencing States CLR for back to top ~ init / LD bit 0 ~ bit 0/pop 0001 ~ ~ ~ init / LD bit 0 bit 0/pop 0000 ~ Binary Counter Shift Reg ~ 0000 Or ~ Ring Counter ~ 0000 ~ ~ 0000 ~ ~ 0111 / LD ~ ~ 0000 / LD 9/18/07 EECS150 Fa07 Lec7 Counters 35 ~ 00000001 0000 ~ ~ init / LD 0000/pop 0000/pop ~ ~ bit 0 0001 bit 0 0001 ~ ~ ~ ~ ~ ~ Binary Counter ~ ~ ~ ~ ~ ~ ~ ~ 0111 / LD, clr init 0111 / LD, clr 9/18/07 EECS150 Fa07 Lec7 Counters 36

Count_Enable for Self-loop Branch with LD (jump counter) 0000/pop ~ bit 0 0001 ~ ~ ~ ~ ~ CE = or (state == 0000) n-bit counter LD CE ~ ~ init 0111 / LD, clr 9/18/07 EECS150 Fa07 Lec7 Counters 37 X ~in in y X+1 n-bit counter LD CE ~selfloop in 9/18/07 EECS150 Fa07 Lec7 Counters 38 Jumping IQ: How would you simplify this further 0000/pop ~ LD = (State === 0000 & ~) or (state == 1111) 0001 S = (state == 0000) 1111 ~ ~ ~ ~ 4 0001 0 ~ 4 4 4 1111 1 ~ s ~ init 0111 / LD, clr LD CE 9/18/07 EECS150 Fa07 Lec7 Counters 39 9/18/07 EECS150 Fa07 Lec7 Counters 40

State Complexity vs Counter Usage 1000 ~ 000 0000/pop ~ ~ 001 1001 0001 ~ ~ ~ 3-bit counter 010 CE set TC 1010 ~ ~ ~ 011 init 1011 ~ ~ ~ 100 1100 ~ ~ ~ LD,pop 101 1101 ~ ~ ~ 110 / LD, pop 1110 ~ ~ ~ 1111/LD,clr 111 0111 / LD, clr ~ 9/18/07 EECS150 Fa07 Lec7 Counters 41 init Another Controller using Counters Example, Bit-serial multiplier: shifta shiftb A register B register Control Algorithm: FA sum carry D-FF reset 0 1 shifthi HI register selectsum 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/18/07 EECS150 Fa07 Lec7 Counters 42 Counter provides subsidiary state Summary State Transition Diagram: Assume presence of two binary counters. An i counter for the outer loop and j counter for inner loop. START CE RST counter TC 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. IDLE CE i,ce j RST i TC i OUTER <outer contol> CE i,ce j RST j TC i START INNER <inner contol> CE i,ce j TC j TC 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/18/07 EECS150 Fa07 Lec7 Counters 43 9/18/07 EECS150 Fa07 Lec7 Counters 44