Simple question, reset a counter

D

Dan

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?
 
J

Jonathan Bromley

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
(e-mail address removed)
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top