State machine: how to stay in a state?

Discussion in 'VHDL' started by David Lamb, Sep 15, 2003.

  1. David Lamb

    David Lamb Guest

    Hi,
    When writing a vhdl state machine, is there an easy way to stay in a given
    state for n clock cycles? I always end up having another process with a
    counter, enable the counter in that particular state, and having a <if count
    = n> statement in the state transition process. However, the counter needs
    to be reset in the state before and it ends up being very confusing. Is it
    possible to do this directly in the state machine process?

    Thanks

    Here is the type of state machine I usually use:

    FSM_transitions: PROCESS (reset, clock) -- synchronous FSM
    BEGIN
    If reset = '1' THEN
    state <= Rst;
    ELSIF(clock'EVENT AND Clock = '1') THEN
    CASE state IS
    WHEN Rst =>
    state <= Idle;
    WHEN Finish =>
    state <= Idle;
    END CASE;
    END IF;
    END PROCESS;

    FSM_OUTPUTS: PROCESS(state)
    BEGIN
    CASE state IS
    WHEN Rst =>
    count_reset <= '1';
    WHEN Finish =>
    Done <= '1';
    END CASE;
    END PROCESS;
     
    David Lamb, Sep 15, 2003
    #1
    1. Advertising

  2. David Lamb

    MM Guest

    David,

    Here is your code slightly modified:

    FSM_transitions: PROCESS (reset, clock) -- synchronous FSM
    variable count :integer;
    BEGIN
    If reset = '1' THEN
    state <= Rst;
    ELSIF(clock'EVENT AND Clock = '1') THEN
    CASE state IS
    WHEN Rst =>
    count := IDLE_TIME;
    state <= Idle;
    WHEN Idle =>
    count := count -1;
    if count=0 then
    state <= Finish;
    count :=IDLE_TIME;
    end if;
    WHEN Finish =>
    state <= Idle;
    END CASE;
    END IF;
    END PROCESS;

    Remember to watch where you reset the counter so it works correctly every
    time.


    /Mikhail



    "David Lamb" <> wrote in message
    news:bk4mdp$h5k$...
    > Hi,
    > When writing a vhdl state machine, is there an easy way to stay in a given
    > state for n clock cycles? I always end up having another process with a
    > counter, enable the counter in that particular state, and having a <if

    count
    > = n> statement in the state transition process. However, the counter needs
    > to be reset in the state before and it ends up being very confusing. Is it
    > possible to do this directly in the state machine process?
    >
    > Thanks
    >
    > Here is the type of state machine I usually use:
    >
    > FSM_transitions: PROCESS (reset, clock) -- synchronous FSM
    > BEGIN
    > If reset = '1' THEN
    > state <= Rst;
    > ELSIF(clock'EVENT AND Clock = '1') THEN
    > CASE state IS
    > WHEN Rst =>
    > state <= Idle;
    > WHEN Finish =>
    > state <= Idle;
    > END CASE;
    > END IF;
    > END PROCESS;
    >
    > FSM_OUTPUTS: PROCESS(state)
    > BEGIN
    > CASE state IS
    > WHEN Rst =>
    > count_reset <= '1';
    > WHEN Finish =>
    > Done <= '1';
    > END CASE;
    > END PROCESS;
    >
    >
     
    MM, Sep 15, 2003
    #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. Weng Tianxiang
    Replies:
    7
    Views:
    1,114
    Mike Treseler
    Nov 25, 2003
  2. Weng Tianxiang
    Replies:
    3
    Views:
    1,419
    Weng Tianxiang
    Jul 25, 2006
  3. Grumps
    Replies:
    2
    Views:
    692
    Grumps
    Feb 13, 2008
  4. axr0284
    Replies:
    6
    Views:
    634
    Mike Treseler
    Jul 8, 2008
  5. fenster
    Replies:
    3
    Views:
    1,164
    jeppe
    Dec 23, 2011
Loading...

Share This Page