mrflibble
Advanced Member level 5
- Joined
- Apr 19, 2010
- Messages
- 2,720
- Helped
- 679
- Reputation
- 1,360
- Reaction score
- 652
- Trophy points
- 1,393
- Activity points
- 19,551
Edited from an older reply to a post on the same subject...
What kind of "for loop" do you want? Basically two options:
1 - Do you want something that loops in time?
2 - Do you want to unroll logic, so that you get multiple pieces of logic that execute simultaneously side by side (loop in space)?
Option 1) is typically what people want. And then they try (and fail) to use the for loop keyword in verilog for that. This is precisely NOT how it works.
When you use the for loop construct in verilog you actually get option 2), unrolling logic.
Summarizing: A for loop in verilog does NOT loop temporally. A for loop in verilog loops spatially.
If you want something that loops in time you should use a counter.
Or to put that another way... If you do a for loop of 5 in verilog you will get 5 side-by-side copies of the same logic on the fpga die. If on the other hand you have a counter running 0,1,2,3,4,0,1,2,3,4,.... then you can make something that loops/repeats in time, similar to how you would expect a for loop in a typical imperative programming language to behave.
What kind of "for loop" do you want? Basically two options:
1 - Do you want something that loops in time?
2 - Do you want to unroll logic, so that you get multiple pieces of logic that execute simultaneously side by side (loop in space)?
Option 1) is typically what people want. And then they try (and fail) to use the for loop keyword in verilog for that. This is precisely NOT how it works.
When you use the for loop construct in verilog you actually get option 2), unrolling logic.
Summarizing: A for loop in verilog does NOT loop temporally. A for loop in verilog loops spatially.
If you want something that loops in time you should use a counter.
Or to put that another way... If you do a for loop of 5 in verilog you will get 5 side-by-side copies of the same logic on the fpga die. If on the other hand you have a counter running 0,1,2,3,4,0,1,2,3,4,.... then you can make something that loops/repeats in time, similar to how you would expect a for loop in a typical imperative programming language to behave.