Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > problem with if statement

Reply
Thread Tools

problem with if statement

 
 
ledinhkha@gmail.com
Guest
Posts: n/a
 
      12-17-2005
hi all,
i got problem with my if statement. Here is my code

temp <= X"1A";

if ((X"1A" <= temp) and (X"1E" >= temp)) then
k <= X"002";
elsif ((X"1F" <= temp) and (X"23" >= temp)) then
k <= X"003";
elsif ((X"24" <= temp) and (X"28" >= temp)) then
k <= X"004";
else
k <= X"005";
end if;

then k is X"005", not like X"002" as I want. Is there anyone here can
explain why the result is like that? Do we have to notice anything with
if statement?
Thks
Kha

 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      12-17-2005
On 16 Dec 2005 23:04:09 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>hi all,
>i got problem with my if statement. Here is my code
>
>temp <= X"1A";
>
>if ((X"1A" <= temp) and (X"1E" >= temp)) then
> k <= X"002";
>elsif ((X"1F" <= temp) and (X"23" >= temp)) then
> k <= X"003";
>elsif ((X"24" <= temp) and (X"28" >= temp)) then
> k <= X"004";
>else
> k <= X"005";
>end if;
>
>then k is X"005", not like X"002" as I want. Is there anyone here can
>explain why the result is like that? Do we have to notice anything with
>if statement?
>Thks
>Kha



May you show us a little more? In particular, temp declaration.

*Because* you may be assigning an 8 bit vector ("1A") to some vector
of a different dimension, which may be valid (and may also generate
some kind of warning!).

But later you are comparing temp to an 8 bit vector. And this
comparison has no sense at all if temp has a length different from 8
bits, so you might get the result you get. Or anything.

Regards

Zara
 
Reply With Quote
 
 
 
 
ledinhkha@gmail.com
Guest
Posts: n/a
 
      12-17-2005
Thks Zara, for your reply. And here is my declaration:

signal k: std_logic_vector(11 downto 0);
signal temp: std_logic_vector(7 downto 0);

I think it is OK, but i don't know why it always drop into the last
case.
Thks
Kha

 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      12-17-2005
(E-Mail Removed) wrote:

> then k is X"005", not like X"002" as I want.


If you make temp a variable,
this will work like you expect.

-- Mike Treseler
 
Reply With Quote
 
Eric Smith
Guest
Posts: n/a
 
      12-17-2005
(E-Mail Removed) writes:
> temp <= X"1A";
>
> if ((X"1A" <= temp) and (X"1E" >= temp)) then
> k <= X"002";
> elsif ((X"1F" <= temp) and (X"23" >= temp)) then
> k <= X"003";
> elsif ((X"24" <= temp) and (X"28" >= temp)) then
> k <= X"004";
> else
> k <= X"005";
> end if;
>
> then k is X"005", not like X"002" as I want. Is there anyone here can
> explain why the result is like that? Do we have to notice anything with


Possibly you misunderstand the way signals work. When you assign a
new value to a signal (e.g., temp <= X"1A"), that doesn't change the
value of the signal "now". It schedules a change for some future time.
If no explicit time is given, the change occurs on the next delta time.

So if your assignment to temp and your conditionals are in a process and
being simulated on the same delta, the value the conditionals will see
for temp will be the old value.

If you advance to the next simuluation delta time, temp will have the
value you expect, and the conditional will work as you expect.

Remember, signals aren't variables. Signals represent a physical signal,
and can't change instantaneously. They take at least one delta time
to change. If you aren't using temp to model an electrical signal, then
you probably want it to be a variable rather than a signal.

Note that a simulation delta time is arbitrarily smaller than any time
unit you can designate, so in terms of measurable time it is
conceptually instantaneous, but in terms of simulation the next delta
time is always later, not "now".
 
Reply With Quote
 
ledinhkha@gmail.com
Guest
Posts: n/a
 
      12-17-2005
thks very much for your answer. I think that's my problem. I will try
to use variable.

 
Reply With Quote
 
ledinhkha@gmail.com
Guest
Posts: n/a
 
      12-18-2005
thks Eric, Zara and Mike!
I change the order of checking my signal (after a clock, not right
after setting it as before), and it worked well. Now I understood about
signal.
Thks and have a nice weekend to all!
Kha

 
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
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
Which of switch statement and if-else statement takes less time to execute? swaroophr@gmail.com C Programming 21 08-02-2005 09:24 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments