FSM problems

Guest #6023190
HI,
during the development of FSM sometimes I forget to declare the status 
of variable (i.e. std_logic). Just as example:
- state n: a<='1'; b<='0';
- state m: a<='0';
in the state m "b" is not declared and then it could assume any value.

Is there a way to chose the default value for a signal, in this way if I 
forget to set it in a state the value will be assumed as specified 
default?
thank you
maurizio stefani
Guest #6023261
You probably describe the state machine inside a clocked process. Then 
an unassigned signal just keeps its value. If you go to state m from 
state n, b will still be '0'.

If you want to define a default value, assign the value at the beginning 
of the process. In a process only the last assigned value is assigned to 
a signal.
1
process(clk) begin
2
  wait until rising_edge(clk);
3
  a<='0';
4
  b<='1';
5
  case state is
6
    when n =>
7
      a<='1';
8
      b<='0';
9
    when m =>
10
      a<='1';
11
  end case;
12
end process;

When state is n, b will be '0', when state is m, b will be '1', because 
'1' is assigned to b and it is not overwritten later.

Just for clarification:
1
process begin
2
  a<='1';
3
  a<='0';
4
  a<='1';
5
  a<='0';
6
end process;
'a' will always be '0'. It will not toggle. Only the last assignment 
is executed.

Reply

A question of your own? This thread is over 7 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.