Docsity

Sequential Logic Design - Controllers - Lecture Slides | ECGR 3181, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
1
Digital Design
Copyright © 2006
Frank Vahid
Digital Design
Chapter 3:
Sequential Logic Design -- Controllers
Slides to accompany the textbook Digital Design, First Edition,
by Frank Vahid, John Wiley and Sons Publishers, 2007.
http://www.ddvahid.com
Copyright © 2007 Frank Vahid
Instructors of courses requiring Vahid'sDigital Design textbook (published by John Wiley and Sons) havepermission to modify and use these slides for customary course-related activities,
subject to keeping this copyright notice in place and unmodified . These slides may be posted as unanimated pdf versions on publicly-accessible course websites.. PowerPoint source (or pdf
with animations) may not be posted to publicly-accessible websites, but may be posted for students on internal protected sites or distributed directly to students by other electronic means.
Instructors may make printouts of the slides available to students for a reasonable photocopying charge, without incurring royalties. Any other use requires explicit permission. Instructors
may obtain PowerPoint source or obtain special use permissions from Wiley –see http://www.ddvahid.com for information.
2
Digital Design
Copyright © 2006
Frank Vahid
Introduction
• Sequential circuit
– Output depends not just on present inputs (as in
combinational circuit), but on past sequence of inputs
• Stores bits, also known as having “state”
– Simple example: a circuit that counts up in binary
• In this chapter, we will:
– Design a new building block, a flip-flop, that stores
one bit
– Combine that block to build multi-bit storage – a
register
– Describe the sequential behavior using a finite state
machine
– Convert a finite state machine to a controller –a
sequential circuit having a register and combinational
logic
3.1
si
z
e
ansis
Combinational
digital circuit
1
a
b
1F
0
1
a
b?F
0
Must know
sequence of
past inputs to
know output
Sequential
digital circuit
Note: Slides with animation are denoted with a small red "a" near the animated items
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download Sequential Logic Design - Controllers - Lecture Slides | ECGR 3181 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Digital Design Copyright © 2006 Frank Vahid

Digital Design

Chapter 3:

Sequential Logic Design -- Controllers

Slides to accompany the textbook Digital Design , First Edition, by Frank Vahid, John Wiley and Sons Publishers, 2007. http://www.ddvahid.com

Copyright © 2007 Frank Vahid

Instructors of courses requiring Vahid's Digital Design textbook (published by John Wiley and Sons) have permission to modify and use these slides for customary course-related activities, subject to keeping this copyright notice in place and unmodified. These slides may be posted as unanimated pdf versions on publicly-accessible course websites.. PowerPoint source (or pdf with animations) may not be posted to publicly-accessible websites, but may be posted for students on internal protected sites or distributed directly to students by other electronic means. Instructors may make printouts of the slides available to students for a reasonable photocopying charge, without incurring royalties. Any other use requires explicit permission. Instructors may obtain PowerPoint source or obtain special use permissions from Wiley – see http://www.ddvahid.com for information.

Digital Design Copyright © 2006 Frank Vahid

Introduction

• Sequential circuit

  • Output depends not just on present inputs (as in

combinational circuit), but on past sequence of inputs

  • Stores bits, also known as having “state”
  • Simple example: a circuit that counts up in binary

• In this chapter, we will:

  • Design a new building block, a flip-flop , that stores

one bit

  • Combine that block to build multi-bit storage – a

register

  • Describe the sequential behavior using a finite state machine
  • Convert a finite state machine to a controller – a

sequential circuit having a register and combinational

logic

si

ze

ansis

Combinational digital circuit

a

b

0 F

a

b

0^?^ F

Must know sequence of past inputs to know output

Sequential digital circuit

Note: Slides with animation are denoted with a small red "a" near the animated items

Digital Design Copyright © 2006 Frank Vahid

Example Needing Bit Storage

  • Flight attendant call button
    • Press call: light turns on
      • Stays on after button released
    • Press cancel: light turns off
    • Logic gate circuit to implement this?

Call Q

Cancel

Doesn’t work. Q=1 when Call=1, but

doesn’t stay 1 when Call returns to 0

Need some form of “feedback” in the circuit

a

a

Bit Storage

Call Blue light button

Cancel button

1. Call button pressed – light turns on

Bit Storage

Call Blue light button Cancel button

2. Call button released – light stays on

Bit Storage

Call Blue light button

Cancel button

3. Cancel button pressed – light turns off

Digital Design Copyright © 2006 Frank Vahid

First attempt at Bit Storage

  • We need some sort of feedback
    • Does circuit on the right do what we want?
      • No: Once Q becomes 1 (when S=1), Q stays 1 forever – no value of S can bring Q back to 0

S Q

t

t

S 0 Q

0 1 0 1 0 1 0

Q

t

S

t

S 1 Q

t

S 1 Q

t

S 1 Q

1 t

0 Q

S (^1) a

Digital Design Copyright © 2006 Frank Vahid

Problem with SR Latch

  • Problem
    • If S=1 and R=1 simultaneously, we don’t know what value Q will take

R=

S=

t

Q

R=

S=

t

Q

R=

S=

t

Q

S

R

Q

t

t 0 1 Q 0

Q may oscillate. Then, because one path will be

slightly longer than the other, Q will eventually

settle to 1 or 0 – but we don’t know which.

Digital Design Copyright © 2006 Frank Vahid

Problem with SR Latch

  • Problem not just one of a user pressing two buttons at

same time

  • Can also occur even if SR inputs come from a circuit that

supposedly never sets S=1 and R=1 at same time

  • But does, due to different delays of different paths

X

Y

S

R

SR= 11

The longer path from X to R than to S causes SR=11 for short time – could be long enough to cause oscillation

Y^ R

X S^

SR latch

Q

Arbitrary circuit

Digital Design Copyright © 2006 Frank Vahid

Solution: Level-Sensitive SR Latch

  • Add enable input “C” as shown
    • Only let S and R change when C=
      • Enure circuit in front of SR never sets SR=11, except briefly due to path delays
    • Change C to 1 only after sufficient time for S and R to be stable
    • When C becomes 1, the stable S and R value passes through the two AND gates to the SR latch’s S1 R1 inputs.

R

S S

C

R

Level-sensitive SR latch

Q

Though SR=11 briefly...

...S1R1 never = 11

S C

Q’ Q R

Level-sensitive

SR latch symbol

R

S

S

X

Y

C

Clk

R

Level-sensitive SR latch

Q

0

1

0

1

S

R

C

S

R

1

a

Digital Design Copyright © 2006 Frank Vahid

Clock Signals for a Latch

  • How do we know when it’s safe to set C=1?
    • Most common solution –make C pulse up/down
      • C=0: Safe to change X, Y
      • C=1: Must not change X, Y
      • We’ll see how to ensure that later
    • Clock signal -- Pulsing signal used to enable latches - Because it ticks like a clock
    • Sequential circuit whose storage components all use clock signals: synchronous circuit - Most common type - Asynchronous circuits – important topic, but left for advanced course

R

S

S

X

Y

C

Clk

R

Q

Level-sensitive SR latch

Digital Design Copyright © 2006 Frank Vahid

Problem with Level-Sensitive D Latch

  • D latch still has problem (as does SR latch)
    • When C=1, through how many latches will a signal travel?
    • Depends on for how long C=
      • Clk_A -- signal may travel through multiple latches
      • Clk_B -- signal may travel through fewer latches
    • Hard to pick C that is just the right length
      • Can we design bit storage that only stores a value on the rising edge of a clock signal?

D1 Q1 D2 Q2 D3 Q3 D

C1 C2 C3 C

Y Q

Clk

Clk_A Clk_B

Clk

rising edges

Digital Design Copyright © 2006 Frank Vahid

D Flip-Flop

  • Flip-flop : Bit storage that stores on clock edge, not level
  • One design -- master-servant
    • Two latches, output of first goes to input of second, master latch has inverted clock signal
    • So master loaded when C=0, then servant when C=
    • When C changes from 0 to 1, master disabled, servant loaded with value that was at D just before C changed -- i.e., value at D during rising edge of C

Clk

D/Dm

Qm/Ds

Cm

Cs

Qs

Clk

rising edges

Note: Hundreds of different flip- flop designs exist

D latch

master

D latch

servant

D Dm Ds

Cs

Qm Qs’

Qs

Q

Q’

Cm

Clk

D flip-flop

Digital Design Copyright © 2006 Frank Vahid

D Flip-Flop

D Q’

Q

D Q’

Q

Symbol for rising-edge

triggered D flip-flop

Symbol for falling-edge

triggered D flip-flop

Clk

rising edges

Clk

falling edges

Internal design: Just invert servant clock rather than master

The triangle

means clock

input, edge

triggered

Digital Design Copyright © 2006 Frank Vahid

D Flip-Flop

  • Solves problem of not knowing through how many latches a signal

travels when C=

  • In figure below, signal travels through exactly one flip-flop, for Clk_A or Clk_B
  • Why? Because on rising edge of Clk, all four flip-flops are loaded simultaneously -- then all four no longer pay attention to their input, until the next rising edge. Doesn’t matter how long Clk is 1.

Two latches inside

each flip-flop

Y D1 Q1 D2 Q2 D3 Q3 D4 Q

Clk

Clk_A Clk_B

T w ol a tches

insideeach fli p

  • flop

Digital Design Copyright © 2006 Frank Vahid

Bit Storage Summary

  • We considered increasingly better bit storage until we

arrived at the robust D flip-flop bit storage

D flip-flop D latch

master

D latch

servant

DmQm Cm

D Ds

Clk

Qs’ Cs Qs

Q’

Q

S

R

D

Q

C

D latch

Feature: Only loads D value present at rising clock edge, so values can’t propagate to other flip-flops during same clock cycle. Tradeoff: uses more gates internally than D latch, and requires more external gates than SR – but gate count is less of an issue today.

Feature: SR can’t be 11 if D is stable before and while C=1, and will be 11 for only a brief glitch even if D changes while C=1. Problem: C=1 too long propagates new values through too many latches: too short may not enable a store.

S

R

S

Q

C

R

Level-sensitive SR latch

Feature: S and R only have effect when C=1. We can design outside circuit so SR=11 never happens when C=1. Problem: avoiding SR= can be a burden.

R (reset)

S (set)

Q

SR latch

Feature: S=1 sets Q to 1, R=1 resets Q to 0. Problem: SR=11 yield undefined Q.

Digital Design Copyright © 2006 Frank Vahid

Basic Register

  • Typically, we store multi-bit items
    • e.g., storing a 4-bit binary number
  • Register : multiple flip-flops sharing clock signal
    • From this point, we’ll use registers for bit storage
      • No need to think of latches or flip-flops
      • But now you know what’s inside a register

D

Q

D

Q

D

Q

D

Q

I3 I

Q3 Q2 Q1 Q

I1 I

clk

4-bit register

I3 I2 I1 I

Q3 Q2 Q1 Q

reg(4)

Digital Design Copyright © 2006 Frank Vahid

Example Using Registers: Temperature Display

  • Temperature history display
    • Sensor outputs temperature as 5-bit binary number
    • Timer pulses C every hour
    • Record temperature on each pulse, display last three recorded values

x4 a x x x

x

C

a3 a2 a1 a

tempe

ra

tu

re

sensor

timer

Display

Present

b4 b3 b2 b1 b

Display

TemperatureHistoryStorage

1 hour ago

c4 c3 c2 c1 c

Display

2 hours ago

(In practice, we would actually avoid connecting the timer output C to a clock input, instead only connecting an oscillator output to a clock input.)

Digital Design Copyright © 2006 Frank Vahid

Example Using Registers: Temperature Display

  • Use three 5-bit registers

x4...x0 21 21 22 24 24 24 25 25 26 26 26 27 27 27 27

C

Ra

Rb

Rc

Q

C

x x x x x

Q

Q

Q

Q

Ra Rb

I

I

I

I

I

Q

a4 a3 a2 a1 a

Q

Q

Q

Q

I

I

I

I

I

Rc

Q

b4 b3 b2 b1 b

Q

Q

Q

Q

I

I

I

I

I

c4 c3 c2 c1 c

TemperatureHistoryStorage

Digital Design Copyright © 2006 Frank Vahid

Describing Behavior of Sequential Circuit: FSM

  • Finite-State Machine (FSM)
    • A way to describe desired

behavior of sequential circuit

  • Akin to Boolean equations for combinational behavior
  • List states, and transitions

among states

  • Example: Make x change toggle (0 to 1, or 1 to 0) every clock cycle
  • Two states: “Off” (x=0), and “On” (x=1)
  • Transition from Off to On, or On to Off, on rising clock edge
  • Arrow with no starting state points to initial state (when circuit first starts)

Outputs: x

Off On

x=0 x=

clk^

clk^

Off On Off On Off On Off On

cycle 1

Off On Off On

cycle 2 cycle 3 cycle 4

clk

state

x

Outputs:

Digital Design Copyright © 2006 Frank Vahid

FSM Example: 0,1,1,1,repeat

  • Want 0, 1, 1, 1, 0, 1, 1, 1, ...
    • Each value for one clock cycle
  • Can describe as FSM
    • Four states
    • Transition on rising clock

edge to next state

Off On1On2 On3 OffOn1On2On3Off

clk

x

State

Outputs:

Outputs: x

Off On1 On2 On

clk^

clk^

x=0 clk^ x=1 x=1 clk^ x=

Digital Design Copyright © 2006 Frank Vahid

Extend FSM to Three-Cycles High Laser Timer

  • Four states
  • Wait in “Off” state while b is

0 (b’)

  • When b is 1 (and rising

clock edge), transition to

On

  • Sets x=
  • On next two clock edges,

transition to On2, then On3,

which also set x=

  • So x=1 for three cycles after

button pressed

Off Off Off Off OffOn1On2 On3Off

clk

State

Outputs:

Inputs:

x

b

On1 On2 On

Off

clk^

clk^

x=1 x=1 x=

x=

clk^

b’*clk^

b*clk ^

Inputs: b; Outputs: x

Digital Design Copyright © 2006 Frank Vahid

FSM Simplification: Rising Clock Edges Implicit

  • Showing rising clock on every

transition: cluttered

  • Make implicit -- assume every

edge has rising clock, even if not

shown

  • What if we wanted a transition

without a rising edge

  • We don’t consider such asynchronous FSMs -- less

common, and advanced topic

  • Only consider synchronous

FSMs -- rising edge on every

transition

Note: Transition with no associated condition thus transistions to next state on next clock cycle

On1 On2 On

Off

x=1 x=1 x=

x=

b’

b

Inputs: b; Outputs: x

On1 On2 On

Off

x=1 x=1 x=

x=

b’

clk^

clk^

clk^

*clk^

b*clk ^

Inputs: b; Outputs: x

a

Digital Design Copyright © 2006 Frank Vahid

FSM Example: Secure Car Key (cont.)

  • Nice feature of FSM
    • Can evaluate output behavior

for different input sequence

  • Timing diagrams show states

and output values for different

input waveforms

K1 K2 K3 K

r=1 r=1 r=0 r=

Wait r=

Inputs: a; Outputs: r

a a’

Wait Wait K1 K2 K3 K4 Wait Wait

clk

Inputs

Outputs

State

a

r

clk Inputs a

Wait Wait K1 K2 K3 K4 WaitK

Output

State

r

Q: Determine states and r value for

given input waveform:

a

Digital Design Copyright © 2006 Frank Vahid

FSM Example: Code Detector

  • Unlock door (u=1) only when

buttons pressed in sequence:

  • start, then red, blue, green, red
  • Input from each button: s, r, g, b
  • Also, output a indicates that some colored button pressed
  • FSM
  • Wait for start (s=1) in “Wait”
  • Once started (“Start”)
  • If see red, go to “Red1”
  • Then, if see blue, go to “Blue”
  • Then, if see green, go to “Green”
  • Then, if see red, go to “Red2”
  • In that state, open the door

(u=1)

  • Wrong button at any step, return to “Wait”, without opening door

Start

Red

Green

Blue

s

r

g

b

a

Door

lock

u

Code

detector

Q: Can you trick this FSM to open the door, without knowing the code?

A: Yes, hold all buttons simultaneously

a

a

a

Wait

Start

Red1 Blue Green Red

s’

a’

ar’ ab’ ag’ ar’

a’

ab ag^ ar

a’ a’

u=

u=

ar

u=0 s

u=0 u=0 u=

Inputs: s,r,g,b,a;

Outputs: u

Digital Design Copyright © 2006 Frank Vahid

Improve FSM for Code Detector

  • New transition conditions detect if wrong button pressed, returns to “Wait”
  • FSM provides formal, concrete means to accurately define desired behavior

Note: small problem still remains; we’ll discuss later

Wait

Start

Red1 Blue Green Red

s’

a’

a’

ab ag^ ar

a’ a’ u=

u= ar

u= s

u=0 u=0 u=

ar’ ab’ ag’ ar’ (^) a

Inputs: s,r,g,b,a;

Outputs: u

Digital Design Copyright © 2006 Frank Vahid

Standard Controller Architecture

  • How implement FSM as sequential

circuit?

  • Use standard architecture
    • State register -- to store the present state
    • Combinational logic -- to compute outputs, and next state
    • For laser timer FSM
      • 2-bit state register, can represent four

states

  • Input b, output x
  • Known as controller

a

On1 On2 On

Off

x=1 x=1 x=

x=

b’

b

Inputs: b; Outputs: x

Combinational logic

State register

s1 s

n

n

b x

clk

FSM

outputs

FSMinputs FSM outputs

General version

Combinational

logic

S

m

m

N

I O

clk

m-bit state register

FSM

outputs

FSMinputs

Digital Design Copyright © 2006 Frank Vahid

Controller Design: Laser Timer Example (cont)

  • Step 4: Create state table

x=1 x=1 x=

x=

b

b’

On1 10 On2 11

Off

On

Inputs: b; Outputs: x

Combinational logic

State register

s1 s

n

n

b x

clk

FSMinputs

FSM

outputs

a

Digital Design Copyright © 2006 Frank Vahid

Controller Design: Laser Timer Example (cont)

  • Step 5: Implement

combinational logic

Combinational logic

State register

s1 s

n

n

b x

clk

FSMinputs

FSM

outputs

a

x = s1 + s0 (note from the table that x=1 if s1 = 1 or s

n1 = s1’s0b’ + s1’s0b + s1s0’b’ + s1s0’b

n1 = s1’s0 + s1s0’

n0 = s1’s0’b + s1s0’b’ + s1s0’b

n0 = s1’s0’b + s1s0’

Digital Design Copyright © 2006 Frank Vahid

Controller Design: Laser Timer Example (cont)

  • Step 5: Implement

combinational logic (cont)

a

x = s1 + s

n1 = s1’s0 + s1s0’

n0 = s1’s0’b + s1s0’

Combinational logic

State register

s1 s

n

n

b x

clk

FSMinputs

FSM

outputs

n

n

s1 s

clk

Combinational Logic

State register

b

FSMoutputs

FSMinputs

x

Digital Design Copyright © 2006 Frank Vahid

Understanding the Controller’s Behavior

s1 s

b (^) x

n

n

x=1 x=1 x=

b

(^01) On1 (^10) On2 11

Off

On

00

b’

x=

clk

clk

Inputs:

Outputs:

b

s1 s

b (^) x

n

n

x=1 x=1 x=

b’

(^01) On1 (^10) On2 11

Off

On

clk

b

x

00

x=

state=00 state=

s1 s

b (^) x

n

n

x=1 x=1 x=

x=

b

b’

01

00

On1^10 On2^11

Off

On

clk 0 1 1 0

state=

a