Understanding FPGA System Design with Finite State Machines

cda 4253 fpga system design finite state machines l.w
1 / 99
Embed
Share

Delve into the world of FPGA system design with a focus on Finite State Machines (FSMs). Learn about datapaths, controllers, programmable vs non-programmable controllers, and the role of FSMs in digital systems. Explore the concepts through illustrations and explanations of datapath execution units and control units. Gain insights into state diagrams, state tables, and Algorithmic State Machine (ASM) charts for designing controllers. This comprehensive guide provides a foundational understanding of implementing FSMs in FPGA systems.

  • FPGA System Design
  • Finite State Machines
  • Digital Systems
  • ASM Charts
  • FSM Controllers

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. CDA 4253 FPGA System Design Finite State Machines Hao Zheng Comp Sci & Eng USF

  2. Required Required reading reading P. Chu, FPGA Prototyping by VHDL Examples Chapter 5, FSM 2

  3. Datapath vs. Controller 3

  4. Structure of a Typical Digital System Data Inputs Control & Status Inputs Control Signals Datapath (Execution Unit) Controller (Control Unit) Status Signals Data Outputs Control & Status Outputs 4

  5. Datapath (Execution Unit) Manipulates and processes data. Performs arithmetic and logic operations, shifting/rotating, and other data-processing tasks. Is composed of registers, multiplexers, adders, decoders, comparators, ALUs, gates, etc. Provides all necessary resources and interconnects among them to perform specified task. Interprets control signals from the controller and generates status signals for the controller. 5

  6. Controller (Control Unit) Controls data movement in the datapath by switching multiplexers and enabling or disabling resources Example: enable signals for registers Example: select signals for muxes Provides signals to activate various processing tasks in the datapath, i.e. +, -, or *, ... Determines the sequence of operations performed by the datapath. Follows some program or schedule. 6

  7. Programmable vs. Non-Programmable Controller Controller can be programmable or non-programmable Programmable Has a program counter which points to next instruction Instructions are held in a RAM or ROM Microprocessor is an example of programmable controller Non-Programmable Once designed, implements the same functionality Another term is a hardwired state machine, or hardwired FSM, or hardwired instructions In this course we will be focusing on non- programmable controllers. 7

  8. Finite State Machines Controllers can be described as Finite State Machines (FSMs) Finite State Machines can be represented using State Diagrams and State Tables - suitable for simple controllers with a relatively few inputs and outputs Algorithmic State Machine (ASM) Charts Will be skipped as it is equivalent to state diagrams. All of these descriptions can be easily translated to the corresponding synthesizable VHDL code 8

  9. Steps of the Design Process 1. Text description 2. Define interface 3. Describe the functionality using pseudo-code 4. Convert pseudo-code to FSM in state diagram 1. Define states and state transitions 2. Define datapath operations in each state. 5. Develop VHDL code to implement FSM 6. Develop testbench for simulation and debugging 7. Implementation and timing simulation Timing simulation can reveal more bugs than pre- synthesis simulation 8. Test the implementation on FPGA boards 9

  10. Finite State Machines Refresher 10

  11. Finite State Machines (FSMs) An FSM is used to model a system that transits among a finite number of internal states. The transitions depend on the current state and external input. The main application of an FSM is to act as the controller of a medium to large digital system Design of FSMs involves Define states Define state transitions Define operations performed in each state Optimize / minimize FSM Manual optimization/minimization is practical for small FSMs only. 11

  12. Moore FSM Output is a function of the present state only Inputs Next State function Next State Present State clock State register reset Outputs Output function 12

  13. Mealy FSM Output is a function of the present state and the inputs. Inputs Next State function Next State Present State clock State register reset Outputs Output function 13

  14. State Diagrams 14

  15. Moore Machine transition condition 1 State 1 / operations State 2 / operations transition condition 2 State operations: datapath operations including output assignments. Transition conditions: Boolean expressions 15

  16. Mealy Machine transition condition 1 / datapath operations State 1 State 2 transition condition 2 / datapath operations 16

  17. Moore FSM - Example 1 Moore FSM that recognizes sequence 10 0 1 0 1 S2 / 1 S0 / 0 S1 / 0 reset 1 0 S0: No elements of the sequence observed S2: 10 observed S1: 1 observed Meaning of states: 17

  18. Mealy FSM - Example 1 Mealy FSM that recognizes sequence 10 1 / 0 0 / 0 1 / 0 S0 S1 reset 0 / 1 S0: No elements of the sequence observed S1: 1 observed Meaning of states: 18

  19. Moore & Mealy FSMs Example 1 clock 0 1 0 0 0 input state S0 S0 S1 S2 S0 S0 Moore output state S0 S0 S1 S0 S0 S0 Mealy output 19

  20. Moore vs. Mealy FSM (1) Moore and Mealy FSMs are functionally equivalent. Equivalent Mealy FSM can be derived from Moore FSM and vice versa. Mealy FSM has richer description and usually requires less number of states Smaller circuit area. 20

  21. Moore vs. Mealy FSM (2) Mealy FSM computes outputs as soon as inputs change. Mealy FSM responds one clock cycle sooner than equivalent Moore FSM. There are direct paths from inputs to outputs can cause output glitches. Moore FSM has no combinational path between inputs and outputs. Less likely to affect the critical path of the entire circuit. 21

  22. Which Way to Go? Mealy FSM Moore FSM Fewer states Safer. Lower Area Less likely to affect the critical path. Responds one clock cycle earlier 22

  23. Finite State Machines in VHDL 23

  24. FSMs in VHDL Finite State Machines can be easily described with processes. Synthesis tools understand FSM description if certain rules are followed. State transitions should be described in a process sensitive to clock and asynchronous reset signals only. Output function described using rules for combinational logic, i.e. as concurrent statements or a process with all inputs in the sensitivity list. 24

  25. Moore FSM process(clock, reset) Inputs Next State function Next State clock State Register Present State reset concurrent statements Outputs Output function 25

  26. Mealy FSM process(clock, reset) Inputs Next State function Next State Present State clock State Register reset Outputs Output function concurrent statements 26

  27. Moore FSM - Example 1 Moore FSM that Recognizes Sequence 10 1 0 0 1 1 S0 / 0 S1 / 0 S2 / 1 reset 0 27

  28. Moore FSM in VHDL (1) architecture ... architecture ... type type state IS (S0, S1, S2); -- enumeration type signal signal Moore_state: state; begin U_Moore: process process(clock, reset) begin begin if if (reset = 1 ) then then Moore_state <= S0; elsif elsif rising_edge rising_edge(clock) then case case Moore_state is is when when S0 => if if input = 1 then Moore_state <= S1; else else Moore_state <= S0; end if end if; 0 1 S0 / 0 S1 / 0 then then next state logic 28

  29. Moore FSM in VHDL (2) when when S1 => if if input = 0 then Moore_state <= S2; else else Moore_state <= S1; end if end if; when when S2 => if if input = 0 then Moore_state <= S0; else else Moore_state <= S1; end if end if; end case end case; end if end if; end process end process; -- output function Output <= 1 when when Moore_state = S2 else then next state logic then else 0 ; 29

  30. Mealy FSM - Example 1 Mealy FSM that Recognizes Sequence 10 . 0 / 0 1 / 0 1 / 0 S0 S1 reset 0 / 1 30

  31. Mealy FSM in VHDL (1) architecture ... architecture ... type type state IS (S0, S1); signal signal Mealy_state: state; begin U_Mealy: process process (clock, reset) begin begin if if (reset = 1 ) then Mealy_state <= S0; elsif elsif rising_edge rising_edge(clock) then case case Mealy_state is when when S0 => if if input = 1 then Mealy_state <= S1; else else Mealy_state <= S0; end if end if; then then is then next state logic 31

  32. Mealy FSM in VHDL (2) when when S1 => if if input = 0 then Mealy_state <= S0; else else Mealy_state <= S1; end if end if; end case end case; end if end if; end process end process; then next state logic -- output function Output <= 1 when 0 ; end architecture; and input = 0 ) else when (Mealy_state=S1 and else 32

  33. Generalized FSM Based on RTL Hardware Design by P. Chu 33

  34. Control Unit Example: Arbiter (1) reset g1 r1 Arbiter g2 r2 g3 r3 clock

  35. Control Unit Example: Arbiter (3) r 1 r 2 r 3 r 1 r 2 r 3 Reset Reset Idle Idle r 1 r 1 r 1 r 1 gnt1 g 1 gnt1 g 1 = = 1 1 r 1 r 1 r 2 r 2 r 1 r 2 r 1 r 2 gnt2 g 2 gnt2 g 2 = = 1 1 r 2 r 2 r 3 r 3 r 1 r 2 r 3 r 1 r 2 r 3 gnt3 g 3 gnt3 g 3 = = 1 1 r 3 r 3

  36. Arbiter VHDL Code ENTITY arbiter IS PORT(Clock, Resetn r g END arbiter; : IN STD_LOGIC ; : IN STD_LOGIC_VECTOR(1 TO 3); : OUT STD_LOGIC_VECTOR(1 TO 3)); ARCHITECTURE Behavior OF arbiter IS TYPE State_type IS (Idle, gnt1, gnt2, gnt3); SIGNAL state: State_type; begin 36

  37. Arbiter VHDL Code PROCESS(Resetn, Clock) BEGIN IF Resetn = '0' THEN state <= Idle ; ELSIF (Clock'EVENT AND Clock = '1') THEN CASE state IS WHEN Idle => IF r(1) = '1' THEN ELSIF r(2) = '1' THEN ELSIF r(3) = '1' THEN ELSE END IF ; WHEN gnt1 => IF r(1) = '1' THEN ELSE END IF ; -- continue on the next slide state <= gnt1 ; state <= gnt2 ; state <= gnt3 ; state <= Idle ; state <= gnt1 ; state <= Idle ; 37

  38. Arbiter VHDL Code WHEN gnt2 => IF r(2) = '1' THEN ELSE END IF ; state <= gnt2 ; state <= Idle ; END PROCESS ; -- continue on the next slide WHEN gnt3 => IF r(3) = '1' THEN state <= gnt3 ; ELSE END IF ; END CASE ; END IF ; state <= Idle ; 38

  39. Arbiter VHDL Code -- output function g(1) <= '1' WHEN y = gnt1 ELSE '0 ; g(2) <= '1' WHEN y = gnt2 ELSE '0 ; g(3) <= '1' WHEN y = gnt3 ELSE '0 ; END architecture Behavior ; 39

  40. Case Study 1 Debouncing Circuit

  41. Original & Debounced Inputs

  42. Debouncing Circuit Scheme 1 sw: input from slide switches or push buttons. m_tick: output from a timer with 10ms period. See listing 5.6 for VHDL code that implements this FSM

  43. Debouncing Testing Circuit

  44. Case Study 2 Fibonacci Number 44

  45. Fibonacci Number if i = 0 if i = 1 45

  46. Fibonacci Number rdy: input ready done: result is available n: number of iteraions t0: holds fib(i-2) t1: holds fib(i-1) idle/ done/ done <= 1 rdy <= 1 n=0/ t1 <= 0 n=1 op n/=1/ t1 <= t1+t0 t0 <= t1 n <= n-1 46

  47. VHDL Variables 47

  48. Differences: Signals vs Variables Variables can only be declared and used within processes or procedures. Used to hold temporary results. Signals can only be declared in architecture. - Used for inter-process communications. Variables are updated immediately. Signals are updated after current execution of a process is finished. Synthesis results: - Variables: wires or nothing - Signals: wires, registers, or latches. -

  49. Differences: Signals vs Variables architecture sig_ex of test is signal out1 : std_logic; begin process (clk) begin if rising_edge(clk) then out1 <= a and b; out2 <= out1 xor c; end if; end process; end sig_ex; a b out1 FF AND out2 FF XOR c

More Related Content