- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I wrote a simple code for multiplication and wanted to store the result in an array. The code does not show any error during compilation, but the output is zeros. Could some one tell me why I am unable to store the result in array. The code is as follows. always @(posedge clk)begin
for(i=0;i<5;i=i+1)
begin
temp= x*h[i];
end
y=temp[0]+temp[1]+temp[2]+temp[3]+temp[4];
out[n]=y;
n=n+1'b1;
end
endmodule
"Y" is my actual output and out is a register (array) in which I would like to store the result of y. When I run this code, the value of y is displayed, but out is zeros. counter "n" is a register. I would appreciate any suggestions regarding this. Thank you, Ambrin
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did You simulate the design?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. I simulated in Modelsim.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try to do the same without using the for structure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Aprado,
Now the result in stored in array if I don't use for structure. But could you explain why this happens only without for structure. Also I am actually designing FIR filter which is supposed to have 100 coefficients. That is why I used for structure, because without that I will have to manually write 100 multiplications. I appreciate your help.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's no obvious reason for failure of your code. But you're showing only a snippet and there may be trivial problems like not initializing n.
If you extend the code to 100 multiplications (and respective additions), it will hardly synthesize with resonable clock speeds without pipelining the adders.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As far as i know FOR shouldn't be used in hardware.. BUT the way you are using is pretty much like a FOR GENERATOR in VHDL which works fine (at least in VHDL it is the equivalent of expanding the code)
You might be using the for in an unaproriated way (i am working more with VHDL lately and i've never used FOR in verilog)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Loops can be easily used in designing hardware, because synthesizer will unwrap the loop and do the synthesis with all the possible loop variable values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- In a HDL (hardware definition language), iteration schemes have a different meaning than in procedural programming languages. They don't define sequential processing of the included statements but are a method to define parallel processing. Even if the iteration construct would be accepted by the Veriolog compiler (when using constant loop parameters), the resource requirement would go beyond any meaningful FPGA size. --- Quote End --- By FVM in another thread. Yeah, it will just unwrap the loop.. so the loop needs to be finite, have a low size and to be constant. It is unrolled BEFORE synthesis
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