DSP Builder for Intel® FPGAs (Advanced Blockset): Handbook

ID 683337
Date 7/15/2024
Public
Document Table of Contents

14.6.6.3. Implement Token Passing with the Finite State Machine

The first state has extra behaviors associated with it. This Finite State Machine block remains in this state if DSP Builder holds the go input at logic low (0). If you add a finish port to Finite State Machine block, the output goes logic high (1) whenever the Finite State Machine returns to the first state.

Procedure

  1. Specify a Finite State Machine block with token passing behaviors:
    # Acts as an open gate only when the token is being held
    # When the release input goes high, the token is released and the gate closes
    require version 23.3
    inputs x release
    finish done
    netlist
    transitions Gate : q
        state Stopped
            default Pass 0
        state Pass
            if (release & ~x) Stopped 0
            if (release &  x) Stopped 1
            if (~x) Pass 0
            if (x) Pass 1
    end
    
    The finish keyword specifies the name for an output port on the Finite State Machine block from which DSP Builder produces any released token. This port outputs logic high (1) for one cycle whenever the Finite State Machine block completes and re-enters the start state.
  2. Connect multiple Finite State Machine blocks:
    Figure 139. Connecting Two Finite State Machine Blocks
    Figure 140.  Gate_q Outputs From the two Finite State Machine blocks as the token passes between them
  3. Observe the SampleDelay block in the feedback path. Simulink simulates the Finite State Machine block like a direct feed-through combinational logic block. It complains of an algebraic loop if you omit the feedback SampleDelay.
    The Finite State Machine block implements a Mealy machine by default when generating the state transition control logic.
  4. Modify this behavior by adding the moore keyword so DSP Builder implements a Moore Machine.
    require version 23.3
    inputs x release
    finish done
    netlist
    transitions Gate : q
        moore
        state Stopped
            default Pass 0
        state Pass
            if (release & ~x) Stopped 0
            if (release &  x) Stopped 1
            if (~x) Pass 0
            if (x) Pass 1
    end
    
    Figure 141. Moore Machine
    Figure 142. Moore Machine SimulationWhen the release input goes high the Finite State Machine does not always release the token as before. The Moore machine implementation now has two stopped states. One that outputs 0 and another that outputs 1. The initial state is output 0.
  5. To release the token, return to the stopped state to produce zero on all output ports:
    require version 23.3
    inputs x release
    finish done
    netlist
    transitions Gate : q
        moore
        state Stopped
            default Pass 0
        state Pass
            if (release) Stopped 0
            if (~x) Pass 0
            if (x) Pass 1
    end
    
    Although this code corrects the token release problem, it costs extra dead cycles where neither Finite State Machine block is active while the token is passing through output registers.