- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
They are both functionally equivalent. Write it how you want. Just make sure you comment it well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is
if(!iRST or (done == 1) ) The logical or operator is ||
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page