Why is my state machine output being synthesized away?

In summary: I would have an input port called "in" and an output port called "out". Then I would have two Verilog blocks (ie. a state machine) that looked like this:entity Moore is port in is input; port out is output begin
  • #1
keith03
31
0
This is my first state machine that has an input large than one bit. The simulation tool says that I synthesize my output away. I think I understand why, but don't really know how to fix it.

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--
entity trimoore is
port
(
clk : in std_logic;
x : in std_logic_vector (1 downto 0);
------ mode : in std_logic_vector (2 downto 0);
q : out std_logic_vector(2 downto 0)
);
end trimoore;
--
architecture behave of trimoore is

type state_type is (A, B, C);
signal state: state_type;
begin
process (clk)
begin

if (clk'event and clk ='1') then
case state is
when A =>
if x<="11" then state <= A;
else state <= B;
end if;
when B =>
if x <= "11" then state <= A;
elsif x <= "00" then state <= B;
else state <= C;
end if;
when C =>
if x <= "00" then state <= B;
elsif x <= "01" then state <= C;
else state <= A;
end if;
end case;
end if;
end process;

with state select
q <= "000" when A,
"001" when B,
"110" when C;
 
Engineering news on Phys.org
  • #2
keith03 said:
This is my first state machine that has an input large than one bit. The simulation tool says that I synthesize my output away. I think I understand why, but don't really know how to fix it.

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--
entity trimoore is
port
(
clk : in std_logic;
x : in std_logic_vector (1 downto 0);
------ mode : in std_logic_vector (2 downto 0);
q : out std_logic_vector(2 downto 0)
);
end trimoore;
--
architecture behave of trimoore is

type state_type is (A, B, C);
signal state: state_type;
begin
process (clk)
begin

if (clk'event and clk ='1') then
case state is
when A =>
if x<="11" then state <= A;
else state <= B;
end if;
when B =>
if x <= "11" then state <= A;
elsif x <= "00" then state <= B;
else state <= C;
end if;
when C =>
if x <= "00" then state <= B;
elsif x <= "01" then state <= C;
else state <= A;
end if;
end case;
end if;
end process;

with state select
q <= "000" when A,
"001" when B,
"110" when C;


Can you post a state diagram that goes with the code? That would make it easier to try to see what is getting optimized out.
 
  • #3
10 is a don't care input. I have attached a pdf of the state diagram. Also, I want three separate iterations of this to be selected from a three bit input. Could I do case statements for entire state machines? thanks ahead of time. actual output is wrong...sorry. the real problem is that the states don't change in simulation.
 

Attachments

  • state diagram.pdf
    5 KB · Views: 214
  • #4
I also get a warning stating that input x does not drive logic. the code is correct to my understanding. Could this maybe be the compiler?
 
  • #5
OK, I'm more of Verilog person and might be wrong, but let me tell you what I observe.

1. you use "if x<=00 then ...". Isn't <= for assignment ?(Again I'm not VHDL person, so forgive me).
2. What does the following mean ?

when A =>
if x<="11" then state <= A;
else state <= B;

Does it mean when you are in state A and X=11, it stays in A, otherwise goes to B ? if so, it doesn't match the state diagram you posted. The same for B and C too.

3. Regarding stating all the possible states, it probably depends on the compiler. In Verilog, it is always recommended to put all the possible states(even with default statement) to avoid the latch inference.

4. Your output is q. You didn't assign anything to q in the code so the tool thinks it can optimize it away. Assuming from the name, you're trying to make a Moore machine. You need to assign the value to q based on the current state.
 
Last edited:
  • #6
About the only advice I could give (I'm a verilog person as well) is that I normally will separate the actual register assignments , (the clocked state memory) from the continuous assignments or the next state logic. This will also help or force the compiler to choose a one hot state machine or not. L
 
  • #7
sorry for the delayed replies.

I used a different compiler, and everything came out fine. I would like to addres the questions that were asked though.

I made a horrible mistake of posting the wrong version of the code, and that is why is does not match the state diagram.

To lostinxlation: you are correct in your interpretation of the VHDL for the states, but the q is assigned values through the select statements at the end of the code.

To lifeattthesha: i had tried to separate them before, but I was getting errors. Turns out that the Quartus free edition that I had been using from school, needed a vouple of updates. I used the trial of Xilinx ISE and everyhting worked fine.

Thanks for the input from both!
 

1. What is a state machine?

A state machine is a mathematical model used to represent the behavior of a system. It consists of a set of states, transitions between states, and actions that occur in response to these transitions. State machines are commonly used in computer science and engineering to describe the behavior of software systems.

2. How does a state machine work?

A state machine operates by transitioning between different states based on external inputs or events. Each state can have associated actions or behaviors that are executed when the state is active. The transitions between states are often triggered by specific conditions or events.

3. What are the benefits of using a state machine?

State machines offer several benefits, including clear representation of complex systems, easy debugging and testing, and the ability to handle multiple inputs and outputs. They also promote modularity and can simplify code by breaking it down into smaller, manageable chunks.

4. How do I create a state machine?

The process of creating a state machine involves identifying the different states of the system, the events that trigger transitions between states, and the actions that occur in each state. This can be done using a visual representation, such as a state diagram, or through writing code that implements the state machine logic.

5. What are some common applications of state machines?

State machines can be applied to a wide range of systems, including software applications, control systems, and manufacturing processes. They are commonly used in the development of video games, graphical user interfaces, and data processing systems. They can also be found in everyday devices such as vending machines and traffic lights.

Similar threads

  • Advanced Physics Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
Replies
5
Views
10K
  • Electrical Engineering
Replies
4
Views
1K
Replies
4
Views
834
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
11K
  • Electrical Engineering
Replies
2
Views
2K
  • General Engineering
Replies
2
Views
4K
Back
Top