1 / 16

Finite State Machine: Realization

Finite State Machine: Realization. Martinet Lee, Steve Chung. Outline. What is FSM? The theory Not only a theory Now, forget about FSM Implementing functions, by circuit Implementing functions, by logic When circuit meets logic, FSM A simple example : from functions to FSM to circuit.

carrie
Télécharger la présentation

Finite State Machine: Realization

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. Finite State Machine:Realization Martinet Lee, SteveChung

  2. Outline • What is FSM? • The theory • Not only a theory • Now, forget about FSM • Implementing functions, by circuit • Implementing functions, by logic • When circuit meets logic, FSM • A simple example: from functions to FSM to circuit

  3. What is FSM?

  4. The Theory

  5. Not only a theory… • You know how it looks like  • But how to construct it?How to connect it with the target function?

  6. Now, Forget about FSM

  7. Implementing functions, by circuit • Function: Simple Traffic Light: Red Green  Yellow  Red(repeat) • Construct a counter which will reset on 2 : • 0  1  2  0 … • 2’b00  2’b01  2’b10  2’b00  … • Construct the lights according to the counter’s value.

  8. Implementing functions, by circuit • Function: Find target , identify target ( enemy and ally ) , act accordingly ( fire, supply ), then repeat. • How to construct? • Counter?

  9. Implementing functions, by Logic • Function: Find target , identify target ( enemy and ally ) , act accordingly ( fire, supply ), then repeat. • How to construct? • Search  Found  if( target == Enemy ) Fire; else Supply; Search

  10. When Circuit meets Logic:Finite State Machine

  11. Finite State Machine • Function: Find target , identify target ( enemy and ally ) , act accordingly ( fire, supply ), then repeat. • Aintuitive mapping from “function” to “FSM graph” • But how to implement?

  12. Finite State Machine Implementation • Create a set of registers, to store STATE • Assign each state on FSM to a number • Search  0  3’b000 • Found  1  3’b001 • Enemy  2  3’b010 • Ally  3  3’b011 • Fire  4  3’b100 • Supply  5  3’b101 • A circuit that could differentiate enemy and ally, will produce a 1-bit signal.

  13. FINITE STATE MACHINE IMPLEMENTATION • reg [2:0] State;reg [2:0] nextState;regdetected_smth;regisenemy;always@(posedgeclk)beginif(reset == 1’b1) State <= 3’b000; else begin State <= nextState; endendalways@(*) begincase(State) 3’b000: if(detected_smth == 1’b1) nextState = 3’b001; elsenextState = 3’b000; 3’b001: if( isenemy == 1’b1)nextstate = 3’b010; elsenextstate = 3’b011; 3’b010: nextState = 3’b100; 3’b011: nextState= 3’b101; 3’b100: nextState = 3’b000; 3’b101: nextState = 3’b000; default: nextState = 3’b000;endcaseend

  14. Code Not Clear enough… • Use parameter! • parameter S_Search = 3’b000;parameter S_Found = 3’b001;parameter S_Enemy = 3’b010;parameter S_Ally = 3’b011;parameter S_Fire = 3’b100;parameter S_Supply = 3’b101;

  15. Overall Code • reg [2:0] State;reg [2:0] nextState;regdetected_smth;regisenemy;parameter S_Search = 3’b000;parameter S_Found = 3’b001;parameter S_Enemy = 3’b010;parameter S_Ally = 3’b011;parameter S_Fire = 3’b100;parameter S_Supply = 3’b101;always@(posedgeclk)begin if(reset == 1’b1) State <= S_Search; else begin State <= nextState; endendalways@(*) begin case(State)S_Search: if(detected_smth == 1’b1) nextState = S_Found; elsenextState = S_Search;S_Found: if( isenemy == 1’b1)nextstate = S_Enemy; elsenextstate = S_Ally;S_Enemy:nextState = S_Fire;S_Ally:nextState = S_Supply;S_Fire:nextState = S_Search;S_Supply:nextState = S_Search; default: nextState = S_Search;endcaseend

  16. Any Questions? 

More Related