Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation:...

24
{0, 1}

Transcript of Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation:...

Page 1: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Combinational Logic

Multiple levels of representation:

• Logic equations

• Truth tables

• Gate diagrams

• Switching circuits

Boolean algebra: tool to manipulate logic equations

An algebra on a set of two elements: {0,1}

Operations: AND, OR, complement

Page 2: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Boolean Algebra

Identities:

0a = 0 1a = a aa = a aa = 00 + a = a 1 + a = 1 a+ a = a a+ a = 1

ab = ba a(bc) = (ab)ca+ b = b+ a a+ (b+ c) = (a+ b) + c

a(b+ c) = ab+ ac a+ (bc) = (a+ b)(a+ c)

(a+ b) = ab (ab) = a+ b

Precedence: AND takes precedence over OR.

Page 3: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Proving Logic Equations

Example: (a+ b)(a+ c) = a+ bc

Algebraic proof?

Proof with Truth Tables:

a b c a+ b a+ c LHS bc RHS0 0 0 0 0 0 0 00 0 1 0 1 0 0 00 1 0 1 0 0 0 00 1 1 1 1 1 1 11 0 0 1 1 1 0 11 0 1 1 1 1 0 11 1 0 1 1 1 0 11 1 1 1 1 1 1 1

Page 4: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Truth Tables To Logic Equations

a b c out Minterms Maxterms

0 0 0 0 abc a+ b+ c0 0 1 1 abc a+ b+ c0 1 0 1 abc a+ b+ c0 1 1 0 abc a+ b+ c1 0 0 1 abc a+ b+ c1 0 1 1 abc a+ b+ c1 1 0 0 abc a+ b+ c1 1 1 0 abc a+ b+ c

Sum of Products: abc+ abc+ abc+ abc

Product of Sums:(a+ b+ c)(a+ b+ c)(a+ b+ c)(a+ b+ c)

Page 5: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Universality: NAND and NOR

==

= =

Universal: can implement any combinational functionusing just NAND or just NOR gates.

Page 6: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Minimizing Logic Equations

Earlier example:

abc+ abc+ abc+ abc︸ ︷︷ ︸ab(c+ c) = ab

One can use Boolean algebra to simplify equations.

Systematic techniques:

• Karnaugh maps

• Quine-McCluskey

(details in section next week)

Page 7: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Word Problems

"Increment input by 1, compute result mod 5"

Representation: 3-bit binary input

I2 I1 I0 O2 O1 O0Input = 0 0 0 0 0 0 1Input = 1 0 0 1 0 1 0Input = 2 0 1 0 0 1 1Input = 3 0 1 1 1 0 0Input = 4 1 0 0 0 0 0Input = 5 1 0 1 0 0 1Input = 6 1 1 0 0 1 0Input = 7 1 1 1 0 1 1

Page 8: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Don't Cares

Given: the input is always between 0 and 4:

I2 I1 I0 O2 O1 O0Input = 0 0 0 0 0 0 1Input = 1 0 0 1 0 1 0Input = 2 0 1 0 0 1 1Input = 3 0 1 1 1 0 0Input = 4 1 0 0 0 0 0Input = 5 1 0 1 X X XInput = 6 1 1 0 X X XInput = 7 1 1 1 X X X

Can be used to simplify logic equations.

Page 9: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

What If I Want to Keep Counting?

add 1

mod 5

What happens?

Page 10: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Sequential Circuits

Need a way to sequence operations.

Idea:

• Introduce devices that can hold statecalled state-holding elements

• Read stable inputs from state-holding elements

• Write stable outputs to state-holding elements

• Generate outputs from inputs usingcombinational logic

Page 11: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Bi-Stable Devices

Part I: state-holding devices

A simple device:

stable state

1

1 0

stable state

BA

0

In a stable state, A = B

• How do we change the state?

Page 12: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

SR Latch

=S

R

Q

Q S

R

Q

Q

S R Q Q

0 0 Q Q0 1 0 11 0 1 01 1 ? ?

• SR Latch (set-reset)• Q: stored value• Q: complement• S = 1 and R = 1?

Page 13: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

D Latch

=

Q

Q

D S

R

D

Q

QD

Q

S

R

QD

=

• When D changes, Q changes...

... immediately.

Need to control when the output changes.

Page 14: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Clocks

Part II: modifying state-holding elements

Introduce a free-running signal: the clock

Clock signal has a �xed cycle time (a.k.a. cycleperiod).Clock frequency = 1/cycle time

clock

clock period

high

edgerising

fallingedge

clock low

Page 15: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Edge Triggered Clocking

state−holding element

state−holding elementif outputs change here, negative edge−triggered

if outputs change here, positive edge−triggered

• Inputs must be stable just before the clock edgewhere the outputs change.

Lots of other choices... (EE 438)

Page 16: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

First Attempt

D

Q

S

R

Q=

Q

Q

QD

CLK

=

Q

D

CLK

• How does the output behave?

CLK

Q

D

Page 17: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Master-Slave Flip-Flop

bubble => negative−edge triggered

X

FF=Q

QD

Q

QD

Q

QDD

CLK

Q

Q

CLK

Q

X

D

Page 18: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Example: 1-Bit Counter

Truth-table:in out0 11 0

Circuit:

Q

QDFF

combinationallogic

CLK

inout

CLK

Page 19: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Finite State Machines

Basic Idea: A circuit has

• External inputs• Externally visible outputs• Internal state

Output and next state depend on:

• Inputs• Current State

Two types:

• Mealy: output is a function of state and input

• Moore: output is a function of state only

Page 20: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Designing a Finite-State Machine

• Draw a state diagram

• Write down state transition table

• State assignment

• Determine logic equations for all �ip-�ops andoutputs

Example: add two input bit-streams(least-signi�cant-bit �rst).

0

0 1 1 0

0 1 1 1 1

1111

serialadder

0 0 1 0 1

0 0 1 0 1

+1 0 1 1 0

1

Page 21: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

The Serial Adder

• Two states: S0 (carry is zero), S1 (carry is 1)

• Inputs: a and b• Output: z

11/1with input vectorand outputab/z

S1S011/0

10/1, 01/1

00/0

00/1

01/0, 10/0

Arcs labelled

Page 22: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

State Table

a b state z next state0 0 S0 0 S00 1 S0 1 S01 0 S0 1 S01 1 S0 0 S10 0 S1 1 S00 1 S1 0 S11 0 S1 0 S11 1 S1 1 S1

For each input combination and state combination,

write down output and next state.

Page 23: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

State Assignment

Pick encoding of states. We have two states, so useone bit s.

• S0: s = 0, S1: s = 1

a b s z s′

0 0 0 0 0 abs0 1 0 1 0 abs1 0 0 1 0 abs1 1 0 0 1 abs0 0 1 1 0 abs0 1 1 0 1 abs1 0 1 0 1 abs1 1 1 1 1 abs

Page 24: Combinational Logic - Cornell University · Combinational Logic Multiple levels of representation: Logic equations Truth tables Gate diagrams Switching circuits Boolean algebra: tool

Logic Equations and Circuit

z = abs+ abs+ abs+ abs

s′ = abs+ abs+ abs+ abs = ab+ bs+ as

z

Q

QDFF

CLK

logiccombinational

a

b

ss’

What's the clock period?