Continue to Site

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.

How to NOT use while() loops in verilog (for synthesis)?

Status
Not open for further replies.

user_asic

Advanced Member level 4
Joined
Nov 13, 2009
Messages
100
Helped
7
Reputation
14
Reaction score
2
Trophy points
1,298
Location
Canada
Activity points
1,836
I've gotten in the habit of developing a lot testbenches and use for() and while() loops for testing purpose. Thats fine. The problem is that I've taken this habit over to coding for circuits which should be synthesizable. XST and others refuse to synthesize code (without additional modification to synthesis parameters) such as:

Code:
while (num < test_number)
     begin
     .
     .
     .
     num = num+1;
     end

This is bad coding style because to the synthesizer test_num is an int with value 2^32! or it sees it as unbounded parameter. Either way, its a bad coding habit. But I'm so used to doing this in C and testbenches. What would be the equivalent synthesizable of code of the above code segment?

Thank you
 

for loops are synthesizable.

Code:
reg [3:0] num;
reg [4:0] test_number = 4'hF;

initial
  for(num = 0; num < test_number; num = num + 1)
    begin
      ///////
    end
 

I dont see how the for() loop is any different. test_number is entered at run-time.
 

I'm not sure what you're asking then.
 

The loop will not be in a always or initial block.

I need a synthesizable equivalent of while() loop I posted.
 

Well the while module will have to be inside an always block in synthesizable or non-synthesizable code. Same with the for loop.
 

This is how I see it.

You will have to increment num under clock control and if the num value is less than num_test then execute the code.

An always block will be enough. You have to take define num and num_test such that they can hold the largest value you can pass at run time.

--
Amr Ali
 

Hey user_asic

u can try if condition for sysnthasizable RTL as shwn

always @ (posedge clk)
if(num < test_number)
begin
.
.
.
num <=num + 1;
end
 

    user_asic

    Points: 2
    Helpful Answer Positive Rating
yea kalyansumankv, thats how I managed to solve it.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top