11. registers & counters - sharif

9
1 11.1 Elec 326 Registers & Counters 11. Registers & Counters Objectives This section deals with some simple and useful sequential circuits. Its objectives are to: Introduce registers as multi-bit storage devices. Introduce counters by adding logic to registers implementing the functional capability to increment and/or decrement their contents. Define shift registers and show how they can be used to implement counters that use the one-hot code. Reading Assignment Counters: Chapter 7, Sections 7.8 through 7.11 in Brown & Vranesic. Verilog description of counters: Chapter 7, Sections 7.13 in Brown & Vranesic. 11.2 Elec 326 Registers & Counters 11.1. Registers A register is a memory device that can be used to store more than one bit of information. A register is usually realized as several flip-flops with common control signals that control the movement of data to and from the register. Common refers to the property that the control signals apply to all flip-flops in the same way A register is a generalization of a flip-flop. Where a flip- flop stores one bit, a register stores several bits The main operations on a register are the same as for any storage devices, namely Load or Store: Put new data into the register Read: Retrieve the data stored in the register (usually without changing the stored data 11.3 Elec 326 Registers & Counters Control Signals When they are asserted, they initiate an action in the register Asynchronous Control Signals cause the action to take place immediately Synchronous Control Signals must be asserted during a clock assertion to have an effect Examples On the following three registers, which control signals are asynchronous and which are synchronous? How are the control signals asserted? 11.4 Elec 326 Registers & Counters DQ Q CLR STO D 0 D 1 D n-1 Q n-1 Q 0 Q 1 DQ Q CLR DQ Q CLR CLR module reg1 (STO, CLR, D, Q); parameter n = 16; input STO, CLR; input [n-1:0] D; output [n-1:0] Q; reg [n-1:0] Q; always @(posedge STO or negedge CLR) if (CLR ==0) Q <= 0; else Q <= D; endmodule

Upload: others

Post on 05-Jan-2022

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 11. Registers & Counters - Sharif

1

11.1Elec 326 Registers & Counters

11. Registers & CountersObjectives

This section deals with some simple and useful sequentialcircuits. Its objectives are to: Introduce registers as multi-bit storage devices. Introduce counters by adding logic to registers

implementing the functional capability to increment and/ordecrement their contents.

Define shift registers and show how they can be used toimplement counters that use the one-hot code.

Reading AssignmentCounters: Chapter 7, Sections 7.8 through 7.11 in Brown &

Vranesic.Verilog description of counters: Chapter 7, Sections 7.13 in

Brown & Vranesic.

11.2Elec 326 Registers & Counters

11.1. Registers

A register is a memory device that can be used tostore more than one bit of information.

A register is usually realized as several flip-flops withcommon control signals that control the movement ofdata to and from the register. Common refers to the property that the control signals

apply to all flip-flops in the same way A register is a generalization of a flip-flop. Where a flip-

flop stores one bit, a register stores several bits The main operations on a register are the same as for any

storage devices, namely Load or Store: Put new data into the registerRead: Retrieve the data stored in the register (usually without

changing the stored data

11.3Elec 326 Registers & Counters

Control Signals When they are asserted, they initiate an action in the

register Asynchronous Control Signals cause the action to take

place immediately Synchronous Control Signals must be asserted during a

clock assertion to have an effect Examples

On the following three registers, which control signals areasynchronous and which are synchronous? How are thecontrol signals asserted?

11.4Elec 326 Registers & Counters

D Q

QCLR

STO

D0

D1

Dn-1 Qn-1

Q0

Q1

D Q

QCLR

D Q

QCLR

CLR

module reg1 (STO, CLR, D, Q);parameter n = 16;input STO, CLR;input [n-1:0] D;output [n-1:0] Q;reg [n-1:0] Q;

always @(posedge STO or negedge CLR)if (CLR ==0) Q <= 0;else Q <= D;

endmodule

Page 2: 11. Registers & Counters - Sharif

2

11.5Elec 326 Registers & Counters

J Q

QK

J Q

QK

J Q

QK

D0

D1

Dn-1 Qn-1

Q0

Q1

LD

CLKCLR

OE

11.6Elec 326 Registers & Counters

D Q

Q

D Q

Q

D Q

QD0

D1

Dn-1Qn-1

Q0

Q1

LD

CLKCLR

OE

11.7Elec 326 Registers & Counters

Verilog description of previous two registers

module reg2 (CLK, CLR, LD, OE, D, Q);parameter n = 4;input CLK, CLR, LD, OE;input [n-1:0] D;output [n-1:0] Q;reg [n-1:0] IQ, Q;integer k;

always @(posedge CLK)if (CLR) IQ <= 0;else if (LD) IQ <= D;

always @(OE)if (OE) Q = IQ;else Q = 'bz;

endmodule

11.8Elec 326 Registers & Counters

11.2. CountersA counter is a register capable of incrementing and/or

decrementing its contents

Q ← Q plus nQ ← Q minus n

The definition of "plus" and "minus" depend on the waythe register contents encode the integers

Binary Counters: Encode the integers with the binarynumber code

Page 3: 11. Registers & Counters - Sharif

3

11.9Elec 326 Registers & Counters

Example: 3-bit binary counter:

What does the counter count? The output signals are just the state variables

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 10 0 0

minus

plus

•••

Count Sequence

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

0 0 10 1 00 1 11 0 01 0 11 1 01 1 10 0 0

Transistion Table

01234567

12345670

State Table

11.10Elec 326 Registers & Counters

Example: 3-bit binary up/down counter

Example: Binary mod 6 counter

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

1 1 10 0 00 0 10 1 00 1 11 0 01 0 11 1 0

TransistionTable

0 0 10 1 00 1 11 0 01 0 11 1 01 1 10 0 0

0 1

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

0 0 10 1 00 1 11 0 01 0 10 0 0x x xx x x

Transistion Table

0 1 2

345

State Diagram

11.11Elec 326 Registers & Counters

Design of a Binary Up Counter

Qi toggles on every clock cycle where Qj = 1, for i > j ≥ 0

11.12Elec 326 Registers & Counters

Binary Up Counter

1

J Q

QK

CK

J Q

QK

J Q

QK

J Q

QK

Page 4: 11. Registers & Counters - Sharif

4

11.13Elec 326 Registers & Counters

Design of a Binary Down Counter

Qi toggles on every clock cycle where Qj = 0, for i > j ≥ 0

11.14Elec 326 Registers & Counters

Binary Down Counter

11.15Elec 326 Registers & Counters

Synchronous, Series-Carry Binary Counter

1

CK

Q0 Q1 Q2 Q3J Q

QK

J Q

QK

J Q

QK

J Q

QK

TW ≥ tPFF + (n-2)tPG + tsu (for n≥2)

tsu

CKTW

Q3Q2Q1

Q0 = JK1

Q=14 Q=15 Q=0

JK2

JK3

tPFF

tPG

tPG

11.16Elec 326 Registers & Counters

Synchronous, Parallel-Carry Binary Counter

1

CK

Q0 Q1 Q2 Q3J Q

QK

J Q

QK

J Q

QK

J Q

QK

TW ≥ tPFF + tPG + tsu (for n≥3)

CKTW

Q3Q2Q1

Q0 = JK1

Q=14 Q=15 Q=0

JK2

JK3

tPFF

tPG

tPG

tsu

Page 5: 11. Registers & Counters - Sharif

5

11.17Elec 326 Registers & Counters

Asynchronous Counters

Typical MSI counter chip

LD and CLR are synchronous LD asserted during the rising edge of the clock loads the register from

ABCD. CLR asserted during the rising edge of the clock clears the counter CLR overrides LD LD overrides EN RCO = QD•QC • QB • QA • ENT, used for cascading chips

CKJ Q

QK

J Q

QK

J Q

QK

J Q

QK

11

11

11

11

CLRLDENPENTABCD

RCO

QAQBQCQD

74LS163

11.18Elec 326 Registers & Counters

Verilog description of the 74x163module V74x163 (CLK, CLR_L, LD_L, ENP, ENT, D, Q, RCO);

input CLK, CLR_L, LD_L, ENP, ENT;input [3:0] D;output RCO;output [3:0] Q;reg [3:0] Q;reg RCO;

always @(posedge CLK)if (CLR_L == 0) Q <= 4'b0000;else if (LD_L == 0) Q <= D;else if (ENT & ENP) Q <= Q +1;

always @(Q or ENT)if (Q == 15 && ENT == 1) RCO = 1;else RCO = 0;

endmodule

11.19Elec 326 Registers & Counters

Verilog description of an up/down counter

module updowncount (R, Clock, L, E, up_down, Q);parameter n = 8;input [n-1:0] R;input Clock, L, E, up_down;output [n-1:0] Q;reg [n-1:0] Q;integer direction;

always @(posedge Clock) begin

if (up_down) direction = 1;else direction = -1;if (L) Q <= R;else if (E) Q <= Q + direction;end

endmodule

-

11.20Elec 326 Registers & Counters

Verilog description of mod-n counters

module upmodn (Ck, Q);parameter n = 6;input Ck;output [3:0] Q;reg [3:0] Q;

always @(posedge Ck)if (Q == n)

Q <= 0;else

Q <= Q + 1;

endmodule

module dwnmodn (Ck, Q);parameter n = 5;input Ck;output [3:0] Q;reg [3:0] Q;

always @(posedge Ck)if (Q == 0)

Q <= n;else

Q <= Q -1;endmodule

Page 6: 11. Registers & Counters - Sharif

6

11.21Elec 326 Registers & Counters

Design of Mod n Counters Mod 6 Up Counter

Mod 5 Down Counter

CKQ0

Q1Q2

0 1 2 3 4 5 0 1 2/CLR

CK

Q0

Q1Q2

01234 234/LD

CLRLDENPENTABCD

RCO

QAQBQCQD

74LS163CLK

11

1

U/DLDENPENTABCD

RCO

QAQBQCQD

74LS169CLK

0

0000

01

11.22Elec 326 Registers & Counters

Decoding Binary Counter States

The decoding spikes are hazzards that can not be designedout

The following circuit will mask the decoding spikes, at thecost of delaying the outputs one clock cycle.

QAQBQC

ABC

Y0Y1Y2Y3Y4Y5Y6Y7

/S0/S1/S2/S3/S4/S5/S6/S7

CK

Q0

Q1Q2/S0/S1/S2

CLK

REGQAQBQC

ABC

Y0Y1Y2Y3Y4Y5Y6Y7

11.23Elec 326 Registers & Counters

11.3. Shift Registers

How would you add a control signal to control when theshift register shifted?

How would you add parallel input capability and whywould you want to?What kind of control signals are needed?

Is the shift register drawn above a left shifter or a rightshifter?

How would you make a shift register that could shift eitherleft or right and what control signals would you need?

11.24Elec 326 Registers & Counters

Example: 74LS194

Shift left is from A to D Shift right is from D to A CLR is asynchronous

CLR

S0S1

RIN

LINDBCA

QDQCQBQA

S1 S0 QA* QB* QC* QD*0011

0101

holdshift rightshift leftload

QARINQBA

QBQAQCB

QCQBQDC

QDQCLIND

Action

Page 7: 11. Registers & Counters - Sharif

7

11.25Elec 326 Registers & Counters

Verilog Description Of A Shift Registermodule shift4 (D, LD, LI, Ck, Q);

input [3:0] D;input LD, LI, Ck;output [3:0] Q;reg [3:0] Q;

always @(posedge Ck) if (LD)

Q <= D;else

beginQ[0] <= Q[1];Q[1] <= Q[2];Q[2] <= Q[3];Q[3] <= LI;

end

endmodule

11.26Elec 326 Registers & Counters

Ring Counters

11.27Elec 326 Registers & Counters

Self-Correcting Ring Counter

11.28Elec 326 Registers & Counters

Johnson counter, switch-tail counter, moebius counter

Page 8: 11. Registers & Counters - Sharif

8

11.29Elec 326 Registers & Counters

Self-Correcting Johnson Counter

Odd Length Johnson Counter

This counter is also self-correcting

0001

1000 1110

01110011

11000000

11.30Elec 326 Registers & Counters

11.4. Design with MSI Components (Counters)Approach

The state diagram of a counter is essentially a cycle. Whenever a state diagram is close to a cycle, with only a

few other edges, it can be realized using a counter byadding logic to take care of the transitions that are not inthe cycle.

The following control inputs on counters are useful: ENABLE: Asserted to cause the counter to count in its natural

count sequence. Deasserted to cause the counter to hold its currentstate.

CLEAR: Used to realize a count sequence that is not a power oftwo and for initialization.

LOAD: Used to modify the natural count sequence by forcing thecounter to a given state.

11.31Elec 326 Registers & Counters

Example:

Assert ENABLE whenThe counter is in state 0 and X = 1,The counter is in state 1,The counter is in state 2 and Z = 1,The counter is in state 3,The counter is in state 4, orThe counter is in state 5 and Z =1.

Assert CLEAR whenThe circuit is to be initialized, orThe counter is in state 6 and Y = 1.

Assert LOAD whenThe counter is in state 5 and Y,Z = 1,0 (Load 100)The counter is in state 6 and Y = 0 (Load 011)

1

2

0

3 4

5

6YX'

X

1

Z' Z 1

Y•Z'

Y'•Z'

1

Z

Y'

11.32Elec 326 Registers & Counters

Assert ENABLE whenThe counter is in state 0 and X = 1,The counter is in state 1,The counter is in state 2 and Z = 1,The counter is in state 3,The counter is in state 4, orThe counter is in state 5 and Z =1.

Assert CLEAR whenThe circuit is to be initialized, orThe counter is in state 6 and Y = 1.

Assert LOAD whenThe counter is in state 5 and Y,Z = 1,0 (Load 100)The counter is in state 6 and Y = 0 (Load 011)

Page 9: 11. Registers & Counters - Sharif

9

11.33Elec 326 Registers & Counters

Example:

Comment: A state table for this diagram would have 7 rows and 256columns

CLEAR = LOAD = A = B = C =

ENABLE =

1 20 3 4 5 6

X0' X1'•X2' X3' X4' X5' X6•x7'

1

X6•X7'X1'•X2

X0 X1 X3 X4 X5 X7INIT

(Q=1)•X1'•X2 + INIT(Q=5)•X6•X7' + (Q=6)(Q=6)(Q=5 )0(Q=0)•X0 + (Q=1)•X1 + (Q=2)•X3 + (Q=3)•X4 + (Q=4)•X5 + (Q=5)•X7

11.34Elec 326 Registers & Counters

11.5. Tips & Tricks

Don't use asynchronous counters, especially if theclock period is close to the flip-flop propagationdelay.

Don't build mod n counters from binary counters withasynchronous clears.

11.6. Pitfalls

Detecting the wrong state for resetting a mod ncounter.

11.35Elec 326 Registers & Counters

11.7. Review

Register control signals and assertions. Binary counters and their operations.

Reset, Load, Output Enable. Counter timing; maximum clock frequency.

Mod-n counters Synchronous vs. asynchronous load and reset signals.

Shift registers and shift register counters. Ring counters, Johnson counters, etc Self-correcting counters

Counter realization of sequential circuits