Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

IF statement doubt in VHDL

Status
Not open for further replies.

sp

Full Member level 6
Joined
Jan 1, 2004
Messages
396
Helped
23
Reputation
46
Reaction score
2
Trophy points
1,298
Location
Floating Garden
Activity points
4,044
i have a question to ask on the IF statement in VHDL....

Code:
if_statement ::=
IF condition THEN
sequence_of_statements
{ELSIF condition THEN
sequence_of_statements}
[ELSE
sequence_of_statements]
END IF;

above is the BNF statement...

let say we have few more "elsif" statement

IF condition1 THEN
sequence_of_statements1
ELSIF condition2 THEN
sequence_of_statements2
ELSIF condition3 THEN
sequence_of_statements3
ELSIF condition4 THEN
sequence_of_statements4
ELSE
sequence_of_statements5
END IF;

if the first condition (condition1) or either one of the condition is true... will the next few elsif statements condition be checked again? or it will just jump to the end if clause??

i have been read through the LRM but no luck...

thank you

warm regards,
sp
 

mos_halas

Newbie level 4
Joined
Nov 24, 2005
Messages
7
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,328
I think it will jump to the endif whenever any of the conditions is true and is taken.
Mostafa Halas
 

    sp

    Points: 2
    Helpful Answer Positive Rating

maksya

Full Member level 3
Joined
Jun 2, 2005
Messages
151
Helped
16
Reputation
32
Reaction score
3
Trophy points
1,298
Activity points
2,256
It will jump to END IF after some condition = TRUE. Also, IF-STATEMENT construction produses priority structure. In other words - if more than one conditions = TRUE, only the first in the list will be checked.

P.S.: Use ModelSim to debug code. It allows program stepping.
 

    sp

    Points: 2
    Helpful Answer Positive Rating

sp

Full Member level 6
Joined
Jan 1, 2004
Messages
396
Helped
23
Reputation
46
Reaction score
2
Trophy points
1,298
Location
Floating Garden
Activity points
4,044
i find this in one of my C language ebuk...

********************************************************************

Else-If
The construction

Code:
if (expression)
statement
else if (expression)
statement
else if (expression)
statement
else if (expression)
statement
else
statement

occurs so often that it is worth a brief separate discussion. This sequence of if statements is the most general way of writing a multi-way decision. The expressions are evaluated in order; if an expression is true, the statement associated with it is executed, and this terminates the whole chain. As always, the code for each statement is either a single statement, or a group of them in braces.

The last else part handles the "none of the above''or default case where none of the other conditions is satisfied. Sometimes there is no explicit action for the default; in that case the trailing

Code:
else
statement

can be omitted, or it may be used for error checking to catch an "impossible'' condition.

********************************************************************

it should b the same for the IF-ELSIF statement in VHDL........(terminates the whole chain when one condition is true)


sp
 

tkbits

Full Member level 5
Joined
Dec 4, 2004
Messages
242
Helped
39
Reputation
78
Reaction score
2
Trophy points
1,298
Activity points
2,209
When synthesizing, there is no jumping.

The sequencing of code represents priority.

So gating is added to give the earlier conditions and assignments priority over later ones.
 

    sp

    Points: 2
    Helpful Answer Positive Rating

sp

Full Member level 6
Joined
Jan 1, 2004
Messages
396
Helped
23
Reputation
46
Reaction score
2
Trophy points
1,298
Location
Floating Garden
Activity points
4,044
tkbits said:
When synthesizing, there is no jumping.

The sequencing of code represents priority.

So gating is added to give the earlier conditions and assignments priority over later ones.

however when one condition is true... other will not be selected if they are true after the first "true"??


sp
 

tkbits

Full Member level 5
Joined
Dec 4, 2004
Messages
242
Helped
39
Reputation
78
Reaction score
2
Trophy points
1,298
Activity points
2,209
That is correct.
 

    sp

    Points: 2
    Helpful Answer Positive Rating

nee_naresh04

Member level 2
Joined
Dec 15, 2005
Messages
47
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,657
this is a conditional operator statement...more over VHDL is capable of CUCONCURRENT SIGNAL ASSIGNMENTAND EXECUTION supporting language..as per conditional statement concern ..if the condition is checked and if true corresponding statements executed..so as concern to concurrent signal process..all the statements checked simulteneously....so i think there is no case of jumping...concurrently all r processed but the statements corresponding true conditionalised case only will execute..
 

Iouri

Advanced Member level 2
Joined
Aug 17, 2005
Messages
682
Helped
87
Reputation
174
Reaction score
8
Trophy points
1,298
Activity points
4,814
Using to many times if/elsif/elsif it is not a good prcatice, better choise will be to use
case construction. look again in your code and try to replace, also consider something like this

a<= b when (condition1) else
c when (condition2) else
............

N when condition N;


Good lack
 

sp

Full Member level 6
Joined
Jan 1, 2004
Messages
396
Helped
23
Reputation
46
Reaction score
2
Trophy points
1,298
Location
Floating Garden
Activity points
4,044
nee_naresh04 said:
this is a conditional operator statement...more over VHDL is capable of CUCONCURRENT SIGNAL ASSIGNMENTAND EXECUTION supporting language..as per conditional statement concern ..if the condition is checked and if true corresponding statements executed..so as concern to concurrent signal process..all the statements checked simulteneously....so i think there is no case of jumping...concurrently all r processed but the statements corresponding true conditionalised case only will execute..

concurrent if it is not in the process... all statement is synthesized but not all are run(hope this word is ok).. when one condition is true, no more is check.... there is a priority encoder...

like wad u mention
Code:
concurrently all r processed but the statements corresponding true conditionalised case only will execute
wad if 2 condition is true?...

sp
 

Iouri

Advanced Member level 2
Joined
Aug 17, 2005
Messages
682
Helped
87
Reputation
174
Reaction score
8
Trophy points
1,298
Activity points
4,814
wad if 2 condition is true?...
Then, which one do you think should executed?
If they have to execude both than there is no reason to have them under the same process or concurent signal assigment, otherwise, introduce third conditions.......


Good lack
 

sp

Full Member level 6
Joined
Jan 1, 2004
Messages
396
Helped
23
Reputation
46
Reaction score
2
Trophy points
1,298
Location
Floating Garden
Activity points
4,044
Iouri said:
If they have to execude both than there is no reason to have them under the same process or concurent signal assigment, otherwise, introduce third conditions.......


Good lack

hi, no offense, sometimes we might hav few independent condition n some of them might b true... so there is priotrity...e.g:

Code:
if (i hav big head) then
statement 1;
elsif (i hav big mouth) then
statement 2;
elsif (i hav bi leg) then
statement 3;
else (do nth);

as we can see, few condition might b true n we only one statement to execute when first true is met(and terminate the whole chain)....so only the elsif statement can do this, using "if if if if" statement will generate wad u think...all true condition will be execute...

sp
 

Resistance

Member level 4
Joined
Dec 24, 2005
Messages
74
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,288
Activity points
2,034
hi,
i think if case is true automatically then else is not checked.. so same hols good with elsif too..

regards..
 

mystique_unbound

Junior Member level 3
Joined
Dec 25, 2005
Messages
25
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,281
Activity points
1,546
IF statements are generally raelized using parallel architecture like PRIORITY ENCODERS . so obviously if one statement is true the the other statements with lower priority are negkected . the order of priority will follow the structure .
It is similar to that of case statements .

In verilog you can make the if statements resulting in latches but be careful it may lead to race conditions .
 

    sp

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top