computer organization and design memories and state machines montek singh wed, nov 6-11, 2013...

40
Computer Organization and Computer Organization and Design Design Memories and State Machines Memories and State Machines Montek Singh Montek Singh Wed, Nov 6-11, 2013 Wed, Nov 6-11, 2013 Lecture 13 Lecture 13

Upload: gillian-lamb

Post on 19-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Computer Organization and Computer Organization and DesignDesign

Memories and State MachinesMemories and State Machines

Montek SinghMontek Singh

Wed, Nov 6-11, 2013Wed, Nov 6-11, 2013

Lecture 13Lecture 13

Page 2: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

TopicsTopics Memory ArraysMemory Arrays Transparent LatchesTransparent Latches Edge-triggered RegistersEdge-triggered Registers Finite State MachinesFinite State Machines

Page 3: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Memory as a Lookup TableMemory as a Lookup Table

A multiplexer to implement a lookup table:A multiplexer to implement a lookup table: Remember that, in theory, we can build any 1-output Remember that, in theory, we can build any 1-output

combinational logic block with multiplexerscombinational logic block with multiplexers For an N-input function we need a 2For an N-input function we need a 2NN input multiplexer input multiplexer

BIG Multiplexers?BIG Multiplexers? How about 10-input function? 20-input?How about 10-input function? 20-input?

MUXLogic

A B

Fn(A,B)

AB Fn(A,B)

00 0 01 1 10 1 11 0

Page 4: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

A MuxA Mux’’s Gutss Guts

Hmmm, by sharing the decoder part of the logic MUXs could be adapted to make lookup tables with any number of outputs

I 00

I 01

I 10

I 11

AB

AB

AB

AB

Y

Decoder Selector Multiplexerscan be

partitionedinto two sections.

A DECODER thatidentifies the

desired input,and

a SELECTOR that enables that

inputonto the output.

A decodergeneratesall possible

productterms fora set ofinputs

0

1

2

3

Page 5: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

A New Combinational DeviceA New Combinational Device

k

D1D2

DN

DECODER:

k SELECT inputs,

N = 2k DATA OUTPUTs.

Selected Dj HIGH; all others LOW.

NOW, we are well on our way to building a general purpose table-lookup device.

We can build a 2-dimensional ARRAY of decoders and selectors as follows ...

Page 6: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Shared Decoding LogicShared Decoding Logic

We can build a general purpose “table-lookup” device called a Read-Only Memory (ROM), from which we can implement any truth table and, thus, any combinational device

Page 7: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Logic According to ROMsLogic According to ROMs ROMs ignore the structure of combinational ROMs ignore the structure of combinational

functions ...functions ... Size, layout, and design are independent of functionSize, layout, and design are independent of function Any Truth table can be Any Truth table can be ““programmedprogrammed”” by minor by minor

reconfiguration:reconfiguration:Metal layer (masked ROMs)Metal layer (masked ROMs)Fuses (Field-programmable PROMs)Fuses (Field-programmable PROMs)Charge on floating gates (EPROMs)Charge on floating gates (EPROMs) ... etc.... etc.

Model: LOOK UP value of function in truth Model: LOOK UP value of function in truth table...table... Inputs: Inputs: ““ADDRESSADDRESS”” of a T.T. entry of a T.T. entry ROM SIZE = # TT entries...ROM SIZE = # TT entries...

... for an N-input boolean function, size = __________... for an N-input boolean function, size = __________

2N x #outputs

Page 8: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Analog Storage: Using CapacitorsAnalog Storage: Using Capacitors WeWe’’ve chosen to encode information using voltages ve chosen to encode information using voltages

and we know from physics that we can and we know from physics that we can ““storestore”” a a voltage as voltage as ““chargecharge”” on a capacitor on a capacitor

Pros:Pros:compact!compact!

Cons:Cons: it leaks! refreshit leaks! refreshcomplex interfacecomplex interface reading a bit, destroys reading a bit, destroys

itit– (you have to rewrite (you have to rewrite

the value after each the value after each read)read)

itit’’s NOT a digital circuits NOT a digital circuit

bit line

N-channel FET serves

as an access switch

VREF

To write: Drive bit line, turn on access fet, force storage cap to new voltageTo read: precharge bit line, turn on access fet, detect (small) change in bit line voltage

wordline

This storage circuit is the basis for commodity DRAMs

Page 9: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Y

S

B

A A ““DigitalDigital”” Storage Element Storage Element ItIt’’s also easy to build a settable DIGITAL s also easy to build a settable DIGITAL

storage element (called a latch) using a MUX storage element (called a latch) using a MUX and FEEDBACK:and FEEDBACK:

0

1

G

0011

D

----01

QIN

01----

QOUT

0101

Q follows D

Q stable

“state” signalappears as bothinput and output

A

D

G

Q

Here’s a feedback path,so it’s no longer acombinational circuit.

Page 10: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Static D LatchStatic D Latch

G

D Q

D

G

Q stable

Q follows D

Positive latch

Q

“static” means latch will hold data (i.e., value of Q) while G is inactive, however long that may be.

G

D Q

Negative latch

Q

G

D

1

0

Page 11: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Latch TimingLatch Timing Circuits with memory must follow some rulesCircuits with memory must follow some rules

Guarantee that inputs to sequential devices are valid Guarantee that inputs to sequential devices are valid and stable during periods when they may influence and stable during periods when they may influence state changesstate changesThis is assured with additional timing specificationsThis is assured with additional timing specifications

G

D

>tPULSE

tPULSE (minimum pulse width): guarantee G is active for long enough for latch to capture data

>tSETUP

tSETUP (setup time): guarantee that D value has propagated through feedback path before latch becomes opaque

>tHOLD

tHOLD (hold time): guarantee latch is opaque and Q is stable before allowing D to change again

Page 12: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Flakey Control SystemsFlakey Control Systems

Here’s a strategy for saving 2 bucks the next time you find yourself at a toll booth!

Page 13: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Flakey Control SystemsFlakey Control Systems

Here’s a strategy for saving 2 bucks the next time you find yourself at a toll booth!

Page 14: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Flakey Control SystemsFlakey Control Systems

WARNING:Professional Drivers Used!

DON’T try thisAt home!

Here’s a strategy for saving 2 bucks the next time you find yourself at a toll booth!

Page 15: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time.

Page 16: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time.

Page 17: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time.

Page 18: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 19: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 20: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 21: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 22: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time.

Page 23: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time.

Page 24: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 25: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 26: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 27: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Page 28: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time.

Page 29: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time.

Page 30: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Escapement StrategyEscapement Strategy

The Solution: Add two gates and only open one at a time. (Psst… Don’t tell the toll folks)

Key Idea: At no time is there an open path through both gates…

Page 31: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

G

D Q

G

D Q

Edge-triggered Flip FlopEdge-triggered Flip Flop

Logical Logical ““escapementescapement””:: Double-gated toll booth built using logic gatesDouble-gated toll booth built using logic gates

Observations:Observations: only one latch only one latch ““transparenttransparent”” at any time: at any time:

master closed when slave is open (CLK is high)master closed when slave is open (CLK is high)slave closed when master is open (CLK is low)slave closed when master is open (CLK is low)no combinational path all the way through flip flopno combinational path all the way through flip flop

Q only changes shortly after 0 Q only changes shortly after 0 1 1 transition transition of CLK, so of CLK, so flip flop appears to be flip flop appears to be ““triggeredtriggered”” by rising edge of by rising edge of CLKCLK

D QD

CLK

Q D

CLK

Qmaster slav

e

Transitions mark instants, not

intervals

Page 32: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Flip Flop WaveformsFlip Flop Waveforms

G

D Q

G

D Q D QD

CLK

Q D

CLK

Qmaster slav

e

D

CLK

Q

master closedslave open

slave closedmaster open

Page 33: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Flip Flop TimingFlip Flop Timing

CLK

D

QD QD

CLK

Q<tPD

tPD: maximum propagation delay, CLK Q >tSETUP

tSETUP: setup timeguarantee that D has propagated through feedback path before master closes

>tHOLD

tHOLD: hold timeguarantee master is closed and data is stable before allowing D to change

Page 34: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Synchronous SystemsSynchronous Systems

Designing digital systems using a clockDesigning digital systems using a clock

Page 35: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Synchronous SystemsSynchronous Systems

FlipflopCombinational

logicFlipflop

leading

edge

trailing

edge

On the leading edge of the clock, the input of a flipflop is transferred to the output and held.

We must be sure the output of the combinational logic has settled before the next leading clock edge.

Clock

data

Clock period must be “long enough”Clock Period >= tFF + tlogic + tsetup

Page 36: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Finite State MachinesFinite State Machines What is a State Machine?What is a State Machine?

Remember automata?Remember automata?

It is defined by the following:It is defined by the following:Set of STATESSet of STATESSet of INPUTSSet of INPUTSSet of OUTPUTSSet of OUTPUTSA mapping from (STATES, INPUTS) to …A mapping from (STATES, INPUTS) to …

… … the next STATE and an OUTPUTthe next STATE and an OUTPUT

STATE represents memory!STATE represents memory!

Page 37: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Implementing an FSMImplementing an FSM Use flipflops to represent state (i.e., memory)Use flipflops to represent state (i.e., memory) Use combinational logic to compute:Use combinational logic to compute:

output as a function of inputs + stateoutput as a function of inputs + state next state as a function of inputs + statenext state as a function of inputs + state

State(flipflops)

Function

(comb. logic)

Inputs Outputs

Clock

Page 38: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Example: Traffic Light ControllerExample: Traffic Light Controller 4 states4 states

each corresponding to a each corresponding to a circlecircle

represent states using 2 represent states using 2 bitsbits00, 01, 10, 1100, 01, 10, 11

4 bits of output4 bits of output 2 bits for east/west light2 bits for east/west light 2 bits for north/south light2 bits for north/south light

Red (00)Red (00)Yellow (01)Yellow (01)Green (10)Green (10)

G E/W

R N/S

Y E/W

R N/S

R E/W

G N/S

R E/W

Y N/S

Page 39: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

Example: Traffic Light ControllerExample: Traffic Light Controller 4 states4 states

00, 01, 10, 1100, 01, 10, 11need 2 flipflops to need 2 flipflops to

represent staterepresent state

4 bits of output4 bits of outputR (00), Y (01), G (10)R (00), Y (01), G (10)

Truth table:Truth table: this defines the this defines the

combinational logic part of combinational logic part of the FSMthe FSM

G E/W

R N/S

Y E/W

R N/S

R E/W

G N/S

R E/W

Y N/S

Input (State) Output Next State

00 10 00 01

01 01 00 10

10 00 10 11

11 00 01 00

Page 40: Computer Organization and Design Memories and State Machines Montek Singh Wed, Nov 6-11, 2013 Lecture 13

SummarySummary Regular Arrays can be used to implement Regular Arrays can be used to implement

arbitrary logic functions arbitrary logic functions MemoriesMemories

ROMs are HARDWIRED memoriesROMs are HARDWIRED memories RAMs include storage elements that are read-writeRAMs include storage elements that are read-write

dynamic memory: compact, only reliable short-termdynamic memory: compact, only reliable short-termstatic memory: controlled use of positive feedbackstatic memory: controlled use of positive feedback

For static storage:For static storage: Level-sensitive D-latches; edge-triggered flipflopsLevel-sensitive D-latches; edge-triggered flipflops Timing issues: setup and hold timesTiming issues: setup and hold times

Finite State Machines:Finite State Machines: Implement using flipflops for memory, and Implement using flipflops for memory, and

combinational logic to compute output, next statecombinational logic to compute output, next state