Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading...

36
16 Page 1 ECE 238L © 2006 Cascaded Counters

Transcript of Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading...

Page 1: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 1

ECE 238L © 2006

Cascaded Counters

Page 2: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 2

ECE 238L © 2006

A Mod4 Counter(A 2-bit counter)

CLR INC Q1 Q0 N1 N0

0 0 0 0 0 00 0 0 1 0 10 0 1 0 1 00 0 1 1 1 10 1 0 0 0 10 1 0 1 1 00 1 1 0 1 10 1 1 1 0 01 - - - 0 0

00

10

0111

CLR’ •INCCLR’ • INC’

CLR

CLR’ • INCCLR’ • INC

CLR’ • INC

CLR’ • INC’

CLR’ • INC’

CLR’ • INC’

Page 3: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 3

ECE 238L © 2006

A Mod4 Counter With a Rollover Signal

CLR INC Q1 Q0 N1 N0 Rollover

0 0 0 0 0 0 00 0 0 1 0 1 00 0 1 0 1 0 00 0 1 1 1 1 00 1 0 0 0 1 00 1 0 1 1 0 00 1 1 0 1 1 00 1 1 1 0 0 11 - - - 0 0 0

00

10

0111

CLR’ • INCCLR’ • INC’

CLR

CLR’ • INCCLR’ • INC

CLR’ • INC/Rollover

CLR’ • INC’

CLR’ • INC’

Signal Rollover can be used to tellother circuitry that counter isrolling over to all 0’s

Mealy output CLR’ • INC’

Page 4: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 4

ECE 238L © 2006

Cascading 2 Mod4 Counters

0001020310111213202122233031323300

Count sequence

Mod4 Counter

2

INCRollover0

Digit0

Increment higherdigit’s counterwhen lower digit’scounter is rollingover

Digit1 Digit0

CLRMod4

Counter

2

Rollover1

Digit1

CLR

clk clk

Page 5: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 5

ECE 238L © 2006

3 Digits’ Worth

Mod4 Counter

2

INCRollover0

Digit0

CLRMod4

Counter

2

Rollover1

Digit1

CLRMod4

Counter

2

Rollover2

Digit2

CLR

Increment higherdigit’s counterwhen lower digit’scounter is rollingover

Can do this with anycounter that has a Rollover outputCould build a digital watch

or clock circuit this way withMod60 and Mod24 counters

clkclkclk

Page 6: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 6

ECE 238L © 2006

Cascading Counters

• A counter will increment only when– The counter below it is at its terminal count

and it is being incremented• That is the definition of the Rollover signal

• Some people try to tie Rollover to the clkinput of the next higher counter– Bad idea… Very bad idea…– Violates our Globally Synchronous policy– Doesn’t work as intended

Page 7: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 7

ECE 238L © 2006

Mod4 Counter

2

INC=‘1’

Rollover0

Digit0

CLRMod4

Counter

2

Rollover1

Digit1

CLR

clk1 clk

‘1’

clk

Digit0 2 0

Clk1(Rollover0)

3

Digit1 1 2

1 2

Sequence should be:…-12-13-20-21-22-23-30-…

but we get:…-12-23-20-21-22-33-30-…

?????

DO NOT TIE CLKinputs on modulesto anything but the clock !!!!!!

Even if you tinker untilyou get the right countsequence, you mustguarantee that signalRollover0 has no hazards

Digit0 transition from 1-2 makes this difficult if not impossible

Page 8: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 8

ECE 238L © 2006

Mod4 Counter

2

INC=‘1’

Rollover0

Digit0

CLRMod4

Counter

2

Rollover1

Digit1

CLR

clk1 clk

‘1’

clk

Digit0 2 0

Clk1(Rollover0)

3

Digit1 1 2

1 2

Sequence should be:…-12-13-20-21-22-23-30-…

but we get:…-12-23-20-21-22-33-30-…

?????

DO NOT TIE CLKinputs on modulesto anything but the clock !!!!!!

Even if you tinker untilyou get the right countsequence, you mustguarantee that signalRollover0 has no hazards

Digit0 transition from 1-2 makes this difficult if not impossible

Possible hazard

Page 9: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 9

ECE 238L © 2006

Ripple Counters

• When you tie a rollover-like signal to a clock on the next higher digit ripple counter

• A ripple counter is an ASYNCHRONOUS counter– Transitions are not all synchronized to the clock– Different flip flops change at different times– Similar to gated clocks (seen earlier)

• Asynchronous circuits are an advanced topic

Page 10: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 10

ECE 238L © 2006

Another Common Ripple Counter

CLK

T QQ’

‘1’T Q

Q’

‘1’T Q

Q’

‘1’T Q

Q’

‘1’

Q3 Q2 Q1 Q0

Sequence is:

00000001001000110100010101100111100010011010101111001101111011110000

So what is the problem?

Page 11: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 11

ECE 238L © 2006

Timing Diagram

clk

Q0

Q1

Q2

Q3

Q0 changes in response to clock edge

Only after it changes does Q1’s FF get a clock

Only after that does Q2’s FF get a clock

Net effect is that all the FF’s change at different times

Logic depending on Q3 has very little timeto react before next clock edge

Page 12: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 12

ECE 238L © 2006

Do Not Use Asynchronous or Ripple Counters

CLK

T QQ’

‘1’T QQ’

‘1’T QQ’

‘1’T QQ’

‘1’

Q3 Q2 Q1 Q0

Mod4 Counter

2

INC=‘1’

Rollover0

Digit0

CLR

Mod4 Counter

2

Rollover1

Digit1

CLR

clk1

clk

‘1’

Page 13: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 13

ECE 238L © 2006

Reset

Reset

Reset

00 CEin Reset’

(CEin Reset’)/CEout

CEin Reset’CEin Reset’

01

10

11

Mod4 Counter

Page 14: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 14

ECE 238L © 2006

The State Flip- Flop

Note: Both CLK and CE are requiredto change the flip-flop

Page 15: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 15

ECE 238L © 2006

Mod4 Counter

CEin Q1 Q0 N1 N0 CEout

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 1 0 0

0 1 1 1 1 0

1 0 0 0 1 0

1 0 1 1 0 0

1 1 0 1 1 0

1 1 1 0 0 1

Q1Q0 N1

Ce 00 01 11 10

0 1 1

1 1 1

Q1Q0 N0

Ce 00 01 11 10

0 1 1

1 1 1

N1 = Ce’Q1 + Q1Q0’ + CeQ1’Q0

N0 = Ce’Q0 + CeQ0’ CEout = CeQ1Q0

Note: No change when CEin=0

Page 16: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 16

ECE 238L © 2006

Mod4 Counter

Page 17: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 17

ECE 238L © 2006

Reset

CLKin

Dout

Next Counter

CEout

Stage 2incrementsis tooearly

Cascaded Ripple Counter

Page 18: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 18

ECE 238L © 2006

Cascaded Ripple Counter

Why is Next Stage increment too early?

10 11

00 01

Stage 1

CEout

Stage 2

CEout from Stage 1 is used as the clockfor Stage 2

master loadsslave loads

Page 19: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 19

ECE 238L © 2006

Cascaded Ripple Counter

A Ripple Counter is an ASYNCHRONOUS counter

since it’s transitions are NOT synchronized to the

system clock.

In a SYNCHRONOUS counter, all stages transition

with the system clock

Page 20: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 20

ECE 238L © 2006

Reset

CLKin

Dout

Next Counter

CEout

Cascaded Synchronous Counter

Stage 2 isincrementedat the correcttime

Page 21: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 21

ECE 238L © 2006

10 11

00 01

Stage 1

CEout

Stage 2

00

slave loads slave loadsmaster loadsmaster loads

Stage 2 master loads

Stage 2 slave loads

Cascaded Synchronous Counter

SystemClock

Page 22: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 22

ECE 238L © 2006

Stage 1

Stage 2

Stage 3

S

SA

A

Cascaded Counters

The more stages you add to the counter, the biggerthe discrepancy between Synchronous and Asynchronous counters

Page 23: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 23

ECE 238L © 2006

Cascaded Synchronous Counter

ClkCEin

CEinCount

ClkCEin

CEinCount

ClkCEin

CEinCount

‘1’

CEin controls when the S.M. can change

CEin also controls when the CEout will be generated

Page 24: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 24

ECE 238L © 2006

Color Code: ClockStage 1Stage 2Stage 3

Cascaded Synchronous Counter

Note that the CEout from each stage is synchronized with the system clock and with each other. The stage transitions are all synchronized with the system clock

CEout 1

CEout 2

Page 25: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 25

ECE 238L © 2006

Cascaded Synchronous Counter

Lesson : Always use SYNCHRONOUS counters and timers.

Page 26: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 26

ECE 238L © 2006

A Mod4 Counter

D Q

D Q

IFL

Inc

TerminalCount

CountValue

CLR INCQ1 Q0 N1 N0 RO

0 0 0 0 0 0 00 0 0 1 0 1 00 0 1 0 1 0 00 0 1 1 1 1 00 1 0 0 0 1 00 1 0 1 1 0 00 1 1 0 1 1 00 1 1 1 0 0 11 - - - 0 0 0

Clr

Page 27: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 27

ECE 238L © 2006

D Q

D Q

IFL

Inc

TerminalCount

RollOver

A Mod4 Counter

CountValue

You wouldn’t really build it like this!

Clr

CLR INCQ1 Q0 N1 N0 RO

0 0 0 0 0 0 00 0 0 1 0 1 00 0 1 0 1 0 00 0 1 1 1 1 00 1 0 0 0 1 00 1 0 1 1 0 00 1 1 0 1 1 00 1 1 1 0 0 11 - - - 0 0 0

Page 28: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 28

ECE 238L © 2006

Cascaded Counters

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

CV CV CV

Inc

Clk

Clr Clr Clr

Clr

Page 29: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 29

ECE 238L © 2006

Cascaded Counters

Assume that the second timer is already at the terminal count

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

CV CV CV

Inc

Clk

Clr Clr Clr

Clr

Page 30: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 30

ECE 238L © 2006

Cascaded Counters

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

CV CV CV

Inc

Clk

Clr Clr Clr

Clr

Page 31: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 31

ECE 238L © 2006

Cascaded Counters

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

CV CV CV

Inc

Clk

Clr Clr Clr

Clr

Page 32: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 32

ECE 238L © 2006

Cascaded Counters

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

CV CV CV

Inc

Clk

Clr Clr Clr

Clr

Page 33: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 33

ECE 238L © 2006

Cascaded Counters

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

CV CV CV

Inc

Clk

Clr Clr Clr

Clr

Page 34: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 34

ECE 238L © 2006

Cascaded Counters

It looks like the Inc signal will ripple from counter to counter.Why is this any different from the toggle flip-flop example?

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

MOD4

Inc

TC

Clk

CV CV CV

Inc

Clk

Clr Clr Clr

Clr

Page 35: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 35

ECE 238L © 2006

D Q

D Q

IFL

Inc

TerminalCount

RollOver

A Mod4 Counter

CountValue

The right way!

Clr

Page 36: Cascaded Counters - University of New Mexicozbaker/ece238/slides/16cascade.pdf · Cascading Counters • A counter will increment only when – The counter below it is at its terminal

16Page 36

ECE 238L © 2006

A Mod4 Counter

MOD4

CountValue

RollOver

Clock

Clear

Increment