Chapter 5 Registers & Counters

Similar documents
HANSABA COLLEGE OF ENGINEERING & TECHNOLOGY (098) SUBJECT: DIGITAL ELECTRONICS ( ) Assignment

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

Finite-State Machine (FSM) Design

Chapter 3 Part 2 Combinational Logic Design

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

Ripple Counters. Lecture 30 1

CSE 140L Final Exam. Prof. Tajana Simunic Rosing. Spring 2008

DIGITAL SYSTEM DESIGN

Modeling Synchronous Logic Circuits. Debdeep Mukhopadhyay IIT Madras

Digital Design with FPGAs. By Neeraj Kulkarni

Sequential Logic Blocks

L5: Simple Sequential Circuits and Verilog

(ii) Simplify and implement the following SOP function using NOR gates:

VALLIAMMAI ENGINEERING COLLEGE. SRM Nagar, Kattankulathur DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING EC6302 DIGITAL ELECTRONICS

Verilog for High Performance

Lecture 3. Behavioral Modeling Sequential Circuits. Registers Counters Finite State Machines

Injntu.com Injntu.com Injntu.com R16

University of Technology

EE 231 Fall EE 231 Homework 8 Due October 20, 2010

Verilog 1 - Fundamentals

Federal Urdu University of Arts, Science and Technology, Islamabad VLSI SYSTEM DESIGN. Prepared By: Engr. Yousaf Hameed.

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING QUESTION BANK NAME OF THE SUBJECT: EE 2255 DIGITAL LOGIC CIRCUITS

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Code No: R Set No. 1

Final Exam Solution Sunday, December 15, 10:05-12:05 PM

CSE 140L Final Exam. Prof. Tajana Simunic Rosing. Spring 2008

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

Writing Circuit Descriptions 8

N-input EX-NOR gate. N-output inverter. N-input NOR gate

Code No: R Set No. 1

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

10EC33: DIGITAL ELECTRONICS QUESTION BANK

R a) Simplify the logic functions from binary to seven segment display code converter (8M) b) Simplify the following using Tabular method

L5: Simple Sequential Circuits and Verilog

Code No: R Set No. 1

SUBJECT CODE: IT T35 DIGITAL SYSTEM DESIGN YEAR / SEM : 2 / 3

Question Total Possible Test Score Total 100

Modeling Sequential Circuits in Verilog

Register Transfer Level in Verilog: Part I

Code No: 07A3EC03 Set No. 1

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

Digital Design Using Digilent FPGA Boards -- Verilog / Active-HDL Edition

Blocking(=) vs Nonblocking (<=) Assignment. Lecture 3: Modeling Sequential Logic in Verilog HDL. Procedural assignments

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

ECE 341 Midterm Exam

NADAR SARASWATHI COLLEGE OF ENGINEERING AND TECHNOLOGY Vadapudupatti, Theni

IA Digital Electronics - Supervision I

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

Topics. Midterm Finish Chapter 7

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

VHDL for Synthesis. Course Description. Course Duration. Goals

Why Should I Learn This Language? VLSI HDL. Verilog-2

Registers and finite state machines

DESIGN PROJECT TOY RPN CALCULATOR

Mark Redekopp, All rights reserved. EE 352 Unit 8. HW Constructs

Two hours - online EXAM PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

L5: Simple Sequential Circuits and Verilog

Logic Circuits II ECE 2411 Thursday 4:45pm-7:20pm. Lecture 3

ECE 551 Digital System Design and Synthesis. Instructor: Kewal K. Saluja. Midterm Exam

BHARATHIDASAN ENGINEERING COLLEGE Degree / Branch : B.E./ECE Year / Sem : II/ III Sub.Code / Name : EC6302/DIGITAL ELECTRONICS

Topics. Midterm Finish Chapter 7

ECE 353 Lab 3 (Verilog Design Approach)

problem maximum score 1 10pts 2 8pts 3 10pts 4 12pts 5 7pts 6 7pts 7 7pts 8 17pts 9 22pts total 100pts

Chap 6 Introduction to HDL (d)

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Topics of this Slideset. CS429: Computer Organization and Architecture. Digital Signals. Truth Tables. Logic Design

L5: Simple Sequential Circuits and Verilog

Henry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

EE 109L Review. Name: Solutions

Digital System Design with SystemVerilog

L11: Major/Minor FSMs

Verilog 1 - Fundamentals

In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and

Register Transfer Level

ELCT 501: Digital System Design

COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING QUESTION BANK SUBJECT CODE & NAME: EC 1312 DIGITAL LOGIC CIRCUITS UNIT I

ECE 2300 Digital Logic & Computer Organization. More Finite State Machines

EE178 Lecture Verilog FSM Examples. Eric Crabill SJSU / Xilinx Fall 2007

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

Control in Digital Systems

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Department of Computer Science & Engineering. Lab Manual DIGITAL LAB. Class: 2nd yr, 3rd sem SYLLABUS

Fundamentals of Computer Systems

Verilog for Synthesis Ing. Pullini Antonio

Microcomputers. Outline. Number Systems and Digital Logic Review

Course Topics - Outline

Chapter 9: Sequential Logic Modules

ENEE 245 Lab 1 Report Rubrics


a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

R10. II B. Tech I Semester, Supplementary Examinations, May

EE 109L Final Review

II/IV B.Tech (Regular/Supplementary) DEGREE EXAMINATION. Answer ONE question from each unit.

ENEE245 Digital Circuits and Systems Lab Manual

Chapter 9: Sequential Logic Modules

VERILOG: FLIP-FLOPS AND REGISTERS

Transcription:

University of Wisconsin - Madison ECE/Comp Sci 352 Digital Systems Fundamentals Kewal K. Saluja and Yu Hen Hu Spring 2002 Chapter 5 Registers & Counters Originals by: Charles R. Kime Modified for course use by: Kewal K. Saluja and Yu Hen Hu Overview of Chapter 5 Registers: asic registers Register with load and hold Shift register Register with parallel load and other functions Counters: asics Ripple counters Synchronous counters Counters with parallel load General counters HDL Representation: Verilog descriptions Chapter 5 2 1

Registers Register a collection of binary storage elements In theory, a register is sequential logic which can be defined by a state table More often think of a register as storing a vector of binary values Frequently used to perform simple data storage and data movement and processing operations, but can also be used to store sequential circuit state. Chapter 5 3 Example: 2-bit Register How many states are there? How many Inputs? Outputs? What is the output function? What is the Next State function? Moore or Mealy? State Table: Current State In1 In0 What happens with a 4-bit register? D D C C Next State 1(t+) 0(t+) For I1 I0 = 00 01 10 11 1 0 Output (=1 0) 1 0 Y1 Y0 0 0 00 01 10 11 0 0 0 1 00 01 10 11 0 1 1 0 00 01 10 11 1 0 1 1 00 01 10 11 1 1 Chapter 5 4 2

Registers: Storage Model The sequential logic model is not useful for whole registers How can we "selectively" store data in some registers and not change the contents of others? Stop the clock when we don't want change clock gating (e careful!) Use a flip flop that can "hold" under some set of logical inputs. SR, T and JK flip-flops all have "hold" states when inputs are "0". We can use logic and a load control signal to build a register that can be controllably loaded. Chapter 5 5 Registers with Clock Gating Load signal is used to enable the clock signal to pass through if 1 and prevent the clock signal from passing through if 0. Example: For Positive Edge Triggering or Neg. Pulse MS Master Clock Load Gated Clock to FF What logic is needed for gating? GC = CLK + LOD What is the problem? Clock Skew of GC Chapter 5 6 3

Registers with Load Control more reliable way to selectively load a register is to run the clock continuously and use a load control to change selectively change the register contents. Example: 2-bit register with Load Control Load In1 J K 1 Note: SR FFs would also work here. In0 J K 0 Chapter 5 7 Registers with Load Control nother way is to use a 2-input multiplexer in front of a DFF like this: I1 D 1 For Load = "1", the outputs are replaced by the current inputs. For Load = "0", data holds. I0 D 0 Load Chapter 5 8 4

Shift Registers Shift Registers are a special class of registers that can be used to store and manipulate data. In the simplest case, the shift register is simply a set of D flip-flops connected in a row like this: In D C Out D D D Data input, "In", is called the "serial input", or "shift right input". Data output, "Out", is often called the "serial output". "","","C", and "Out" collectively are the "parallel outputs". Chapter 5 9 Shift Registers (Continued) The behavior of the serial shift register is depicted below. The clock pulse "T0" is just before the first pulse occurs. "T1" is after the first pulse and before the second. The states initially unknown are denoted "?". In D C Out D D D In C Out T0 0???? T1 1 0??? T2 1 1 0?? T3 0 1 1 0? T4 1 0 1 1 0 T5 1 1 0 1 1 T6 1 1 1 0 1 Chapter 5 10 5

Parallel Load Shift Registers y adding a mux between each shift register stage, we can "shift", or "load" data. IN SHIFT LOD_ D LOD_ If "SHIFT" is low, "" and "" are replaced by the data on "LOD_" and "LOD_" lines, else data shifts each clock. y tying together more than one of these, we can make longer parallel load shift registers. y tying an n-bit shift register to a control that is low (load = low) only one period out of n, we will "serialize" data. D Chapter 5 11 Shift Registers with More Functions y placing a 4-input multiplexer in front of each D flip-flop in a shift register, we can implement a device which: 1. Shifts right 2. Shifts left 3. Holds 4. Parallel loads This device becomes a "universal" shift register that can be used for a number of different things. In particular, such a structure is good for tying all state elements together so you can "scan" the current state in or out of a system for test purposes. The shift-left, shift-right and parallel-load inputs give three ways to load data into the registers. Chapter 5 12 6

Serial Data Operations y using two shift registers for operands, a full adder, and one more flip flop (for the carry), it is possible to add two numbers serially, starting at the least significant bit. Serial addition is not a bad way to add huge numbers of operands, since a "tree" of adders can be made to any depth, and each new level doubles the number of operands. Other operations can be performed serially as well, such as parity generation/checking or more complex error-check codes. Shifting a binary number left is equivalent to multiplying by 2. Shifting a binary number right is equivalent to dividing by 2. Chapter 5 13 Serial dder The circuit shown uses two shift registers for operands (3..0) and (3..0). full adder, and one more flip flop (for the carry) is used to compute the sum. The result is stored back in the "" register along with the final carry. This can be extended to trees of adders, adding a large number of operands. Serial In Serial In Load/Shift Registers 3 2 1 0 Parallel Load 3 2 1 0 Parallel Load (Clock and Load/Shift Control not shown) F Sum Cin Cout D Chapter 5 14 7

Counters Counters are sequential circuits which "count" through a specific state sequence. They can count up, count down, or count through other fixed sequences. Two distinct types are in common usage: Ripple Counters Clocks are connected to flip-flop outputs, thus not truly synchronous Outputs are "delayed" for higher bits. Resurgent because of low power consumption Synchronous Counters Clocks are directly connected to the flip-flops. Logic is used to implement the desired state sequencing. Chapter 5 15 Counter asics: Divide by 2 Consider the following circuit: "1" T D ' Draw Waveform and Chapter 5 16 8

Divide Clock Frequency by 2 The waveforms look like a new clock with twice the period of (half the frequency). The flip-flops are said to "divide-by-2" since the frequency of the output waveform is 1/2 the frequency of clock. "1" T D ' Chapter 5 17 Ripple Counter What happens now? (note clock change on ) "1" T D ' Draw the waveform for. Chapter 5 18 9

Ripple Counter (Continued) Here's what happens: Note that "divides" the frequency in by 2 -- or doubles the period. Notice the count ( ) base 10 of: 3 2 1 0 3 2 1 What kind of counter is this? Down Counter! "1" T D ' 1 0 1 0 1 1 1 0 0 1 Chapter 5 19 Ripple Counter (Continued) Now consider this (what has changed?): "1" T D ' ' 1 0 1 0 1 Draw waveform. Chapter 5 20 10

Ripple Counter (Continued) Here's what happens: Note that "divides" the frequency in by 2 -- or doubles the period. Notice the count ( ) base 10 of: "1" T D ' ' 0 1 2 3 0 1 What type of counter is this? Up Counter! Can also use negative edgetriggering 1 0 0 1 1 0 1 1 0 0 Chapter 5 21 Ripple Counter (Continued) The circuits designed this way are called Ripple Counters because each edge sensitive transition (positive in the example's case) causes a change in the next flipflop's state. The changes "ripple" up the chain. That is, each transition occurs after a clock to output delay from the stage before. To see this effect in detail look at the following circuit: What is the detailed waveform behavior? "1" T T T C Chapter 5 22 11

Ripple Counter (Continued) "1" T T T C Here is the detailed waveform behavior: 1 0 1 0 1 What "counts" are shown? C 0 0 0 1 1 0 0 0 1 1 Chapter 5 23 Ripple Counter (Continued) Starting with ==C = "1", equivalent to (C,,) = 7 base 10, the next count will increment the count to (,,C) = 0 base 10. Here's what happens in fine timing detail: The clock to output delay t PHL causes an increasing delay from clock edge for each stage transition. Thus, the count "ripples" from least to most significant bit. For n bits, total worst case delay is n tphl. C TpHL TpHL TpHL Chapter 5 24 12

Synchronous Counters In order to eliminate the "ripple" effect, we will use a common clock for each flip-flop and a combinatorial circuit to generate the next state. One way to generate a counter is with an dder/register circuit: Here "CNT" is the D3 3 count constant: SUM D2 2 0000 is HOLD, D1 1 1111 is DOWN and CNT 4-it D0 0 0001 is UP. dder Note potential logic simplification due to constant applied to. Chapter 5 25 Synchronous Counters (Continued) simple 2-bit synchronous counter can be made with two "T" Flip-Flops: Note that the from the first stage enables the second stage to toggle. Does it count "up" or "down"? How do you extend this to three stages? "1" T T 1 0 1 0 1 0 0 0 1 1 Chapter 5 26 13

Synchronous Counters (Continued) "1" T T T The concept can be extended to multiple stages. For binary "UP" counters, the upper stages toggle when LL of the lower stages are at the value "1" and the clock occurs. y "NDing" in a count enable signal to each "T" input, we can produce a "HOLD" count signal. Chapter 5 27 Synchronous Counters Serial Gating When a two-input ND gate is used for each stage of the counter with a ripplelike carry, this is referred to as serial gating. s the size of the counter increases the delay through the combinational logic increases roughly in proportion to n, the number of stages. Chapter 5 28 14

Synchronous Counters Parallel Gating When a multiple-input ( >2) ND gates are used for each stage of the counter with logic dedicated to each stage or to a group of stages, this is referred to as parallel gating. It resembles carry lookahead in an adder. s the size of the counter increases the delay through the combinational logic increases roughly in proportion to n/m, the number of stages/the group size. Chapter 5 29 Design: Synchronous CD We can use the sequential logic model to design a synchronous CD counter with T flip-flops. elow is the State Table. Don't care states have been left out here. Current State 8 4 2 1 Next State 8 4 2 1 T-FF Excitation T8 T4 T2 T1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 1 Chapter 5 30 15

Synchronous CD (Continued) Use K-Maps to minimize the next state function: T8 8 T8 = 8 1 + 4 2 1 1 1 2 0 1 3 2 4 5 7 6 x x x x 12 13 15 14 x 1 x 8 9 11 10 4 T4 8 1 2 0 1 3 2 4 5 7 6 x x x x 12 13 15 14 x 1 1 x 8 9 11 10 4 T4 = 2 1 T2 = 8' 1 T1 = "1" Note: Don't Cares are included here. T2 8 1 1 1 1 2 0 1 3 2 4 5 7 6 x x x x 12 13 15 14 x 1 x 8 9 11 10 4 T1 8 1 1 1 1 1 1 1 1 1 1 1 2 0 1 3 2 4 5 7 6 x x x x 12 13 15 14 x x 8 9 11 10 4 Chapter 5 31 Synchronous CD (Continued) The minimized circuit: "1" T 1 T 2 8*1 2*1 T 4 4*2*1 T 8 8*1 Chapter 5 32 16

Synchronous CD (Continued) What about the Don't Cares now?. LL Next States are now specified!! Current State 8 4 2 1 Next State 8 4 2 1 T-FF Excitation T8 T4 T2 T1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 1 1 0 1 0???? 0 0 0 1 1 0 1 1???? 1 1 0 1 1 1 0 0???? 0 0 0 1 1 1 0 1???? 1 0 0 1 1 1 1 0???? 0 0 0 1 1 1 1 1???? 1 1 0 1 Chapter 5 33 Synchronous CD (Continued) Don't care states have now been specified by the logic. Current State 8 4 2 1 Next State 8 4 2 1 T-FF Excitation T8 T4 T2 T1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 1 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 0 1 1 0 1 Chapter 5 34 17

Synchronous CD (Continued) What does the complete state diagram look like? 1 2 3 0 15 14 12 13 4 How does the sequential machine get into some of the states? 9 8 10 7 11 6 5 Chapter 5 35 Counter with Parallel Load COUNT LOD In "T" Load and Count To Other Cells Common Logic asic Cell J K CLR CLER If we replace the T flip-flop with a JK flip-flop and some other logic, we can introduce a Hold function and a Parallel Load function. This basic cell replaces the T-FFs from before. Note that the "T" input can be used as a normal T-FF if LOD is low and COUNT is high. The clock,, and CLER lines are tied to all flip-flops. Chapter 5 36 18

Counting Modulo N The Load feature can be used to preset the counter synchronously on command. The Clear feature can asynchronously reset the counter to zero. (This can lead to counts which are present only a very short time). y detecting a "terminal" count of N-1 in a Modulo-N count sequence, we can synchronously load in "zero" to start over. y detecting a "terminal" count of N in a Modulo-N count sequence, we can clear the count asynchronously to "zero" to start over. lternatively, we can detect the "all-ones" terminal count and use load to preset a count of the maximum count value minus (N-1). Chapter 5 37 Counting Modulo 7 synchronous 4-bit binary counter with a synchronous load and an asynchronous clear is to be used to make a Modulo 7 counter. Use the Load feature to detect the count "6" and load in "zero". This gives a count of 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0... etc. "0" "0" "0" "0" CLOCK "1" IN8 8 IN4 4 IN2 2 IN1 1 LOD CLER Chapter 5 38 19

Counting Modulo 7, syn.clear synchronous 4-bit binary counter with a synchronous load and an asynchronous clear is to be used to make a Modulo 7 counter. Use the Clear feature to detect the count "7" and clear the count to "zero". This gives a count of 0, 1, 2, 3, 4, 5, 6, 7(short) 0, 1, 2, 3, 4, 5, 6, 7(short) 0, etc. CLOCK "0" IN8 IN4 IN2 IN1 LOD 8 4 2 1 CLER DON T DO THIS! Referred to as a suicide counter! Chapter 5 39 Counting Modulo 7, Preset 9 synchronous, 4-bit binary counter with a "1" IN8 8 synchronous load and an "0" IN4 4 asynchronous clear is to be "0" IN2 2 used to make a Modulo 7 counter. "1" IN1 1 CLOCK Use the Load feature to LOD preset the count to "9" "1" CLER when you detect the count "15". This gives a count of 9, 10, 11, 12, 13, 14, 15, 9, 10, 11, 12, 13, 14, 15, 0,... etc. Sometimes the "Detect 15" is built in to the counter. Chapter 5 40 20

Timing Sequences For digital systems, useful to generate a multi-phase sequence of timing signals to perform different functions at different intervals. There are many ways to do this. Here are a few that start with a clock and use a "counter" to divide the clock into separate phases. Counter/Decoder - connect the output of a counter to a decoder. Ring Counter - shift a single pulse down a chain of flip-flops connected as a shift register. For "N" phases, use "N" flip-flops. There can be "unwanted" states if not initialized properly. Johnson Counter - (Switch-Tail Ring) uses an "N" bit shift register and decoders to produce 2*N phases. There can be "unwanted" states if not initialized properly. Chapter 5 41 Counter Decoder Example Here is one variant of a counterdecoder multi-phase clock generator: Note the "Glitches" due to the ripple count. synchronous counter would have been better than the ripple counter. Even with a synchronous counter, glitches are possible although reduced in duration. Method OK if glitches not a problem, for example, if signals are used as enables in a positive edge-triggered system. C3 C2 C1 C0 "1" Ripple Counter 2 2 1 1 C3 C2 C1 C0 "GLITCH" Chapter 5 42 21

Ring Counter ring counter is just a shift register with feedback. ssuming the initial state CD is 1000 we get the timing diagram shown: The state must be initialized to operate correctly. Use logic to assure this. Same circuit can be used with positive edgetriggering. C D D D IF CD = 1000 t Start: D C D D Chapter 5 43 Johnson Counter (Switch-Tail) Johnson counter is also a shift register with feedback. ssuming the initial state C is 000 we get the timing diagram shown: The state must be initialized to operate correctly. Use logic to assure this. C C C D D IF CD = 000 t Start: D C C Chapter 5 44 22

Verilog for Registers and Counters Register same as flip-flop except multiple bits: reg[3:0] ; input[3:0] D; always@(posedge CLK or posedge RESET) begin if (RESET) <= 4'b0000; else <= D; end Shift Register use concatenate: <= {[2:0], SI}; Counter use increment/decrement: count <= count + 1; or count <= count - 1 Chapter 5 45 Verilog Description of Left Shift Register // 4-bit Shift Register with Reset // (See Figure 5-3) module srg_4_r_v (CLK, RESET, SI,,SO); input CLK, RESET, SI; output [3:0] ; output SO; reg [3:0] ; assign SO = [3]; always@(posedge CLK or posedge RESET) begin if (RESET) <= 4'b0000; else <= {[2:0], SI}; end endmodule Chapter 5 46 23

Verilog Description of inary Counter // 4-bit inary Counter with Reset // (See Figure 5-10) module count_4_r_v (CLK, RESET, EN,, CO); input CLK, RESET, EN; output [3:0] ; output CO; always@(posedge CLK or posedge RESET) begin if (RESET) count <= 4'b0; else if (EN) count <= count + 1; end endmodule reg [3:0] count; assign = count; assign CO = (count == 4'b1111 && EN == 1'b1)? 1 : 0; Chapter 5 47 24