Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > State machine outputs and tri-state

Reply
Thread Tools

State machine outputs and tri-state

 
 
Grumps
Guest
Posts: n/a
 
      02-13-2008
Hi
I'm not a VHDL expert, just learning, so please don't shout.

I'm using Xilinx ISE9.2sp4 and have the following code as part of a state
machine:
CP_IN_OUTPUT_DECODE: process (state_cp_in)
begin
if state_cp_in = sta_idle then
RDY <= 'Z';
BUSY <= '0';
end if;

if state_cp_in = sta_1 then
RDY <= '0';
BUSY <= '0';
end if;

if state_cp_in = sta_2 then
RDY <= '1';
BUSY <= '1';
end if;
....
....etc

The state machine goes from sta_idle, then to sta_1, then to sta_2, etc.
RDY is a pin on the device.
During operation, I can see RDY go low in sta_1, but not high in sta_2. I
know it gets to sta_2 as I can observe BUSY. I don't think RDY is tri-stated
in sta_2 as there is an external pull-up; it just stays low. Gray encoding
is used.

If I change the RDY to rdyi (signal) and then have:
RDY <= 'Z' when state_cp_in = sta_idle else rdyi;
outside of the decode process then it all behaves itself.

Apart from lack of experience, what mistake(s) have I made?
Thanks.


 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      02-13-2008
On Feb 13, 10:24 am, "Grumps" <grumpsnoth...@hotmail.com> wrote:
> Hi
> I'm not a VHDL expert, just learning, so please don't shout.
>
> I'm using Xilinx ISE9.2sp4 and have the following code as part of a state
> machine:
> CP_IN_OUTPUT_DECODE: process (state_cp_in)
> begin
> if state_cp_in = sta_idle then
> RDY <= 'Z';
> BUSY <= '0';
> end if;
>
> if state_cp_in = sta_1 then
> RDY <= '0';
> BUSY <= '0';
> end if;
>
> if state_cp_in = sta_2 then
> RDY <= '1';
> BUSY <= '1';
> end if;
> ...
> ...etc
>
> The state machine goes from sta_idle, then to sta_1, then to sta_2, etc.
> RDY is a pin on the device.
> During operation, I can see RDY go low in sta_1, but not high in sta_2. I
> know it gets to sta_2 as I can observe BUSY. I don't think RDY is tri-stated
> in sta_2 as there is an external pull-up; it just stays low. Gray encoding
> is used.
>
> If I change the RDY to rdyi (signal) and then have:
> RDY <= 'Z' when state_cp_in = sta_idle else rdyi;
> outside of the decode process then it all behaves itself.
>
> Apart from lack of experience, what mistake(s) have I made?
> Thanks.


For combinatorial processes, the number one mistake I see is that not
all potential execution paths through the process are considered, and
there is some path that results in no assignment to an output. This
results in a latch, which can fool you especially if you are trying to
figure out which state you're in by observing other outputs, which may
be latches themselves.

Try putting a set of default assignments to all of the outputs that
are driven by the process, at the top of the process (right after the
begin), with no conditionals, etc. around them. That way, you know
there will be no latches.

Better yet, try learning to use clocked processes exclusively, and
expressing any combinatorial logic within those clocked processes;
then it is impossible to get a latch. Since your outputs will be
registered in almost all cases* you have to take that clock cycle
delay into account.

*Some synthesis tools allow you to create a combinatorial output from
a clocked process using an expression of variables assigned to a
signal after the clocked if-then clause. The resulting hardware
behavior is cycle-accurate compared to the RTL simulation.

Andy
 
Reply With Quote
 
 
 
 
Grumps
Guest
Posts: n/a
 
      02-13-2008
"Andy" <> wrote in message
news:3c5a2835-d41a-48d9-8173-...
> On Feb 13, 10:24 am, "Grumps" <grumpsnoth...@hotmail.com> wrote:
>> Hi
>> I'm not a VHDL expert, just learning, so please don't shout.
>>
>> I'm using Xilinx ISE9.2sp4 and have the following code as part of a state
>> machine:
>> CP_IN_OUTPUT_DECODE: process (state_cp_in)
>> begin
>> if state_cp_in = sta_idle then
>> RDY <= 'Z';
>> BUSY <= '0';
>> end if;
>>
>> if state_cp_in = sta_1 then
>> RDY <= '0';
>> BUSY <= '0';
>> end if;
>>
>> if state_cp_in = sta_2 then
>> RDY <= '1';
>> BUSY <= '1';
>> end if;
>> ...
>> ...etc
>>
>> The state machine goes from sta_idle, then to sta_1, then to sta_2, etc.
>> RDY is a pin on the device.
>> During operation, I can see RDY go low in sta_1, but not high in sta_2. I
>> know it gets to sta_2 as I can observe BUSY. I don't think RDY is
>> tri-stated
>> in sta_2 as there is an external pull-up; it just stays low. Gray
>> encoding
>> is used.
>>
>> If I change the RDY to rdyi (signal) and then have:
>> RDY <= 'Z' when state_cp_in = sta_idle else rdyi;
>> outside of the decode process then it all behaves itself.
>>
>> Apart from lack of experience, what mistake(s) have I made?
>> Thanks.

>
> For combinatorial processes, the number one mistake I see is that not
> all potential execution paths through the process are considered, and
> there is some path that results in no assignment to an output. This
> results in a latch, which can fool you especially if you are trying to
> figure out which state you're in by observing other outputs, which may
> be latches themselves.
>
> Try putting a set of default assignments to all of the outputs that
> are driven by the process, at the top of the process (right after the
> begin), with no conditionals, etc. around them. That way, you know
> there will be no latches.
>
> Better yet, try learning to use clocked processes exclusively, and
> expressing any combinatorial logic within those clocked processes;
> then it is impossible to get a latch. Since your outputs will be
> registered in almost all cases* you have to take that clock cycle
> delay into account.
>
> *Some synthesis tools allow you to create a combinatorial output from
> a clocked process using an expression of variables assigned to a
> signal after the clocked if-then clause. The resulting hardware
> behavior is cycle-accurate compared to the RTL simulation.


Thanks for the comments.
I may go and revisit the design with this knowledge. But, it is now working
simply be taking the tri-states out of the process.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
State machine - Vending machine - strange behaviour fenster VHDL 3 12-23-2011 09:53 AM
State Machine with single cycle pulsed outputs? Analog_Guy VHDL 24 10-01-2008 05:27 AM
State machine with control outputs john VHDL 15 02-14-2007 08:59 PM
State machine: how to stay in a state? David Lamb VHDL 1 09-15-2003 05:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57