Simple question, reset a counter

Discussion in 'VHDL' started by Dan, Nov 19, 2007.

  1. Dan

    Dan Guest

    Hi,

    I've created a FSM and, inside it, a counter to count the clock cycles
    between transitions.

    Maybe it's too simple but I don't see how can I reset the *counter* from
    inside the state machine?

    Example:

    entity FSM is
    Port ( Clk : in STD_LOGIC;
    Reset : in STD_LOGIC;
    ...);

    end FSM;

    architecture Behavioral of FSM is

    component Counter
    port ( Clk : in STD_LOGIC;
    Clear : in STD_LOGIC;
    ....);
    end component;

    .....

    U1: Counter port map (<I don't know what signals include here>);

    .....

    when S2 =>
    if .... then
    Next_State <= S3;
    Signal <= '1'; -- Reset the counter
    end if;

    .....

    The "Reset" signal of the FSM returns to state S0, so that's not what I
    want, I only want to reset the counter.

    I'm stuck, any ideas?
    Dan, Nov 19, 2007
    #1
    1. Advertising

  2. On Mon, 19 Nov 2007 19:33:02 +0100, Dan wrote:

    >I've created a FSM and, inside it, a counter to count the clock cycles
    >between transitions.
    >
    >Maybe it's too simple but I don't see how can I reset the *counter* from
    >inside the state machine?


    You've already done it! Create a signal that's an output from
    the FSM - as you've done, in your transition from state S2 to S3.
    Use that signal directly as the counter's reset.

    Even better, don't instantiate a counter at all. Instead,
    provide a variable in your FSM process that counts down on
    every clock. Some states (the states that need the counter)
    will wait until the counter hits zero before proceeding.
    Transitions into those states will preset the counter
    to an appropriate timeout value. This has been discussed
    many times here, including at least one very recent occasion.
    --
    Jonathan Bromley, Consultant

    DOULOS - Developing Design Know-how
    VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

    Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK

    http://www.MYCOMPANY.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Nov 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The Eeediot
    Replies:
    3
    Views:
    2,230
    =?Utf-8?B?UnVsaW4gSG9uZw==?=
    Dec 22, 2004
  2. Paul Rubin

    Simple thread-safe counter?

    Paul Rubin, Apr 2, 2005, in forum: Python
    Replies:
    16
    Views:
    1,283
    Michael Hudson
    Apr 5, 2005
  3. coldplay112
    Replies:
    2
    Views:
    691
    rickman
    Sep 25, 2006
  4. Thunder
    Replies:
    4
    Views:
    746
    Jonathan Bromley
    Jun 29, 2007
  5. George2
    Replies:
    1
    Views:
    796
    Alf P. Steinbach
    Jan 31, 2008
Loading...

Share This Page