Sequential logic •Latches •Flip-flops •Counters

89
Andrew H. Fagg: Embedded Real-Time Systems: Sequential Logic 1 Today Sequential logic • Latches • Flip-flops • Counters

Transcript of Sequential logic •Latches •Flip-flops •Counters

Page 1: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

1

Today

Sequential logic

• Latches

• Flip-flops

• Counters

Page 2: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

2

Time

Until now: we have essentially ignored theissue of time

• We have assumed that our digital logiccircuits perform their computationsinstantaneously

• Our digital logic circuits have been“stateless”– Once you present a new input, they forget

everything about previous inputs

Page 3: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

3

Time

In reality, time is an important issue:

• Even our logic gates induce a smallamount of delay (on the order of a fewnanoseconds)

• For much of what we do – we actuallywant our circuits to have some form ofmemory

Page 4: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

4

Timing Notation

time

X

high

lowIn transition(undetermined)

Page 5: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

5

Timing Notation

time

X

Either high or low (but well defined and constant)

low

In transition(undetermined)

Page 6: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

6

NAND Latch

What does this circuit do?

Page 7: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

7

NAND Latch

Consider this initial state

Is this a stable state?

10

11

Yes!

Page 8: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

8

NAND Latch

What happens with S is set to 0?

00->?

11->?

Page 9: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

9

NAND Latch

What happens with S is set to 0?

Q becomes 1 (thus S ‘sets’ Q)

00->1

11->0

Page 10: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

10

NAND Latch

Now S is set 1 – what happens?

11->?

10->?

Page 11: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

11

NAND Latch

Q and Q’ remain the same!

11->1

10->1

So Q and Q’ retain a memory of past state!

Page 12: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

12

NAND Latch

Now set R to 0 – what happens?

11->?

00->?

Page 13: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

13

NAND Latch

Now set R to 0 – what happens?

The state flips back (Q is ‘reset’)

11->0

00->1

Page 14: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

14

NAND Latch

Finally: set R to 1 – what happens?

10->?

11->?

Page 15: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

15

NAND Latch

Finally: set R to 1 – what happens?

Q and Q’ do not change state

10->0

11->1

Page 16: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

16

Timing Diagram Representation

S

R

Q

Q’

?

Page 17: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

17

Timing Diagram Representation

S

R

Q

Q’

Note small delay in response in Q and Q’

Page 18: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

18

Timing Diagram Representation

S

R

Q

Q’

When S returns to high –both Q and Q’ remain in the same state

Page 19: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

19

Timing Diagram Representation

S

R

Q

Q’

?

Page 20: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

20

Timing Diagram Representation

S

R

Q

Q’

Q and Q’ flipstate

Page 21: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

21

Timing Diagram Representation

S

R

Q

Q’

How about this case?

Page 22: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

22

Timing Diagram Representation

S

R

Q

Q’

No change in Q and Q’

Page 23: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

23

Latches

Provide us with a simple form of memory

• State of the circuit depends not only onthe current inputs, but also on the recenthistory of the inputs

Page 24: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

24

Latches

But: our circuit responds any time the inputsare low

• We want to limit the state change to a verynarrow time period

• This will allow us to synchronize the statechange of several devices

-> Flip Flops

Page 25: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

25

Flip Flops

• Add one more input to the circuit: a “clock”signal

• We will only allow the state of the output tochange in response to S & R when theclock transitions from 1 to 0

Page 26: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

26

Flip Flops

• Add one more input to the circuit: a “clock”signal

• We will only allow the state of the output tochange in response to S & R when theclock transitions from 1 to 0

Page 27: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

27

Flip Flops

Page 28: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

28

R-S Flip Flop

Initial state

0

0

0

0

1

1

1

1

1

0

0

1

Note that the meaning of S & R has been inverted

Page 29: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

29

R-S Flip Flop

Clock goes high

0

0

0->1

0

1

1

1

1->0

1

0->1

0

1

No change in Q and Q’

Page 30: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

30

R-S Flip Flop

Clock goes low again

0

0

1->0

0

1

1

1

0->1

1

1->0

0

1

Still no change in Q and Q’

Page 31: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

31

R-S Flip Flop

S goes high

0->1

0

0

0

1

1

1

1

1

0

0

1

Nothing in the circuit changes

Page 32: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

32

R-S Flip Flop

Now: clock goes high

1

0

0->1

0->1

1->0

1->0

1

1->0

1

0->1

0

1

The state of the first latch changes

Page 33: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

33

R-S Flip Flop

Now: clock goes low

1

0

1->0

1

0

0->1

1

0->1

1->0

1

0->1

1->0

The state of the second latch changes!

Page 34: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

34

R-S Flip FlopTiming Diagram Representation

S

R

Q

Q’

C Q and Q’ flip stateonly after theclock goes low

Page 35: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

35

R-S Flip Flop

The timing of the drop of S is not critical

• But it must do so before the clock goeslow

Page 36: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

36

R-S Flip FlopTiming Diagram Representation

S

R

Q

Q’

C The circuit willrequire aspecified amountof “setup time”

Page 37: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

37

R-S Flip Flop Summary

Behaves like an R-S latch – but:

• The flip flop will only “pay attention” to theR-S inputs on the falling edge of the clock

Page 38: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

38

Next Time

• D flip flops

• Binary number encoding

• Shift registers

• Counters

Page 39: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

39

Last Time

• Project 1 specification

• Sequential logic:– R-S Latch

– R-S Flip flop

Page 40: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

40

Today

Sequential circuits continued

• Clocked R-S latch

• D Flip flop

• Binary coding

• Shift registers

• Counters

Page 41: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

41

Administrivia

• Mark back?

• Homework 1 is out:– Due Feb 17th @ 5:00

• Project 1:– Worth 8% of your final grade

– The group that demonstrates successfully firstwill receive an extra 0.5% of extra credit

Page 42: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

42

Latch vs Flip flop

• Latch implements a simple form ofmemory

• A flip flop adds:– Precise control over when the state of the

memory changes

Page 43: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

43

Clocked R-S Latch

Allows some control over when the latchchanges state

Page 44: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

44

Clocked R-S Latch

State can only change when the clock ishigh

Note that R or S must be high to cause areset or a set

Page 45: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

45

Clocked R-S Latch

S

R

Q

Q’

C Q and Q’ flip statewhen the clock ishigh

Page 46: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

46

Clocked R-S Latch

How is this different than our R-S flip flop?

Page 47: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

47

Clocked R-S Latch

S

R

Q

Q’

C

What do Q and Q’do?

Page 48: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

48

Clocked R-S Latch

S

R

Q

Q’

C

Clock triggers flip

Page 49: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

49

Clocked R-S Latch

S

R

Q

Q’

C

R triggers reset

Page 50: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

50

Clocked R-S Latch

S

R

Q

Q’

C

S triggers set

Page 51: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

51

Clocked R-S Latch

S

R

Q

Q’

CClock goes low:No furtherchanges in state

Page 52: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

52

R-S Latch vs Flip Flop

What would the R-S flip flop do?

Page 53: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

53

R-S Flip Flop

S

R

Q

Q’

C

What happens toQ and Q’?

Page 54: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

54

R-S Flip Flop

S

R

Q

Q’

C

State change onlyon downwardedge of the clock

Page 55: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

55

R-S Flip Flop

State change happens at a very precise time

Page 56: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

56

R-S Flip Flop

State change happens at a very precise time

But:

• We must guarantee that R and S arenever high at the same time

• We would like to be able to store thehigh/low state of a single line

Page 57: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

57

D-Type Flip Flop

Replace R/S with D

• In essence, R is replaced with D’

Page 58: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

58

D-Type Flip Flop

D=1 results in a ‘set’ of the latch

1

1

1

0

Page 59: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

59

D-Type Flip Flop

D=1 results in a ‘set’ of the latch

1

1

1

0

0

1

0

1

1

Page 60: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

60

D-Type Flip Flop

Clock transitions from high to low

1->0

1

1

0->1

0

1

0->1

1->0

1

Page 61: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

61

D-Type Flip Flop

Clock transition -> ‘set’ of the slave latch

1->0

1

1

0->1

0

1

0->1

1->0

1

1

0

Page 62: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

62

D-Type Flip Flop

D=0 results in a ‘reset’ of the latch

1

0

0

1

Page 63: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

63

D-Type Flip Flop

D=0 results in a ‘reset’ of the latch

1

0

0

1

1

0

0

1

1

Page 64: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

64

D-Type Flip Flop

Clock transitions from high to low results in a‘reset’ of the slave latch

1->0

0

0->1

1

1

0

0->1

1

1->01

0

Page 65: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

65

D Flip Flop

D

Q

Q’

C

What happens toQ and Q’?

Page 66: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

66

D Flip Flop

D

Q

Q’

C

What happens toQ and Q’?

Page 67: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

67

D Flip Flop

D

Q

Q’

C

What happens toQ and Q’?

Page 68: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

68

D Flip Flop

D

Q

Q’

C

No changein state

Page 69: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

69

D Flip Flops

Clock

Page 70: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

70

An Application of D Flip Flops

What does this circuit do?

Page 71: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

71

Shift Register

On each clock transition from high to low:

• X0 takes on the current value of D

• X1 <- X0

• X2 <- X1

Page 72: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

72

Another D Flip Flop Circuit

How does this circuit behave?

Page 73: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

73

Frequency Divider

How does this circuit behave?

CLK

Q

Page 74: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

74

Frequency Divider

Q flips state on every downward edge of theclock

CLK

Q

Page 75: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

75

A Bit About Binary Encoding

If a boolean variablecan only encode twodifferent values, howdo we represent alarger number ofvalues?

www.thinkgeek.com

Page 76: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

76

Binary Encoding

How do we represent a larger number ofvalues?

• As with our decimal number system: weconcatenate binary digits (or “bits”) intostrings

Page 77: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

77

Binary Encoding

• The first (rightmost) bit is the 1’s digit

• The second bit is the 2’s digit

• The ith bit is the 2i-1 ’s digit

Page 78: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

78

Binary Encoding

How do weconvert frombinary todecimal ingeneral?

7111

6011

5101

4001

3110

2010

1100

0000

decimalB0B1B2

Page 79: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

79

Last Time

Sequential Logic

• D Flip Flops

• Shift registers

• Ripple Counters

Binary number system

Page 80: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

80

Today

• A little more on number systems

• Arithmetic operators

• Representing negative numbers

• Multiplication with shift registers

• Arithmetic logic units

Page 81: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

81

Administrivia

• Homework 1 due in 1 week

• Project 1:– One robot is now up and stable

– A complete set of power supplies will beavailable today

Page 82: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

82

Binary to Decimal Conversion

K++++= 33

22

110 2*2*2* BBBBvalue

∑−

=

=1

0

2*N

i

iiBvalue

How do we convert from decimalto binary?

Page 83: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

83

Decimal to Binary Conversion

}

2

1

22

{

)0(

0:

1

i

i

ii

i

valuevalue

B

valuesuchthatiFind

valuewhile

Bi

−←

≥>

←∀

+

Page 84: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

84

Binary Counter

How would we build acircuit that counts thenumber of clock ticksthat have gone by?

111

011

101

001

110

010

100

000

B0B1B2

Page 85: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

85

Binary Counter

How would we build acircuit that counts thenumber of clock ticksthat have gone by?

Insight:• B1 changes state at half

the frequency that B0does

• B2 changes state at halfthe frequency of B1

111

011

101

001

110

010

100

000

B0B1B2

Page 86: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

86

Ripple Counter

The carry “ripples” down the chain …

Page 87: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

87

J-K Flip Flops

Behave similarly to R-S flip flops, but:

• Deal properly with the case where both Rand S inputs are 1– The R-S flip flop will arbitrarily choose one of

the possible output states

• The master latch (on the input side) canonly change state once while the clock ishigh

Page 88: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

88

T Flip Flops

• J-K flip flop with R and S tied high

• Every downward clock edge causes theflip flop to change state

• This is just like our D flip flop with Dconnected to Q’

Page 89: Sequential logic •Latches •Flip-flops •Counters

Andrew H. Fagg: EmbeddedReal-Time Systems: Sequential

Logic

89

Next Time

Binary Arithmetic:• Addition• Representing negative numbers &

subtraction• A little bit on multiplicationOther number systems• Octal• Hexadecimal