Altera_Forum
Honored Contributor
13 years agoVHDL -> Verilog for loop conversion
I have been attempting to convert some code I have written from VHDL to Verilog without much success. My main stumbling block is the for loops in my VHDL code. My FOR loops have a much larger index, I am using 0 to 1 for simplicity.
Simplified VHDL example:PROCESS(CLK)
BEGIN
IF (rising_edge(CLK)) THEN
FOR I IN 0 TO 1 LOOP
data_s(((8*I)+7) DOWNTO (8*I)) <= data_s(((8*I)+7) DOWNTO (8*I)) + '1';
END LOOP;
END IF;
END PROCESS; When this is simplified by the compiler (during analysis and synthesis), it looks like this: PROCESS(CLK)
BEGIN
IF (rising_edge(CLK)) THEN
data_s(7 DOWNTO 0) <= data_s(7 DOWNTO 0) + '1'
data_s(15 DOWNTO 8) <= data_s(15 DOWNTO 8) + '1'
END IF;
END PROCESS; I have ended up generating code that I think is close, but still has issues: always @(*) begin : data_increment_loop_I
integer i;
for(i=0;i<1;i=i+1) begin : Loop_lane_increment_i
data_plus_1_s = data_s + 1;
end
end
always @ (posedge CLK) begin
data_s <= data_plus_1_s;
end I end up with "Range must be bounded by constant expressions." on data_plus_1_s and data_s. Suggestions on better ways to code this (other than write them all out individually) would be most appreciated.