Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17267 Discussions

Verilog syntax if statement

Altera_Forum
Honored Contributor II
4,010 Views

what is the correct syntax for if statement with multiple conditions? 

 

I've written(which works): 

 

always@(posedge iGO or negedge iRST)//on key press event begin if(!iRST) go_en <= 0; else if (done == 1) go_en <= 0; else begin if(iGO) //if go key pressed enable ADC go_en <= 1; end end 

 

but i wonder what is the syntax to write it as: 

 

always@(posedge iGO or negedge iRST)//on key press event begin if(!iRST or (done == 1) ) go_en <= 0; else begin if(iGO) //if go key pressed enable ADC go_en <= 1; end end
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
2,495 Views

They are both functionally equivalent. Write it how you want. Just make sure you comment it well.

0 Kudos
Altera_Forum
Honored Contributor II
2,495 Views

the second method gives me an error, i think the error was something regarding missing semicolon, which might be caused by the or (done ==1)

0 Kudos
Altera_Forum
Honored Contributor II
2,495 Views

i'm curious about both codes. the rtl view of the first one show a d flip-flop: iRST - async as reset, iGO as clk, done as data input and go_en as q. 

 

as mhouse1 saids, second code gives an error, i think because the "or" operator ( in verilog we have '|' ). i modified so it didn't give errors: 

 

module verilog_ffd(igo, irst, go, done); 

input igo; 

input irst; 

output go; 

input done; 

 

reg go_en; 

wire caca; 

/* 

always@(posedge igo or negedge irst)//on key press event 

begin 

if(!irst) 

go_en <= 0; 

else if (done == 1) 

go_en <= 0; 

else 

begin 

if(igo) //if go key pressed enable adc 

go_en <= 1; 

end 

end*/ 

always@(posedge igo or negedge caca)//on key press event 

begin 

if(!caca) 

go_en <= 0; 

else 

begin 

if(igo) //if go key pressed enable adc 

go_en <= 1; 

end 

end 

 

assign go = go_en; 

assign caca = irst | (done != 1); 

endmodule 

 

but the rtl view show a different behavior ( as expected ): -iGO as clock, data input fixed '1', and reset is ( not iRST and done ). In the second done was an async input.
0 Kudos
Altera_Forum
Honored Contributor II
2,495 Views

The problem is 

 

 

if(!iRST or (done == 1) ) 

 

 

The logical or operator is ||
0 Kudos
Reply