Скачать презентацию

Идет загрузка презентации. Пожалуйста, подождите

Презентация была опубликована год назад пользователемФёдор Грамотин

1 CS Fall Sequential Logic Examples - 1 Sequential Logic Examples zFinite State Machine Concept yFSMs are the decision making logic of digital designs yPartitioning designs into datapath and control elements yWhen inputs are sampled and outputs asserted zBasic Design Approach: 4-step Design Process zImplementation Examples and Case Studies yFinite-string pattern recognizer yComplex counter yTraffic light controller yDoor combination lock

2 CS Fall Sequential Logic Examples - 2 General FSM Design Procedure z(1) Determine inputs and outputs z(2) Determine possible states of machine y– State minimization z(3) Encode states and outputs into a binary code y– State assignment or state encoding y– Output encoding y– Possibly input encoding (if under our control) z(4) Realize logic to implement functions for states and outputs y– Combinational logic implementation and optimization y– Choices in steps 2 and 3 have large effect on resulting logic

3 CS Fall Sequential Logic Examples - 3 Finite String Pattern Recognizer (Step 1) zFinite String Pattern Recognizer yOne input (X) and one output (Z) yOutput is asserted whenever the input sequence …010… has been observed, as long as the sequence 100 has never been seen zStep 1: Understanding the Problem Statement ySample input/output behavior: X: … Z: … X: … Z: …

4 CS Fall Sequential Logic Examples - 4 Finite String Pattern Recognizer (Step 2) zStep 2: Draw State Diagram yFor the strings that must be recognized, i.e., 010 and 100 yMoore implementation S1 [0] S2 [0] 0 1 S3 [1] 0 S4 [0] 1 0 or 1 S5 [0] 0 0 S6 [0] S0 [0] reset

5 CS Fall Sequential Logic Examples - 5 Finite String Pattern Recognizer (Step 2, contd) zExit conditions from state S3: have recognized …010 yIf next input is 0 then have …0100 = (state S6) yIf next input is 1 then have …0101 = …01 (state S2) S4 [0] S1 [0] S0 [0] S2 [0] 10 1 reset 0 or 1 S3 [1] 0 S5 [0] 0 0 S6 [0] Exit conditions from S1: recognizes strings of form …0 (no 1 seen); loop back to S1 if input is 0 Exit conditions from S4: recognizes strings of form …1 (no 0 seen); loop back to S4 if input is

6 CS Fall Sequential Logic Examples - 6 Finite String Pattern Recognizer (Step 2, contd) zS2 and S5 still have incomplete transitions yS2 = …01; If next input is 1, then string could be prefix of (01)1(00) S4 handles just this case yS5 = …10; If next input is 1, then string could be prefix of (10)1(0) S2 handles just this case zReuse states as much as possible yLook for same meaning yState minimization leads to smaller number of bits to represent states zOnce all states have complete set of transitions we have final state diagram S4 [0] S1 [0] S0 [0] S2 [0] 10 1 reset 0 or 1 S3 [1] 0 S5 [0] 0 0 S6 [0]

7 CS Fall Sequential Logic Examples - 7 module string (clk, X, rst, Q0, Q1, Q2, Z); input clk, X, rst; output Q0, Q1, Q2, Z; reg state[0:2]; define S0 = [0,0,0]; //reset state define S1 = [0,0,1]; //strings ending in...0 define S2 = [0,1,0]; //strings ending in...01 define S3 = [0,1,1]; //strings ending in define S4 = [1,0,0]; //strings ending in...1 define S5 = [1,0,1]; //strings ending in...10 define S6 = [1,1,0]; //strings ending in assign Q0 = state[0]; assign Q1 = state[1]; assign Q2 = state[2]; assign Z = (state == S3); clk) begin if rst state = S0; else case (state) S0: if (X) state = S4 else state = S1; S1: if (X) state = S2 else state = S1; S2: if (X) state = S4 else state = S3; S3: if (X) state = S2 else state = S6; S4: if (X) state = S4 else state = S5; S5: if (X) state = S2 else state = S6; S6: state = S6; default: begin $display (invalid state reached); state = 3bxxx; endcase end endmodule Finite String Pattern Recognizer (Step 3) zVerilog description including state assignment (or state encoding)

8 CS Fall Sequential Logic Examples - 8 Finite String Pattern Recognizer zReview of Process yUnderstanding problem xWrite down sample inputs and outputs to understand specification yDerive a state diagram xWrite down sequences of states and transitions for sequences to be recognized yMinimize number of states xAdd missing transitions; reuse states as much as possible yState assignment or encoding xEncode states with unique patterns ySimulate realization xVerify I/O behavior of your state diagram to ensure it matches specification

9 CS Fall Sequential Logic Examples - 9 Mode Input M Current State Next State Complex Counter zSynchronous 3-bit counter has a mode control M yWhen M = 0, the counter counts up in the binary sequence yWhen M = 1, the counter advances through the Gray code sequence binary: 000, 001, 010, 011, 100, 101, 110, 111 Gray: 000, 001, 011, 010, 110, 111, 101, 100 zValid I/O behavior (partial)

10 CS Fall Sequential Logic Examples - 10 Complex Counter (State Diagram) zDeriving State Diagram yOne state for each output combination yAdd appropriate arcs for the mode control S0 [000] S1 [001] S2 [010] S3 [011] S4 [100] S5 [101] S6 [110] S7 [111] reset

11 CS Fall Sequential Logic Examples - 11 Complex Counter (State Encoding) zVerilog description including state encoding module string (clk, M, rst, Z0, Z1, Z2); input clk, X, rst; output Z0, Z1, Z2; reg state[0:2]; define S0 = [0,0,0]; define S1 = [0,0,1]; define S2 = [0,1,0]; define S3 = [0,1,1]; define S4 = [1,0,0]; define S5 = [1,0,1]; define S6 = [1,1,0]; define S7 = [1,1,1]; assign Z0 = state[0]; assign Z1 = state[1]; assign Z2 = state[2]; clk) begin if rst state = S0; else case (state) S0: state = S1; S1: if (M) state = S3 else state = S2; S2: if (M) state = S6 else state = S3; S3: if (M) state = S2 else state = S4; S4: if (M) state = S0 else state = S5; S5: if (M) state = S4 else state = S6; S5: if (M) state = S7 else state = S7; S5: if (M) state = S5 else state = S0; endcase end endmodule

12 CS Fall Sequential Logic Examples - 12 TS/ST S1 TS' –/ST S1a S1b S1c traffic light controller timer TLTS ST Traffic Light Controller as Two Communicating FSMs zWithout Separate Timer yS0 would require 7 states yS1 would require 3 states yS2 would require 7 states yS3 would require 3 states yS1 and S3 have simple transformation yS0 and S2 would require many more arcs xC could change in any of seven states zBy Factoring Out Timer yGreatly reduce number of states x4 instead of 20 yCounter only requires seven or eight states x12 total instead of 20

13 CS Fall Sequential Logic Examples - 13 machines advance in lock step initial inputs/outputs: X = 0, Y = 0 CLK FSM1 X FSM2 Y AAB CDD FSM 1FSM 2 X Y Y==1 A [1] Y==0 B [0] Y==0 X==1 C [0] X==0 D [1] X==1 X==0 Communicating Finite State Machines zOne machine's output is another machine's input

14 CS Fall Sequential Logic Examples - 14 "puppet" "puppeteer who pulls the strings" control data-path status info and inputs control signal outputs state Datapath and Control zDigital hardware systems = data-path + control yDatapath: registers, counters, combinational functional units (e.g., ALU), communication (e.g., busses) yControl: FSM generating sequences of control signals that instructs datapath what to do next

15 CS Fall Sequential Logic Examples - 15 Digital Combinational Lock zDoor Combination Lock: yPunch in 3 values in sequence and the door opens; if there is an error the lock must be reset; once the door opens the lock must be reset yInputs: sequence of input values, reset yOutputs: door open/close yMemory: must remember combination or always have it available yOpen questions: how do you set the internal combination? xStored in registers (how loaded?) xHardwired via switches set by user

16 CS Fall Sequential Logic Examples - 16 Implementation in Software integer combination_lock ( ) { integer v1, v2, v3; integer error = 0; static integer c[3] = 3, 4, 2; while (!new_value( )); v1 = read_value( ); if (v1 != c[1]) then error = 1; while (!new_value( )); v2 = read_value( ); if (v2 != c[2]) then error = 1; while (!new_value( )); v3 = read_value( ); if (v2 != c[3]) then error = 1; if (error == 1) then return(0); else return (1); }

17 CS Fall Sequential Logic Examples - 17 resetvalue open/closed new clock Determining Details of the Specification zHow many bits per input value? zHow many values in sequence? zHow do we know a new input value is entered? zWhat are the states and state transitions of the system?

18 CS Fall Sequential Logic Examples - 18 Digital Combination Lock State Diagram zStates: 5 states yRepresent point in execution of machine yEach state has outputs zTransitions: 6 from state to state, 5 self transitions, 1 global yChanges of state occur when clock says its ok yBased on value of inputs zInputs: reset, new, results of comparisons zOutput: open/closed closed C1==value & new C2==value & new C3==value & new C1!=value & new C2!=value & new C3!=value & new closed reset not new S1S2S3OPEN ERR open

19 CS Fall Sequential Logic Examples - 19 reset open/closed new C1C2C3 comparator value equal multiplexer controller mux control clock Datapath and Control Structure zDatapath yStorage registers for combination values yMultiplexer yComparator zControl yFinite-state machine controller yControl for data-path (which value to compare)

20 CS Fall Sequential Logic Examples - 20 State Table for Combination Lock zFinite-State Machine yRefine state diagram to take internal structure into account yState table ready for encoding resetnewequalstatestatemuxopen/closed 1–––S1C1closed 00–S1S1C1closed 010S1ERR–closed 011S1S2C2closed S3OPEN–open... next

21 CS Fall Sequential Logic Examples - 21 resetnewequalstatestatemuxopen/closed 1––– – – –1... next mux is identical to last 3 bits of state open/closed is identical to first bit of state therefore, we do not even need to implement FFs to hold state, just use outputs reset open/closed new equal controller mux control clock Encodings for Combination Lock zEncode state table yState can be: S1, S2, S3, OPEN, or ERR xNeeds at least 3 bits to encode: 000, 001, 010, 011, 100 xAnd as many as 5: 00001, 00010, 00100, 01000, xChoose 4 bits: 0001, 0010, 0100, 1000, 0000 yOutput mux can be: C1, C2, or C3 xNeeds 2 to 3 bits to encode xChoose 3 bits: 001, 010, 100 yOutput open/closed can be: open or closed xNeeds 1 or 2 bits to encode xChoose 1 bit: 1, 0

22 CS Fall Sequential Logic Examples - 22 C1C2C3 comparator equal multiplexer mux control value C1iC2iC3i mux control value equal Datapath Implementation for Combination Lock zMultiplexer yEasy to implement as combinational logic when few inputs yLogic can easily get too big for most PLDs

23 CS Fall Sequential Logic Examples - 23 C1C2C3 comparator equal multiplexer mux control value C1iC2iC3i mux control value equal + oc open-collector connection (zero whenever one connection is zero, one otherwise – wired AND) tri-state driver (can disconnect from output) Datapath Implementation (contd) zTri-State Logic yUtilize a third output state: no connection or float yConnect outputs together as long as only one is enabled yOpen-collector gates can only output 0, not 1 xCan be used to implement logical AND with only wires

24 CS Fall Sequential Logic Examples - 24 InOEOut X 0Z non-inverting tri-state buffer 100 In OE Out Tri-State Gates zThird value yLogic values: 0, 1 yDon't care: X (must be 0 or 1 in real circuit!) yThird value or state: Z high impedance, infinite R, no connection zTri-state gates yAdditional input – output enable (OE) yOutput values are 0, 1, and Z yWhen OE is high, the gate functions normally yWhen OE is low, the gate is disconnected from wire at output yAllows more than one gate to be connected to the same output wire xAs long as only one has its output enabled at any one time (otherwise, sparks could fly) InOut OE

25 CS Fall Sequential Logic Examples - 25 when Select is high Input1 is connected to F when Select is low Input0 is connected to F this is essentially a 2:1 mux OE F Input0 Input1 Select Tri-State and Multiplexing zWhen Using Tri-State Logic y(1) Never more than one "driver" for a wire at any one time (pulling high and low at same time can severely damage circuits) y(2) Only use value on wire when its being driven (using a floating value may cause failures) zUsing Tri-State Gates to Implement an Economical Multiplexer

26 CS Fall Sequential Logic Examples - 26 open-collector NAND gates with ouputs wired together using "wired-AND" to form (AB)'(CD)' Open-Collector Gates and Wired-AND zOpen collector: another way to connect gate outputs to same wire yGate only has the ability to pull its output low yCannot actively drive wire high (default – pulled high through resistor) zWired-AND can be implemented with open collector logic yIf A and B are "1", output is actively pulled low yIf C and D are "1", output is actively pulled low yIf one gate output is low and the other high, then low wins yIf both outputs are "1", the wire value "floats", pulled high by resistor xLow to high transition usually slower than if gate pulling high yHence, the two NAND functions are ANDed together

27 CS Fall Sequential Logic Examples - 27 C1C2C3 comparator value equal multiplexer mux control ld1ld2ld3 Digital Combination Lock (New Datapath) zDecrease number of inputs zRemove 3 code digits as inputs yUse code registers yMake them loadable from value yNeed 3 load signal inputs (net gain in input (4*3)–3=9) xCould be done with 2 signals and decoder (ld1, ld2, ld3, load none)

28 CS Fall Sequential Logic Examples - 28 Section Summary zFSM Design yUnderstanding the problem yGenerating state diagram yImplementation using synthesis tools yIteration on design/specification to improve qualities of mapping yCommunicating state machines zFour case studies yUnderstand I/O behavior yDraw diagrams yEnumerate states for the "goal" yExpand with error conditions yReuse states whenever possible

Еще похожие презентации в нашем архиве:

Готово:

HPC Pipelining Parallelism is achieved by starting to execute one instruction before the previous one is finished. The simplest kind overlaps the execution.

HPC Pipelining Parallelism is achieved by starting to execute one instruction before the previous one is finished. The simplest kind overlaps the execution.

© 2017 MyShared Inc.

All rights reserved.