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

ID 683337
Date 10/02/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

14.6.6.4. Implementing a One Shot Counter with the Finite State Machine

If a control unit in a design needs to send a control pulse at some fixed number of cycles after the first valid sample (or coming out of reset), implement a one-shot counter.

Procedure

  1. Implement the following Finite State Machine block definition:
    # one shot counter
    require version 23.3
    netlist
    transitions OneShot : q
        state S0
            default S1 0
        state S1
            default S2 0
        state S2
            default S3 0
        state S3
            default S4 0
        state S4
            default S5 0
        state S5
            default S6 0
        state S6
            default S7 0
        state S7
            default S8 0
        state S8
            default S9 0
        state S9
            default S10 0
        state S10
            default Stop 0
        state Stop
            default Halted 1
        state Halted
            default Halted 0
    end
    
    This code allows you to send control signals after a small number of cycles but it is verbose and is difficult to parameterize in setup scripts.
  2. Alternatively, implement the Finite State Machine block with DSP Builder primitive blocks such as the Sequence block.
    # One-shot finite state machine to be used
    # with an external counter or sequence block
    require version 23.3
    netlist
    transitions OneShot : q
        state Start
            default Next 0
        state Next
            default Stop 1
        state Stop
            default Stop 0
    end
    
    The control pulse sends after 50 clock cycles. Even though the Sequence block repeats every 100 cycles, the one-shot Finite State Machine produces the control signal only once.
  3. Implement the following code so the Finite State Machine blocks incorporate ForLoop blocks internally to achieve the same effect:
    Figure 144. One-shot Counter
    # A one shot counter using a for-loop for the initial delay
    require version 23.3
    netlist
    for x 0 < 50
    end
    transitions OneShot : q
        state Start
            default Next 0
        state Next
            default Stop 1
        state Stop
            default Start 0
    end