+ All Categories
Home > Documents > •J-K flip-flops •Edge-triggered flip-flops •Finite state...

•J-K flip-flops •Edge-triggered flip-flops •Finite state...

Date post: 16-Jul-2020
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
22
CMSC 313 Lecture 22 • J-K flip-flops • Edge-triggered flip-flops • Finite state machines • DigSim Assignment 2 UMBC, CMSC313, Richard Chang <[email protected]>
Transcript
Page 1: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

CMSC 313 Lecture 22

• J-K flip-flops

• Edge-triggered flip-flops• Finite state machines

• DigSim Assignment 2

UMBC, CMSC313, Richard Chang <[email protected]>

Page 2: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Recap: Latches vs Flip-Flops

• LatchOutput changes right after the input changes

No reference to clocking event

M&H’s “SR flip-flop” if often called an SR latch in other texts.

• Level-Sensitive LatchA latch that operates only when the clock is high or only when low

M&H’s “clocked SR flip-flop” is a level sensitive latch

• Flip-FlopReserved for circuits that record the input only during clocking events

The output of the flip-flop does not change during this clocking event

M&H’s “master-slave flip-flop” fits this definition

UMBC, CMSC313, Richard Chang <[email protected]>

Page 3: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

J-K Flip-Flops

• Allows both “set” and “reset” to be 1

• When both J and K are 1, the output toggles• If the clock is high, “endless toggle” occurs

• Master-slave J-K flip-flops solve the endless toggle problem, but has the ones-catching problem

• Use edge-triggered flip-flops to eliminate the ones-catching problem.

UMBC, CMSC313, Richard Chang <[email protected]>

Page 4: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-56

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Master-Slave J-K Flip-Flop

Q

QJ

CLK

J

Q

Q

K

CircuitSymbol

K

Richard Chang
Richard Chang
Page 5: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Master-Slave Flip-Flops Revisited

• Master-slave J-K flip-flopsShould get rid of the endless toggle condition when J=1 & K=1

Clocking Problem 1: if master turns on before slave turns off, slave latches the input as soon as the clock goes high.

Clocking Problem 2: if slave turns on before master turns off, feeback of Q and ¬Q propagates through the master.

• Two-Phase Clocks: always turn off first!

Clock 1

Clock 2

UMBC, CMSC313, Richard Chang <[email protected]>

Page 6: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-57

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Clocked T Flip-Flop• The presence of a constant 1 at J and K means that the flip-flop

will change its state from 0 to 1 or 1 to 0 each time it is clockedby the T (Toggle) input.

J

Q

Q

K

Circuit

Q

Q

Symbol

1

T T

Page 7: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Edge-Triggered Flip-Flops

• Records input during a low-to-high (positive edge) or a high-to-low (negative edge) clock transition

• Signal must be stable before “setup time” and continue to be stable for “hold time”

setup time

hold time

UMBC, CMSC313, Richard Chang <[email protected]>

Page 8: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-58

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Negative Edge-Triggered D Flip-Flop• When the clock is

high, the two inputlatches output 0, sothe Main latch re-mains in its previousstate, regardless ofchanges in D.

• When the clock goeshigh-to-low, values inthe two input latcheswill affect the state ofthe Main latch.

• While the clock islow, D cannot affectthe Main latch.

Q

Q

CLK

D

R

S

Main latch

Stores D

Stores D

Page 9: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Master-Slave vs Edge-Triggered

• Master-slave flip-flops record the input in the slave when the clock goes from high to low

• Are master-slave flip-flops negative edge-triggered flip-flops?

Some textbooks say “yes” others say “no”

Master-slave JK flip-flops have the ones catching problem (momentary high signal at J when the clock is high is “caught” and recorded.)

Master-slave D flip-flops do not have the ones catching problem

UMBC, CMSC313, Richard Chang <[email protected]>

Page 10: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-59

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Example: Modulo-4 Counter• Counter has a clock input (CLK) and a RESET input.

• Counter has two output lines, which take on values of 00, 01, 10,and 11 on subsequent clock cycles.

3-bit Synchronous

Counter

0 0 0 0 1 0 1 1 0 0RESET q0

4 3 2 1 04 3 2 1 0 Time (t)Time (t)

0 1 0 1 0

D

Q

Q

CLK

s0

s1

D

Q

Q

q1

s0

s1

Page 11: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-60

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

StateTransition

Diagram forMod-4

Counter

A B1/00

0/01

1/00

Output 00state

Output 01state

RESET

q1

C D

Output 10state

Output 11state

q0

0/101/00

0/00

0/11

1/00

Page 12: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-61

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

State Table for Mod-4 Counter

Present state

Input RESET

0 1

A B/01 A/00B C/10 A/00

Next state Output

C D/11 A/00D A/00 A/00

Page 13: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-62

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

State Assignment for Mod-4 Counter

Presentstate (St)

Input RESET

0 1

A:00 01/01 00/00B:01 10/10 00/00

C:10 11/11 00/00D:11 00/00 00/00

Page 14: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-63

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Truth Table for Mod-4 Counter

00110011

01010101

s1(t) s0(t)

00001111

RESET r(t)

0110110000000000

s1s0(t+1)

0110110000000000

q1q0(t+1)

s1(t+1) = r(t)s1(t)s0(t) + r(t)s1(t)s0(t)

s0(t+1) = r(t)s1(t)s0(t) + r(t)s1(t)s0(t)

q1(t+1) = r(t)s1(t)s0(t) + r(t)s1(t)s0(t)

q0(t+1) = r(t)s1(t)s0(t) + r(t)s1(t)s0(t)

Page 15: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Appendix A: Digital LogicA-64

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Logic Design for Mod-4 Counter

CLK

QD

Q

s1

QD

Q

s0

RESET

q1

q0

Page 16: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Mod 4 Counter Timing

Clock

Reset

s1

s0

q1

q0

Outputs 00 only when reset is high

UMBC, CMSC313, Richard Chang <[email protected]>

Page 17: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Mealy vs Moore Finite State Machines

• Mealy: output depends on input and state bits

CombinationalLogic

FlipFlops

input output

• Moore: output depends only on state bits

CombinationalLogic

FlipFlops

input output

CombinationalLogic

UMBC, CMSC313, Richard Chang <[email protected]>

Page 18: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

CMSC 313, Computer Organization & Assembly Language Programming Section 0101

Fall 2004

DigSim Assignment 2: A Finite State Machine

Due: Tuesday November 30, 2004

Objective: The objective of this assignment is to implement a finite state machine using DigSim.

Assignment: Consider the finite state machine from question A.34 of Murdocca & Heuring:

��� ���� �A

0/0

1/0

��

��� ���� �B1/0

�� �������

�������

��������

�0/0

��

��� ���� �C1/0

���������

��������

�������

�0/0

����� ���� �D

0/0,1/0

� �

��� ���� �E

0/1,1/1

!

This finite state machine starts in state A and has one input bit and one output bit. Themachine outputs 1 only after it has entered state E.

Your assignment is to implement this finite state machine in DigSim. You must:

1. Use three D flip-flops to store the 5 states of the machine. State A will be represented as 000,B = 001, C = 010, D = 011 and E = 100. The bit patterns 101, 110 and 111 are not used.

2. Let s2, s1, s0 be the state bits stored in the D flip-flops, x be the input bit and z be the outputbit. Fill in the attached truth table for the next state bits s′

2, s′

1, s′

0and the output bit z.

3. For s′2, s′

1, s′

0and z, use Karnaugh maps to obtain simplified SOP or POS Boolean formulas.

4. Implement the finite state machine in DigSim. You should study the “Sequence Detector”example in DigSim (use “Open example” under the File menu) for suggestions on the layoutof your finite state machine.

Implementation notes:

• Label the switches and flip-flops in your circuit appropriately.

• If you need a 4-input OR gate, you need to use two layers of 2-input or 3-input OR gates toaccomplish the same function. Ditto for 4-input AND gates.

• The D flip-flops in DigSim are positive-edge triggered. To change the state of the flip-flop,change the input when the clock is low, then bring the clock from low to high. The input tothe D flip-flop when the clock changes from low to high will be stored in the flip-flop.

Page 19: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

What to submit:

1. Make a copy of your truth-table and Karnaugh maps and submit the hard copy in class onTuesday, November 30.

2. Save your circuit as you did in the DigSim Assignment 1. Submit the circuit file using theUnix submit command as in previous assignments. The submission name for this assignmentis: digsim1. The UNIX command to do this should look something like:

submit cs313_0101 digsim2 a34.sim

Page 20: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Name:

Truth table:

m s2 s1 s0 x s′

2 s′

1 s′

0 z

0 0 0 0 0

1 0 0 0 1

2 0 0 1 0

3 0 0 1 1

4 0 1 0 0

5 0 1 0 1

6 0 1 1 0

7 0 1 1 1

8 1 0 0 0

9 1 0 0 1

10 1 0 1 0 d d d d

11 1 0 1 1 d d d d

12 1 1 0 0 d d d d

13 1 1 0 1 d d d d

14 1 1 1 0 d d d d

15 1 1 1 1 d d d d

Page 21: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

10

11

9

14

15

13

6

7

5

2

3

1

81240

00 01 11 10

00

01

11

10

s2 s1

s0 x 11s2

s1

x

s010

11

9

14

15

13

6

7

5

2

3

1

81240

00 01 11 10

00

01

11

10

s2 s1

s0 x 11s2

s1

x

s0

10

11

9

14

15

13

6

7

5

2

3

1

81240

00 01 11 10

00

01

11

10

s2 s1

s0 x 11s2

s1

x

s0 10

11

9

14

15

13

6

7

5

2

3

1

81240

00 01 11 10

00

01

11

10

s2 s1

s0 x 11s2

s1

x

s0

s2’ = s1’ =

s0’ = z =

Page 22: •J-K flip-flops •Edge-triggered flip-flops •Finite state ...chang/cs313.f04/topics/Slides22.pdf · J-K Flip-Flops •Allows both “set” and “reset” to be 1 •When both

Next Time

• designing finite state machines

UMBC, CMSC313, Richard Chang <[email protected]>


Recommended