1 / 53

8. State Machines (also called Finite State Machines (FSM), Automaton)

8. State Machines (also called Finite State Machines (FSM), Automaton). Finite-State Machines (FSMs). Why do we need them? Problem 1: make an 8-bit shift register. Implement the following sequence: 8’b00000001 //Shift left 8’b00000010 //Shift Left … 8’b10000000 //Shift right

meris
Download Presentation

8. State Machines (also called Finite State Machines (FSM), Automaton)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 8. State Machines(also called Finite State Machines (FSM), Automaton)

  2. Finite-State Machines (FSMs) • Why do we need them? • Problem 1: make an 8-bit shift register. Implement the following sequence: • 8’b00000001 //Shift left • 8’b00000010 //Shift Left • … • 8’b10000000 //Shift right • 8’b01000000 //Shift right • … • 8’b00000001 • ..and from the beginning again… • Solution (?) Bidirectional shift register with a comparator… • always @ (posedge CLK) • if (Reset || Q_reg == 8’b00000000) Q_reg <= 8’b00000001; • elseif (LnR) Q_reg <= {Q_reg[6:0], 1’b0}; • elseQ_reg <= {1’b0, Q_reg [7:1]}; • assignLnR = (Q_reg == 8’b10000000) ? 1’b0:1’b1;

  3. Finite-State Machines (FSMs) • Solution (?) Bidirectional shift register with a comparator… • always @ (posedge CLK) • if (Reset || Q_reg == 8’b00000000) Q_reg <= 8’b00000001; • elseif (LnR) Q_reg <= {Q_reg[6:0], 1’b0}; • elseQ_reg <= {1’b0, Q_reg [7:1]}; • assignLnR = (Q_reg == 8’b10000000) ? 1’b0:1’b1; • Will it work? What will be the real sequence? • 8’b00000001 • 8’b00000010 • … • 8’b10000000 • 8’b01000000 //AND NOW? • 8’b10000000 //Because LnR becomes 1 • //again! • 8’b01000000 // and 0 again! • 8’b10000000 //and so on… • What are we missing?

  4. Finite-State Machines (FSMs) • What are we missing? • KEEP IN MIND whether the register shifts to left or right • Toggle LnR at both endpoint conditions • reg QFF; • always @ (posedge CLK) • if (Reset) QFF = 1’b0; • else if ((Q == 8’h10) && (QFF == 1’b0) QFF <= 1’b1; • else if ((Q == 8’h01) && (QFF == 1’b1) QFF <= 1’b0; • assign LnR = ~QFF; • QFF depends on its previous value the current value i.e. ON THE PREVIOUS STATE • In fact QFF implements a STATE MACHINE WITH TWO STATES

  5. Finite-State Machines (FSMs) • In fact QFF implements a STATE MACHINE WITH TWO STATES (we can call it hidden state machine) • Look to the block schematic below! • The comparators will determinethe NEXT STATE of QFF, DEPENDINGon the CURRENT STATE • QFF holds THE CURRENT STATE • There is useless to have a state machinewithout an OUTPUT (LnR, which is ~QFF)

  6. Finite-State Machines (FSMs) • Problem 2: make a 4-bit counter, that counts in the following sequence: • 1. Count up to 12 • 2. Count down to 5 • 3. Count up to 7 and hold counting until Reset becomes active • In other words, imagine it as a task: • 1. Go up to the 12th floor to take some papers from an office • 2. Then go down to the 5th floor to leave the papers to be signed • 3. Afterwards go up to the 7th floor and wait for… • Cannot be done by simply pressing the elevator buttons 12, 5 and 7! • We have here four STATES to keep in mind: • Counting up to 12 • Counting down to 5 • Counting up to 7 • Hold counting at 7 • Think about a two-bit counter that holds the current state

  7. Finite-State Machines (FSMs) • Think about a two-bit counter that holds the current state • reg [1:0] cntst; • always @ (posedge CLK) • if (Reset) cntst <= 2’b00; • elseif ( ((cnt == 4’hC) && (cntst == 2’b00)) || //are the conditions OK? • ((cnt == 4’h5) && (cntst == 2’b01)) || //Check them • ((cnt == 4’h7) && (cntst == 2’b10)) ) //using simulation! • cntst<=cntst+ 2’b01; • //correct conditions are: 4’hB, 4’h6, 4’h6 !!! • //NOT EVEN THE PREVIOUS PROBLEM/SOLUTION IS CORRECT!!! GO BACK //AFTER FINISHINGTHIS ONE ! • always @ (cntst) begin • case (cntst) • 2’b00: begin • CE = 1’b1; UnD = 1’b1; • end • 2’b01: begin • CE = 1’b1; UnD = 1’b0; • end • … • 2’b11: CE = 1’b0;

  8. Finite-State Machines (FSMs) • Think about a two-bit counter that holds the current state • Therefore our states are called 2’b00, 2’b01, 2’b10, 2’b11 • Why not organize the state machine? • Describe states and transitions by using STATE MACHINE DIAGRAMS • Give suggestive names to states • Use a typical coding style • Note: In the HLD7 state the UnD = 1’b1 output is not relevant (CE is anyway 0)

  9. Finite-State Machines (FSMs) • Many digital systems can be looked as FSMs • Example: Assembly code sequence for HC08 (Freescale, former Motorola) • EE00 lda $0010 ; Load accumulator A from address… • EE02 beq #EE0D ; If A=0, jump to address EE0D • EE04inca; A<-A+1 • EE05 beq #EE10 ; If A was FF, then jump to address … • EE07 cmp #$02 ; Compare with 2 • EE09 beq #EE15 ; If A = 2, then jump to address… • EE0B bra #EE00 ; Jump back to address…

  10. @ELSE RESET IDLE A=1 A=0 A=255 INSTR_FROM_EE0D INSTR_FROM_EE15 INSTR_FROM_EE10 Finite-State Machines (FSMs) • Many digital systems can be looked as FSMs • Example: Assembly code sequence for HC08 (Freescale, former Motorola) • The state machine diagram implemented by the code sequence:

  11. Finite-State Machines (FSMs) • IN FACT : CPU is a PROGRAMMABLE STATE MACHINE • States are held by the INSTRUCTION POINTER (or PROGRAM COUNTER) (for HC08: 16 bits) • Outputs: set by the instructions • Transitions: depending on the microprocessor flags • Keeping into account the considerations above, a part of the state diagram is – see next slide

  12. RESET EE00 PC=PC+2 1 EE02 PC<=PC+(A=0) AND 11 + (A\=0) A\=0 A=0 EE0D EE04 INSTRUCTION A<=A+1 PC<=PC+1 1 EE05 PC<=PC+(A=0) AND 11 + (A\=0) AND A=0 A\=0 Z=0 EE07 EE10 Z<='1' when A=2 ELSE INSTRUCTION '0' 1 EE09 PC<=PC+(Z=1) AND 12 + (Z=0) Z=1 EE15 INSTRUCTION Keeping into account the considerations above, a part of the state diagram is:

  13. Finite-State Machines (FSMs) • Notes: • The state machine diagram above can be described in many ways, depending on the level of abstractization • Each state (instruction) represents in fact a colloection of states/operations for the CPU: • Fetch • Instruction decode • Execute • Some of the operations above can be implemented in Pipeline!

  14. Finite-State Machines (FSMs) • For State machines implemented by CPUs: • Low execution speed: some of the instructions need several clock periods, at a clock speed of 4..20MHZ • But flexible – easy to change the algorithm • For state machines implemented on FPGAs or ASICs: • Very fast (A decision can be taken in a single clock period, at a clock frequency of 50..200MHz • But rigid – changing the algorithm to be implemented may need to redesign the state machine • Therefore: design the state machine to be as readable as possible!

  15. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) Logica Stare IN D Q CLK > RESET RESET – Sincron sau asincron • SINCRONE: • Structura Generala(Ieșirile nu sunt atribuite): COMBINAȚIONAL SECVENȚIAL • În funcție de modul de atribuire a ieșirilor, se deosebesc trei tipuri de automate secvențiale (conform Heinkel): • Medvedev • Moore • Mealy

  16. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) RESET INCEPUT OUT Logica Stare IN Y<='0'; Z<='0' D Q CLK > A XOR B ='1' A='0' AND B='0' RESET CONTINUARE SFARSIT RESET – Sincron sau asincron Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV • Iesirile reprezinta de fapt STĂRILE automatului secvential (vectorul de stari) • Exemplu:

  17. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV • Ieșirile reprezintă de fapt STĂRILE automatului secvențial • Exemplu: Un Proces • parameter INCEPUT =2’b00; • parameter CONTINUARE = 2’b11; • parameter SFARSIT= 2’b01; • reg [1:0] STATE; • always @ (posedge CLK or A or B or STATE orposedge RESET) • if (RESET) STATE<=INCEPUT; • elsebegin case (STATE) • INCEPUT: if (!(A | B)) STATE<=CONTINUARE; • else STATE<=INCEPUT; • CONTINUARE : if (A & B) STATE<=SFARSIT; • else STATE<=CONTINUARE; • SFARSIT: if (A ^ B) STATE<=INCEPUT; • else STATE<=SFARSIT; • default: STATE<=INCEPUT; • endcase; • end • assign Y<=STATE[1]; • assign Z<=STATE[0]; • end

  18. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV • Ieșirile reprezintă de fapt STĂRILE automatului secvențial • Rezultatul simulării Post-Translate: Y, Z: reprezintă starea -> Automat MEDVEDEV

  19. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV • Ieșirile reprezintă de fapt STARILE automatului secvential • Exemplele cu un proces: • greu de urmărit, greu de depanat • greu de atribuit semnale la “intrarea în stare” • Exemplu cu Doua Procese: • Folosim semnalul intermediar NEXTSTATE - de la ieșirea blocului combinațional

  20. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' Logica Stare IN D Q CONTINUARE SFARSIT CLK > Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' RESET • MEDVEDEV • Folosim semnalul intermediar NEXTSTATE - de la iesirea blocului combinațional • reg [1:0] STATE, NEXTSTATE:=INCEPUT; • always @ (posedge CLK orposedge RESET) • if (RESET) STATE<=INCEPUT; • else STATE <= NEXTSTATE; • always @ (A or B or STATE) begin • case (STATE) • INCEPUT: if (!(A | B)) NEXTSTATE<=CONTINUARE; • elseNEXTSTATE<=INCEPUT; • CONTINUARE : if (A & B) NEXTSTATE<=SFARSIT; • elseNEXTSTATE<=CONTINUARE; • SFARSIT: if (A ^ B) NEXTSTATE<=INCEPUT; • elseNEXTSTATE<=SFARSIT; • default: NEXTSTATE<=INCEPUT; • endcase; • end • assign Y<=STATE[1]; • assign Z<=STATE[0]; • end

  21. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV Rezultatul simularii Post-translate: acelasi

  22. Automate Secvenţiale (Finite-State Machines, FSM, Automaton) RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • (Heinkel): Una sau doua procese? • Observații: • Moore, Mealy: pot fi două sau trei (sau mai multe!) procese • Chiar si la Medvedev: pot exista mai multe procese ! • (Exemplu: Se trece din CONTINUARE in SFARSIT daca A AND B =‘1’ timp de 10 perioade de ceas) • In acest caz: numărător separat, (recomandabil) numărând în proces separat: • always @ (posedge CLK) begin • if ((STATE!=CONTINUARE) | (!(A & B)) cnt<=0; • else cnt<=cnt+1; • end • always @ (A or B or STATE) begin • case (STATE) • … • CONTINUARE : if (cnt==10) NEXTSTATE<=SFARSIT; • elseNEXTSTATE<=CONTINUARE; • SFARSIT: • …

  23. Automate Secvenţiale • (Heinkel): Una sau doua procese? • Întrebarea relevantă este: Înregistrarea stării şi tranziţiile: ÎN PROCES COMUN SAU în PROCESE SEPARATE? (una sau doua procese?) • Un singur proces, justificate de: • Starea automatului secvențial: SE SCHIMBĂ INTR-UN SINGUR PROCES • Reprezentarea grafică a automatului secvențial: Echivalent cu un singur proces • Ieșirile pot fi atribuite concomitent cu stările • Dar în cazul folosirii unui numărător? vezi exemplul precedent • Doua procese, justificate de: • Structura automatului secvenţial: Circuitele combinaţionale ≠ Circuitele secventiale -> două procese • Simulare: Doua procese permit acces la semnalul NEXTSTATE (starea urmatoare), rezulta: MAI USOR DE DEPANAT • Sinteză: oferă acces la NEXTSTATE – semnalele pot fi modificate la “intrarea” în stare • Sinteză: Doua procese pot conduce la circuite mai mici, deci, la rezultate de sinteză mai bune (Heinkel)

  24. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV • Avantaje: • Foarte rapide (ieșirile nu parcurg logică suplimentară) • Ieşiri – de la ieşirea unui bistabil (Q), deci sunt ÎNREGISTRATE, Rezultă că se evită apariţia de semnale hazardate (spike, glitch) • Dezavantaje: • Codificarea stărilor: trebuie făcut manual, necesita efort suplimentar in scrierea codului HDL • Rigide – greu de modificat automatul secvenţial (adăugat sau șters stări etc)

  25. RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' STATE Logica Iesire OUT Logica Stare IN D Q CLK > RESET RESET – Sincron sau asincron Automate Secvenţiale (Finite-State Machines, FSM, Automaton) • MOORE • Ieșirile reprezintă de fapt FUNCŢII LOGICE ale STĂRILOR (vectorului de stari) • Exemplu: Acelaşi automat secvenţial SECVENȚIAL COMBINAȚIONAL COMBINAȚIONAL

  26. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MOORE • Iesirilereprezintă de fapt FUNCŢII LOGICE ale STĂRILOR (vectorului de stari) • parameter INCEPUT =1; • parameter CONTINUARE = 2; • parameter SFARSIT=3; • reg [1:0]StC, StN; • always @ (posedge CLK orposedge RESET) • if (RESET) StC<=INCEPUT; • elseStC<= NEXTSTATE; • always @ (A or B orStC)begin • StN<= StC; //Introducemtranzitiaimplicita • //Asta e posibil la oricareimplementare de automat secvential! • case (StC) • INCEPUT: if (!(A | B)) StC<=CONTINUARE; • CONTINUARE : if (A & B) StC<=SFARSIT; • SFARSIT: if (A ^ B) StC<=INCEPUT; • default: StC<=INCEPUT; • endcase; • end • assign Y<= (StC == CONTINUARE) ? 1:0; • assign Z<= ((StC == CONTINUARE) || (StC == SFARSIT)) ? 1:0; • end

  27. Automate Secvenţiale • Din nou: Una sau doua procese? • Observație: ISE, Language Templates, Coding Examples: Automat secvențial de tip MOORE cu un singur proces: • always@(posedge <clock>) • if (<reset>) begin • state <= <state1>; • <outputs> <= <initial_values>; • end • else • (* PARALLEL_CASE, FULL_CASE *) case (state) • <state1> : begin • if (<condition>) state <= <next_state>; • else if (<condition>) state <= <next_state>; • else state <= <next_state>; • <outputs> <= <values>; • end • <state2> : begin • if (<condition>) state <= <next_state>; • else if (<condition>) state <= <next_state>; • else state <= <next_state>; • <outputs> <= <values>; • end

  28. Automate Secvenţiale • Din nou: Una sau doua procese? • Observație: ISE, Language Templates,CodingExamples: Automat secvențial de tip MOORE cu un singur proces: • Exemplu • always @ (posedge CLK) • if (Reset) begin • state <= INCEPUT; • Y <= 0; • Z <= 0; • end • else • (* PARALLEL_CASE, FULL_CASE *) case(state) • INCEPUT : begin • if (A|B) state <= CONTINUARE; • else state <= INCEPUT; • Y <=1; • Z <=0; • end • … • Codul e scris corect, ieșirile sunt ÎNREGISTRATE • Dar în cazul multor ieșiri sau în cazul folosirii unui contor?

  29. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' STATE Logica Iesire OUT Logica Stare IN D Q CLK > RESET RESET – Sincron sau asincron • MOORE • Ieşirile reprezinta de fapt FUNCTII LOGICE ale STĂRILOR (vectorului de stări) • Rezultatul simularii: • Semnalele de ieşire se schimbă sincron cu starea, rezultă automat secvenţial MOORE

  30. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MOORE • Avantaje: • Asigură viteză de lucru mare • Operaţie stabilă • Dezavantaje: • Nu este ferit de hazard combinațional! Pot aparea valori parazite in semnalele de ieşire, de exemplu: logică SAU, logică XOR • Însă: valorile parazite în general sunt mult mai scurte decât perioada de tact

  31. RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' Logica Iesire Logica Stare Out D IN Q CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' CLK A='1' AND B='1' > RESET Proces Combinational Proces Secvential Automate Secvenţiale (Finite-State Machines, FSM, Automaton) • MEALY • Ieșirile sunt FUNCŢII LOGICE ale STĂRILOR (vectorului de stări) şi ALE INTRĂRILOR • Exemplu: Acelaşi automat secvenţial

  32. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEALY • Ieșirile sunt FUNCTII LOGICE ale STARILOR (vectorului de stări) și ALE INTRĂRILOR • Exemplu: (aceeași descriere de stări ca si la MOORE) • parameter INCEPUT =1; • parameter CONTINUARE = 2; • parameter SFARSIT=3; • reg [1:0]StC, StN; • always @ (posedge CLK orposedge RESET) • if (RESET) StC<=INCEPUT; • elseStC<= NEXTSTATE; • always @ (A or B orStC)begin • StN<= StC; //Introducemtranzitiaimplicita • //Asta e posibil la oricareimplementare de automat secvential! • case (StC) • INCEPUT: if (!(A | B)) StC<=CONTINUARE; • CONTINUARE : if (A & B) StC<=SFARSIT; • SFARSIT: if (A ^ B) StC<=INCEPUT; • default: StC<=INCEPUT; • endcase; • end • assignY = ((StC==CONTINUARE) &&(!(A | B))) || ((StC==SFARSIT) && (!(A & B))) ? 1:0; • assign Z = ((StC==INCEPUT) && (A & B)) || (StC==CONTINUARE) • || ((StC==SFARSIT && (A & B)) ? 1:0; • end

  33. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEALY • Ieșirile sunt FUNCȚII LOGICE ale STĂRILOR (vectorului de stări) și ALE INTRARILOR • Rezultatul simulării: Y, Z se schimbă la cu intrările si cu starea, rezultă automat secvential MEALY

  34. Automate Secvenţiale • MEALY • Iesirile sunt FUNCTII LOGICE ale STARILOR (vectorului de stari) si ALE INTRARILOR • ATENTIE: PARAZIȚI (SPIKE, GLITCH) ÎN SEMNALELE DE IESIRE! • SPIKE: SEMNAL ACTIV PE O DURATĂ MAI SCURTĂ DECÂT PERIOADA DE TACT – POATE GENERA DISFUNCŢIUNI ÎN SISTEMUL DIGITAL

  35. Automate Secvenţiale Logica Iesire Logica Stare IN2 Out2 D Q CLK < RESET Proces Combinational Proces Secvential Logica Iesire Out1 Logica Stare D IN1 Q CLK > RESET Proces Combinational Proces Secvential • MEALY • Avantaje: • Cel mai flexibil (usor de modificat) • Dezavantaje: • Posibilitatea apariției paraziților in semnalele de ieșire • Pot exista căi cu timpi de propagare lungi (reduce perioada minima a tactului • PERICOLUL APARIŢIEI BUCLELOR COMBINAŢIONALE!!!

  36. Automate Secvenţiale Logica Iesire Logica Stare Out D IN Q Q D CLK > > RESET Proces Combinational Logica Iesire Logica Stare Out Proces Secvential D IN Q Q D CLK > > RESET Proces Combinational Proces Secvential • MEALY • Pentru Evitarea PARAZITILOR SI A BUCLELOR COMBINATIONALE: IESIRI INREGISTRATE • Doua Variante:

  37. Automate Secvenţiale Logica Iesire Logica Stare Out D IN Q Q D CLK > > RESET Proces Combinational Proces Secvential • MEALY • PentruEvitarea PARAZITILOR SI A BUCLELOR COMBINATIONALE: IESIRI INREGISTRATE • Prima varianta: • //semnale interne Y_INT, Z_INT • wireY_INT, Z_INT; • ….. • assignY_INT = ((StC==CONTINUARE) &&(!(A | B))) || ((StC==SFARSIT) && (!(A & B))) ? 1:0; • assign Z_INT = ((StC==INCEPUT) && (A & B)) || (StC==CONTINUARE) • || ((StC==SFARSIT && (A & B)) ? 1:0; • always @ (posedge CLK) begin • Y<=Y_INT; • Z<= Z_INT; • end • Rezultatulsimularii: Ieșirile – întârziate cu un tact, pot rezultavalorinedorite/nepresupuse

  38. Automate Secvenţiale Logica Iesire Logica Stare Out D IN Q Q D CLK > > RESET Proces Combinational Proces Secvential • MEALY • Pentru Evitarea PARAZITILOR SI A BUCLELOR COMBINATIONALE: IESIRI INREGISTRATE • A doua varianta: ATRIBUIRE PE StN • wireY_INT, Z_INT; • ….. • assignY_INT = ((StN==CONTINUARE) &&(!(A | B))) || ((StN==SFARSIT) && (!(A & B))) ? 1:0; • assign Z_INT = ((StN==INCEPUT) && (A & B)) || (StN==CONTINUARE) • || ((StN==SFARSIT && (A & B)) ? 1:0; • always @ (posedge CLK) begin • Y<=Y_INT; • Z<= Z_INT; • end • Rezultatul simularii: Ieșirile – Sincrone cu tactul si cu starea, fără paraziți

  39. Automate Secvenţiale Logica Iesire Logica Stare Out D IN Q Q D CLK > > RESET Proces Combinational Proces Secvential • MEALY • Pentru Evitarea PARAZITILOR SI A BUCLELOR COMBINATIONALE: IESIRI INREGISTRATE • A doua varianta: ATRIBUIRE PE StN • Rezultatul simularii: Ieșirile – Sincrone cu tactul si cu starea, fără paraziți • Dezavantaje: • Ieșirea circuitului combinațional, E ÎNCĂRCATĂ, care determină timpi de întârzieri mai mari

  40. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV MODIFICAT • Ieșirile reprezintă Semnale din Vectorul Stărilor • însă stările sunt codificate după conveniența proiectantului • Exemplu: • //Prima coloană reprezintă stările, cea de-a doua coloană reprezintă ieșirile • parameter INCEPUT = {2’b00, 2’b00}; • parameter CONTINUARE = {2’b01, 2’b11}; • parameter SFARSIT= {2’b11, 2’b01}; • reg [3:0]StC, StN = INCEPUT; • assign Y<=StC [1]; • assign Z<=StC [0]; • always @ (posedge CLK orposedge RESET) • if (RESET) StC<=INCEPUT; • elseStC<= NEXTSTATE; • always @ *begin • StN<= StC; • case (StC) • INCEPUT: if (!(A | B)) StC<=CONTINUARE; • CONTINUARE : if (A & B) StC<=SFARSIT; • SFARSIT: if (A ^ B) StC<=INCEPUT; • default: StC<=INCEPUT; • endcase; • end

  41. Automate Secvenţiale RESET INCEPUT Y<='0'; Z<='0' A XOR B ='1' A='0' AND B='0' CONTINUARE SFARSIT Y<='0';Z<='1' Y<=‘1';Z<=‘1' A='1' AND B='1' • MEDVEDEV MODIFICAT • Ieșirile reprezintă Semnale din Vectorul Stărilor • însă stările sunt codificate după conveniența proiectantului • Avantaje: • Ieșirile sunt înregistrate • Automatul secvențial este rapid și posedă toate avantajele automatelor secvențiale Medvedev • Dezavantaje: • Automatul este totuși rigid și necesită o specificare foarte precisă • Semnale suplimentare față de stări: • Automatul secvențial în implementare ocupă mai mulți regiștri decât în cazul unei implementări Medvedev

  42. Automate Secvenţiale • Moduri de codificare a stărilor: • Diverse moduri: • Binar: 000, 001, 010, 011, …. – compact, celemaiputinebistabilerezultate • One-Hot: 000, 001, 010, 100,… - rapid, rezultalogica minima • Gray: 000, 001, 011, 010, …. – un singur bit se schimba: probabilitatefoarte mica de hazard • Johnson: 000, 001, 011, 111, 110, … - e atât rapid cât și cu probabilitate de hazard foarte mică • Celmai convenient mod de codificare: printipuri de enumerare, iarcodificareasa fie lasatapentrusintetizator • În meniu: Synthesize, options, HDL options, FSM encodingstyle: se poate alege tipul de codificare, inclusiv USER şi NONE! • În cod: (* FSM_ENCODING=“<CODING_STYLE>“ *) • Întotdeauna ÎNAINTEA definirii semnalului de stare!!!

  43. Automate Secvenţiale • Moduri de codificare a stărilor: • În cod: (* FSM_ENCODING=“<CODING_STYLE>“ *) • Întotdeauna ÎNAINTEA definirii semnalului de stare!!! • Exemplu: • (* FSM_ENCODING=“ONE_HOT“ *)reg[4:0] StC, StN; • Coding STYLE (Encoding Algorithm) • • Auto (default) • • One-Hot • • Compact • • Sequential • • Gray • • Johnson • • Speed1 • • User • Coding STYLE poatefispecificatși în cadrul fișierului de constrângeri .xcf

  44. Automate Secvenţiale • Observație: Synthesis Report • Synthesizing Unit <State_machine_1>. • Related source file is "State_machine_1.v". • Found finite state machine <FSM_0> for signal <StC>. • ----------------------------------------------------------------------- • | States | 4 | • | Transitions | 7 | • | Inputs | 2 | • | Outputs | 3 | • | Clock | CLK (rising_edge) | • | Reset | RESET (positive) | • | Reset type | synchronous | • | Reset State | 0000 | • | Encoding | automatic | • | Implementation | LUT | • ----------------------------------------------------------------------- • Summary: inferred 1 Finite State Machine(s). • Unit <State_machine_1> synthesized.

  45. Automate Secvenţiale • Observație: Synthesis Report • ============================================================== * Advanced HDL Synthesis * ==============================================================Analyzing FSM <FSM_0> for best encoding. • Optimizing FSM <StC/FSM> on signal <StC[1:2]> • with gray encoding. • ------------------- State | Encoding ------------------- • 0000 | 00 • 0101 | 01 • 1010 | 11 • 1111 | 10 • -------------------

  46. Automate Secvenţiale • Opțiuni de Sinteză legate de Automate Secvențiale • • Automatic Finite State Machine (FSM) Extraction (FSM_EXTRACT) • Yes sau No • • Finite State Machine (FSM) Style (FSM_STYLE) • LUT sau BRAM • • Finite State Machine (FSM) Encoding Algorithm (FSM_ENCODING) • Binary, One-hotetc • • Enumerated Encoding (ENUM_ENCODING) • Numai in cazul VHDL • • Safe Implementation (SAFE_IMPLEMENTATION) • Yes sau No • • Safe Recovery State (SAFE_RECOVERY_STATE) • (* safe_recovery_state = "<value>" *) • Exemplu: (* safe_recovery_state = “Shiftl0" *)

  47. Automate Secvenţiale • Safe Implementation: • Automatelesecventiale: datoritaunorperturbatii, pot ajunge in starinedefinite (eronate), lucru care trebuieevitat, de exempluprinresetare • Moduri de codificare a starilor: Evitareablocarii in StarileEronate • Celmai convenient mod de codificare: printipuri de enumerare, iarcodificareasa fie lasatapentrusintetizator • Exemplu: • case (StC) • INCEPUT: …… • CONTINUARE: …. • SFARSIT: ….. • default: => StN<=Inceput; • //dacacodificarea: Binarsau GRAY, rezulta: pedoibiti • //Rezultanumarul maxim de stari: 4 • // In cazulaparitieistariinedorite, defaultreseteaza • //automatulsecvential ? Default tine doar de implementarea case • endcase//Doar daca (* SAFE_IMPLEMENTATION = YES *)

  48. Automate Secvenţiale • Moduri de codificare a starilor: • Alta Solutie:Introducerea de starieronate manual, exemplu: • AceastaSolutiepoatefisisimulata! • Parameter Eronat = 2’b10 • case (StC) • INCEPUT: …… • CONTINUARE: …. • SFARSIT: ….. • ERONAT: ….. • default:StN<=InceputDezavantaje: • In cazulcodificariibinaresau Gray pe N biti: ca sa se acoperetoatestarile, arfinecesar un numar de starieronate de 2N-Numar_Stari_Corecte! • In cazulcodificarii One-Hot: Prinintroducera de starisuplimentare, crestenumarul de biti, implicit numarul de starieronateposibile. Rezulta: NU SE POT ACOPERI STARILE ERONATE! • Solutie: Pentru automat secventialstabil, metodarecomandata: • Codificaremanuala, de tip Medvedev sau Medvedev modificat

  49. Automate Secvenţiale • Moduri de codificare a starilor: Cat conteaza codificarea in viteza circuitului? Cat conteaza tipul de numarator folosit? • Exemplul 1: Numarator in cod BCD, pe 8 biti, descris in Behavioral (8 bistabile, 256 stari): (SPARTAN 2E XC2S200E) • always @ (posedge CLK) • if (CE) • if (Q==255) Q<=0; • else Q<=Q+1; • Synthesis Report : Minimum period: 6.795ns (Maximum Frequency: 147.167MHz) • Exemplul 2: Numarator in cod JOHNSON, pe 8 biti, descris in Behavioral (8 bistabile, 16 stari): (SPARTAN 2E XC2S200E) • always @ (posedge CLK) • if (CE) Q [7:0] <= {Q[6:0], ~Q[0]}; • Synthesis Report : Minimum period: 4.254ns (Maximum Frequency: 235.073MHz)

  50. Automate Secvenţiale • Cat conteaza tipul de codificare folosit? • Exemplul 3: Numarator in cod BINAR, pe 8 biti, descris in Behavioral (8 bistabile, 256 stari, cu insumare) • always @ (posedge CLK) • if (CE) Q<=Q+1; • Synthesis Report : Minimum period: 4.845ns (Maximum Frequency: 206.398MHz) • Mai rapid decat Exemplul 1, insa mai incet decat Exemplul 2 • Din ce cauză?

More Related