Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf ·...

47
Feedback and Flip-Flops Philipp Koehn 7 September 2019 Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Transcript of Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf ·...

Page 1: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

Feedback and Flip-Flops

Philipp Koehn

7 September 2019

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 2: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

1The Story So Far

• We can encode numbers

• We can do calculation

• ... but it’s all a bit static

• How about a counter?

→ this requires "memory"

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 3: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

2

feedback

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 4: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

3A Strange Contraption

- +

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 5: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

4Let’s Turn It On

- +

Electricity is on → this opens the normally closed key

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 6: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

5Let’s Turn It On

- +

Electricity is off → this closes the normally closed key

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 7: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

6What Do We Have?

• A Buzzer

• A Clock

• An Oscillator

NOT

(symbol)

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 8: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

7Oscillator

• Period of oscillator

• Frequency: cycles per second

• Unit: 1 cycle per second: 1 Hertz

• Modern computes:Billions of Hertz = Gigahertz (GHz)

Heinrich Hertz

1857--1894

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 9: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

8

flip flop

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 10: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

9Another Contraption

V

V

NORNOR OUT

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 11: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

10Closing Upper Key

V

V

NORNOR OUT

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 12: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

11Opening Upper Key

V

V

NORNOR OUT

Same key configuration as initially

But: Now OUT is on --- we remembered the key turn

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 13: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

12Closing Lower Key

V

V

NORNOR OUT

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 14: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

13Opening Lower Key

V

V

NORNOR OUT

Back to initial state

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 15: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

14Memory

• We have memory -- called Reset-Set Flip-Flop

• Truth table

UPPER LOWER OUT

0 0 OUT

0 1 0

1 0 1

1 1 Illegal

• UPPER = SET

• LOWER = RESET

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 16: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

15Re-Arranged

NOR

NOR Q

S

R

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 17: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

16Symmetric

NOR

NOR

Q

Q

S

R

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 18: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

17Truth Table

S R Q Q̄

1 0 1 0

0 1 0 1

0 0 Q Q̄

1 1 Illegal

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 19: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

18

d-type flip flop

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 20: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

19Vision

• Control bit ("clock")

– on = write to memory– off = read from memory

• Data bit

– data item to be written

• Output

– current state of the memory

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 21: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

20Replace Set/Reset with Data

NOR

NOR

Q

Q

DATA

NOT

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 22: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

21Add Control Bit ("Clock")

Q

Q

DATA

NOT

AND

ANDNOR

NOR

CLOCK

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 23: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

22D-Type Flip-Flop

• Also called D-type latch

• Circuit latches on one bit of memory and keeps it around

• Truth table

Data Clock Q Q̄

0 1 0 1

1 1 1 0

X 0 Q Q̄

• Can also build these for multiple data bits

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 24: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

23

accumulative adder

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 25: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

24Design Goal

• Adder has initially value 0

• Adding a number

→ value increases

• Resetting

→ value goes back to 0

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 26: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

25Ingredients

8-BIT ADDERA7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0

S7 S6 S5 S4 S3 S2 S1 S0

CO CI

8-BIT LATCHD7 D6 D5 D4 D3 D2 D1 D0

Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0

CLK

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 27: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

26Ingredients

8

8-BIT ADDERA B

SCO CI

8

8

8

8-BIT LATCHD

QCLK

8

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 28: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

27Building an Accumulative Adder

8

8

8-BIT LATCHD

Q

CLK

0

CLOCK• Latch: current sum

• Clock on → set it to 0

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 29: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

28Building an Accumulative Adder

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

CLOCK

OUT

• Adder

• Combines

– current value

– selected input

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 30: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

29Building an Accumulative Adder

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

CLOCK

OUT

• Can we pass outputdirectly to latch?

• Concerns

– select between 0 and sum

– only stored when clock on

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 31: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

30Building an Accumulative Adder

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

CLOCK

OUT

2-1 SELECTORB

S

A

8 8Clear

• 2-1 selector

• Either uses 0 or sum

• Built with AND gates

• Still have runaway feedback loop...

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 32: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

31Building an Accumulative Adder

8

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

CLOCK2

OUT

2-1 SELECTORB

S

A

8 8

8-BIT LATCHD

Q

CLKCLOCK1

S

Clear• Two Latches

– one to store the sum

– one to store input to adder

• Clock 1

– carry out addition

– store result

• Clock 2

– transfer to set up next addition

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 33: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

32Building an Accumulative Adder

8

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

OUT

2-1 SELECTORB

S

A

8 8

8-BIT LATCHD

Q

CLK

S

NOT

Add

Clear• Combine the clocks

• Pressing the add key

– carry out addition

– store result in upper latch

• Release the add key

– transfer to lower latch

– set up next addition

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 34: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

33What Else?

8

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

OUT

2-1 SELECTORB

S

A

8 8

8-BIT LATCHD

Q

CLK

S

NOT

Add

Clear

• Remember the oscillator?

NOT

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 35: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

34What Else?

8

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

OUT

2-1 SELECTORB

S

A

8 8

8-BIT LATCHD

Q

CLK

S

NOT

Clear

NOT

• Each cycle of oscillator:

keeps adding

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 36: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

35What Else?

8

8

8

8

8-BIT LATCHD

Q

CLK

0

8-BIT ADDERB

S

A

CO

8

IN

CI

OUT

2-1 SELECTORB

S

A

8 8

8-BIT LATCHD

Q

CLK

S

NOT

Clear

NOT

• We have something interesting here

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 37: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

36

edge triggered flip-flop

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 38: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

37D-Type Latch

LATCHD

CLK

Q

Q

• When clock is on, save data

• "Level-triggered"

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 39: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

38D-Type Latch

LATCHD

CLK

Q

Q

LATCHD

CLK

Q

Q

NOT

• "Edge-triggered": changes value, when switched from 0 to 1

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 40: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

39Edge Triggered D-Type Latch

D

> CLK

Q

Q

Symbol

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 41: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

40Truth Table

Data Clock Q Q̄

0 ↑ 0 1

1 ↑ 1 0

X 0 Q Q̄

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 42: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

41

ripple counter

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 43: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

42Oscillator and Latch

D

> CLK

Q

Q

NOT

Data Clock Q Q̄

1 0 0 1

1 ↑ 1 0

0 1 1 0

0 0 1 0

0 ↑ 0 1

1 1 0 1

1 0 0 1

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 44: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

43Oscillator and Latch

D

> CLK

Q

Q

NOT

Data Clock Q Q̄

1 0 0 1

1 ↑ 1 0

0 1 1 0

0 0 1 0

0 ↑ 0 1

1 1 0 1

1 0 0 1

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 45: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

44Halving of Frequency

Data Clock Q Q̄

1 0 0 1

1 ↑ 1 0

0 1 1 0

0 0 1 0

0 ↑ 0 1

1 1 0 1

1 0 0 1

IN

OUT

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 46: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

45Multiple Bits

D

> CLK

Q

Q

NOT

NOT

OUT0 OUT1

D

> CLK

Q

Q

OUT2

D

> CLK

Q

Q

OUT3

OUT0

OUT1

OUT2

OUT3

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019

Page 47: Feedback and Flip-Flops - Department of Computer Sciencephi/csf/slides/lecture-flipflop.pdf · 2019-08-27 · Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7

46Ripple Counter

OUT0

OUT1

OUT2

OUT3

0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

0 0 1 1 0 0 1 1 11 1 10 0 0 0

0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Philipp Koehn Computer Systems Fundamental: Feedback and Flip-Flops 7 September 2019