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.

Can this be done by any mean in verilog

Status
Not open for further replies.

hallovipin

Member level 1
Joined
Dec 23, 2009
Messages
40
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,638
input [11:0] adc_data_in;
reg [15:0] sum, check_for_loop;
reg [7:0] j;
reg crossed_sum_threshold;

always @(posedge clk) begin

if(sum>15'b001111111111111) begin
sum=0;
crossed_sum_threshold=~crossed_sum_threshold;
end
else
sum=sum+adc_data_in;
end

always @(crossed_sum_threshold)
for(j=8'd0;j<8'd128;j=j+1) begin
check_for_loop = check_for_loop + sum +j; ///// problem lies here
end



As per SYNTHESIS RULES for loop can only accumulate constants not variable
like:

check_for_loop=check_for_loop+15'd6;

It can not accumulate variables.

What should I do to acheicve this accumulation. Always block can accumulate variable also but always blocks can not be nested (I cant put one always block inside other). One always block has already been used for detecting that sum value has crossed threshold.

Can anybody suggest something
 

what do you think your code is doing?

eg, from where i sit, it seems to do:
cfl = cfl*128 + sum*128 + k.

but it does this in a non-ideal manner, and at odd times.
 

I have not posted the exact code since its quite big. I had problem with such kind of execution, where a for loop was accumulating a variable. Above code is just a reference for that.

Can u help me finding a solution??
 

It's hard to guess the intended pupose of your code, because you're completely misunderstanding the purpose of the Verilog "for loop" iteration scheme. It's a mean to generate parallel logic, not a sequence in time. A for loop is always "executed" within a single clock cycle.

Typically, a counter which is incremented each clock cycle, is the way to go.
 

that still depends, what do you think the above code is doing?

I have an interpretation for what I think the code does. This may be very different than what the code is intended to do.


However, the most likely answer is that HDL is not a programming language. Most likely you have bad expectations on what a for-loop can be used for. Most likely, you want to be able to add N elements in N cycles (accumulating 1 new value per cycle).

as written, the for loop would imply a fairly complex operation that has to complete within 1 cycle.
 

The best advice when learning HDL:

Draw the circuit first with what you intend to do, then write the HDL of your circuit, never the other way round.
 

But my query still remains unanswered.

If not for loop can it be done by any other way.

and it is impossible to draw diagram for complex DSP applications, its easier to write behavioral codes and people are using FPGAs for DSP applications. I think purpose of behavioral is not to make user too worry about circuit.
I may be wrong too..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top