Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

State machine transitioning into illegal state

I am working with a simple state machine with 4 states. The state machine is properly detected by Altera's state machine optimizer, and the state diagram it produces is correct.

When I probe this state machine with Signaltap, I find that it's entering an illegal state (all 4 state signals are low). Signaltap image is attached, triggered when all states == 0. This is an intermittent problem that does not occur every time.

This state machine does have asynchronous inputs (transmit_req), but they are all synchronized with code similar to that below.

always @(posedge Clk, negedge Rst_)
	if (~Rst_)
		safe_transmit_req <= 2'b0;
	else begin
		safe_transmit_req	<= transmit_req;
		safe_transmit_req	<= safe_transmit_req;
	end

The transition that is failing is conditional on ~safe_transmit_req[1]. It leaves the state, but instead of going to the correct state (st_fabric_Idle), it enters some unknown state.

st_fabric_Ack: begin
	fabric_transmit_ack	= 1'b1; 
	if (~safe_fabric_transmit_req)	begin	
		sm_tx_fabric_next	= st_fabric_Idle;
	end

The resets aren't shown but, even if it was getting reset, it should transition to the idle state. Does anyone see any glaring errors that would cause it to enter an illegal state?

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I made this a Moore FSM, and the output is only active during a single state - however thinking about it I realized that it doesn't matter if these are glitching, as they are already registered at the input of the receiving FSM module.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I didn't read all the posts, but one-hot state-machines will have an all 0s state when looked at in SignalTap or in a timing simulation. The reason is that the registers power up to all 0s. In your state-diagram, the idle state is shown as being all 0s. In essence, it's just like a normal one-hot except the lsb is inverted:

    0000

    0011

    0101

    1001

    Synthesis still decodes off a single bit, but for the idle state we just decode if the LSB is a 0 instead of if it's a 1.

    Also, if bringing asynchronous signals into a SM, I would recommend double-registering them in the new domain to shake out metastability.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Problem fixed.

    It turns out that not registering/synchronizing signals across clock domains was indeed the problem, and in more than one location. In one FSM I was only single registering the input, and in another I was reading the count from the wrong side of a DCFIFO.

    Lesson learned: Be very vigorous about following proper clock domain crossing boundaries and follow Altera's recommendations as laid out in Application Note 473.