- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to make a simple for loop to add up a parameterizable count of numbers, all in the same clock cycle( I am aware that this may not fit in a single cycle, I may split it up later to more cycles if timing issues arise.). What I am trying to do in essence is(for 3 numbers):always@(posedge clk) out=in+in+in;
I am getting the error: "j is not a constant". I am sure there is a method to do this, am I trying to do this in a wrong way? My full code is: module mymodule# (
parameter maxIter = 9,
parameter bitCount = 16
)(
input wire clk,
input wire in,
output reg out
);
initial begin
out=0;
end
integer j;
always@(posedge clk)begin
for (j=0; j<maxIter; j=j+1) begin
// I have tried this
// out= out + in;
// Then on a forum I found this
out= out + in;
// Neither works
end
end
endmodule
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You want
out= out + in[bitCount*j +: 16];- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
rozatib
Verilog specifies that if you are taking a slice, one of the indices must be a constant.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much, problem solved.

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