1 of 36

Adapted from Dr. Bassam Kahhaleh’ Slides by Prof. Iyad Jafar

Digital Logic

0907231

0

2 of 36

Chapter 7

Registers and Counters

1

3 of 36

Outline

  • Registers
  • Shift Registers
  • Ripple Counters
  • Synchronous Counters

2

4 of 36

Registers

3

5 of 36

Registers

  • A register is basically a group of binary storage elements
    • In theory, a register is sequential logic circuit 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
      • data movement
      • processing operations

4

6 of 36

Registers

  • 4-bit register using D-FF
    • I3, I2, I1 and I0 are loaded into the register on every rising edge of the clock

D

Q

R

Reset

D

Q

R

D

Q

R

D

Q

R

CLK

I0

I1

I2

I3

A0

A1

A2

A3

5

7 of 36

Registers

D

Q

R

Reset

D

Q

R

D

Q

R

D

Q

R

CLK

I0

I1

I2

I3

A0

A1

A2

A3

CLK

I3

I2

I1

I0

A3

A2

A1

A0

Note: New data has to go in with every clock

6

8 of 36

Registers with Parallel Load

  • Control Loading the Register with New Data
    • Add the Load (LD) input to decide when the data is loaded
    • How?

LD

Q(t+1)

0

Q(t)

1

D

D3

D2

D1

D0

Q3

Q2

Q1

Q0

LD

4-bit Register

7

9 of 36

Registers with Parallel Load

  • The load can be used to block/disable the clock!
  • Should we block the “Clock” to keep the “Data”?

D

Q

CLK

I0

A0

D

Q

I1

A1

D

Q

I2

A2

D

Q

I3

A3

Load

Delays the Clock

D3

D2

D1

D0

Q3

Q2

Q1

Q0

LD

4-bit Register

8

10 of 36

Registers with Parallel Load

  • Alternatively, use the LD to decide what happens on the edge: hold the old data or load the new data

D

Q

CLK

I0

A0

D

Q

I1

A1

D

Q

I2

A2

D

Q

I3

A3

Load

MUX

I0

I1

Y

S

MUX

I0

I1

Y

S

MUX

I0

I1

Y

S

MUX

I0

I1

Y

S

9

11 of 36

Shift Registers

10

12 of 36

Remember! Shift Left Operation

1

0

1

0

1

0

1

0

1

1

0

0

0

0

x

x

11

13 of 36

Remember! Logical Shift Right Operation

1

0

1

0

1

0

1

0

0

1

1

0

0

0

x

x

12

14 of 36

Remember! Arithmetic Shift Right Operation

1

0

1

0

1

0

1

1

1

1

1

1

1

1

x

x

13

15 of 36

Shift Registers

  • Shift Registers move data laterally within the register toward its MSB or LSB position
  • In the simplest case, the shift register is simply a set of �D flip-flops connected in a row like this (4-bit shift register)

Serial�Input

Serial�Output

D

Q

D

Q

D

Q

D

Q

CLK

SI

SO

A

B

C

D

Parallel Output

14

16 of 36

Shift Registers

D

Q

D

Q

D

Q

D

Q

CLK

SI

SO

Q3

SI

Q2

Q1

Q0

CLK

Q3

Q2

Q1

Q0

15

17 of 36

Universal Shift Register

  • Performs the following operations
    • Parallel-in Parallel-out
    • Serial-in Serial-out
    • Serial-in Parallel-out
    • Parallel-in Serial-out

D

Q

D

Q

D

Q

D

Q

16

18 of 36

Universal Shift Register

D

Q

D

Q

D

Q

D

Q

MUX

I3 I2 I1 I0

Y

S1�S0

Q3

Q2

Q1

Q0

D1

S1�S0

CLK

CLR

D0

D2

D3

SI for SR

SI for SL

17

19 of 36

Universal Shift Register

Q3

Q2

Q1

Q0

D3

D2

D1

D0

S1

S0

USR

CLR

SRin

SLin

Mode Control

Register Operation

S1

S0

0

0

No change

0

1

Shift right

1

0

Shift left

1

1

Parallel load

18

20 of 36

Real Stuff

  • 74LS194
  • 4-Bit Bidirectional Universal Shift Register

19

21 of 36

Counters

20

22 of 36

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
    • Synchronous Counters

21

23 of 36

Types of Counter

Synchronous

Ripple

22

24 of 36

Example 1 – 4-bit Ripple Counter

  • Design a 4-bit ripple counter using T flip-flops

    • We need to know how to connect the FF inputs (T and clock)
    • Investigate the counting pattern!

T

Q

CLR

T

Q

CLR

T

Q

CLR

T

Q

CLR

Q3

Q2

Q1

Q0

CLK

CLR

23

25 of 36

Example 1 - 4-bit Ripple Counter

Q3

Q2

Q1

Q0

0

0

0

0

0

0

0

1

0

0

1

0

0

0

1

1

0

1

0

0

0

1

0

1

0

1

1

0

0

1

1

1

1

0

0

0

1

0

0

1

1

0

1

0

1

0

1

1

1

1

0

0

1

1

0

1

1

1

1

0

1

1

1

1

  • Q0: toggles on every count
    • Connect its clock input to the clock
    • T0 =1
  • Q1: toggles when Q0 change from 1 to 0
    • Connect its clock to Q0
    • T1 = 1
  • Q2: toggles when Q1 change from 1 to 0
    • Connect its clock to Q1
    • T2 = 1
  • Q3: toggles when Q2 change from 1 to 0
    • Connect its clock to Q2
    • T3 = 1

24

26 of 36

Example 1 - 4-bit Ripple Counter

T

Q

CLR

T

Q

CLR

T

Q

CLR

T

Q

CLR

Q3

Q2

Q1

Q0

CLK

CLR

1

1

1

1

CLK

Q0

Q1

Q2

Q3

Delay accumulates towards the MSB

0

1

2

3

4

5

6

7

8

9

25

27 of 36

Example 1 - 4-bit Ripple Counter Using D FFs

D

Q

Q

D

Q

Q

D

Q

Q

D

Q

Q

Q3

Q2

Q1

Q0

CLK

CLK

Q0

Q1

Q2

Q3

0

1

2

3

4

5

6

7

8

9

26

28 of 36

Real Stuff

  • 74HC4024
  • 7-stage binary ripple counter

27

29 of 36

Example 2

  • Design the following synchronous counter using D FFs

    • Six states only!
    • Unused states?

28

30 of 36

Example 2

  • Design the following synchronous counter

29

31 of 36

Example 3 - Synchronous 4-bit Binary Counter

Q3

Q2

Q1

Q0

0

0

0

0

0

0

0

1

0

0

1

0

0

0

1

1

0

1

0

0

0

1

0

1

0

1

1

0

0

1

1

1

1

0

0

0

1

0

0

1

1

0

1

0

1

0

1

1

1

1

0

0

1

1

0

1

1

1

1

0

1

1

1

1

Design a 4-bit synchronous binary counter using JK FFs. The counter has an enable input to pause/resume counting.

  • All FFs are synched to the clock.
  • The Qs toggle; however, this should happen if Enable is 1 when the edge arrives.
  • Q0 toggles on every edge if Enable is 1
    • Connect the J and K inputs to Enable
  • Q1 toggles when Enable is 1 and Q0 is 1 when the edge arrives
    • Connect J and K to the AND of Q0 and Enable
  • Q2 toggles when Enable = Q0 = Q1 = 1 when the edge arrives
    • Connect J and K to the AND of Q0, Q1 and Enable
  • Q3 toggles when Enable = Q0 = Q1 = Q2 = 1 when the edge arrives
    • Connect J and K to the AND of Q0, Q1, Q2 and Enable

30

32 of 36

Example 3 - Synchronous 4-bit Binary Counter

J

Q

Q

K

CLK

Enable

Q3

Q2

Q1

Q0

J

Q

Q

K

J

Q

Q

K

J

Q

Q

K

To Next Stage

31

33 of 36

Example 4 - Up-Down Binary Counter

T

Q

Q

Up

T

Q

Q

T

Q

Q

T

Q

Q

Q3

Q2

Q1

Q0

Down

CLK

Design a 4-bit synchronous binary counter using T FFs. The counter has two inputs; up and down, to control counting order.

32

34 of 36

Binary Counter with Parallel Load

Q3

Q2

Q1

Q0

LD

I3

I2

I1

I0

Count

CLR

LD

Count

Q(t+1)

0

x

x

0

1

0

0

Q(t)

1

0

1

Q(t)+1

1

1

x

I

CLR

Usually Asynchronous Clear

33

35 of 36

Example 5

Q3

Q2

Q1

Q0

LD

I3

I2

I1

I0

Count

CLR

0

0

0

0

A3

A2

A1

A0

1

CLK

Count

The following counter can count 0,1,2, … 15, 0, 1, … . Modify it to

count up to 10 only.

Can you think of a different approach? How about using the CLR input?

34

36 of 36

Example 5

Q3

Q2

Q1

Q0

LD

I3

I2

I1

I0

Count

CLR

0

0

0

0

A3

A2

A1

A0

1

CLK

Count

The following counter can count 0,1,2, … 15, 0, 1, … . Modify it to

count up to 10 only.

Can you think of a different approach? How about using the CLR input?

35