omara007
Advanced Member level 4
- Joined
- Jan 6, 2003
- Messages
- 1,237
- Helped
- 50
- Reputation
- 102
- Reaction score
- 16
- Trophy points
- 1,318
- Location
- Cairo/Egypt
- Activity points
- 9,716
integer verilog loop
Hi folks
I'm currently having the following MUX Verilog code:
I was asked to convert this code so as to be of a generic number of input ports instead of being fixed to 8 ports. The new range of ports is from 1 to 8 ports.
Here is my new code:
The problem appeared when I tried to synthesize the code using Synplify. I got the following error regarding the loop:
and it pointed to the "index" integer in this statement:
So, what could be the problem here ? .. and if there is a problem about using an integer .. or a synthesizable while loop .. please advise regarding a different approach to parametrize this code ..
Hi folks
I'm currently having the following MUX Verilog code:
Code:
input [29:0] port0;
input [29:0] port1;
input [29:0] port2;
input [29:0] port3;
input [29:0] port4;
input [29:0] port5;
input [29:0] port6;
input [29:0] port7;
reg [7:0] sel;
reg [29:0] mux8to1; //Multiplexer 8 to 1
always @ (in0 or in1 or in2 or in3 or in4 or in5 or in6 or in7 or sel)
casex( sel )
8'bxxxxxxx1: mux8to1 = port0; // port0 selected
8'bxxxxxx10: mux8to1 = port1; // port1 selected
8'bxxxxx100: mux8to1 = port2; // port2 selected
8'bxxxx1000: mux8to1 = port3; // port3 selected
8'bxxx10000: mux8to1 = port4; // port4 selected
8'bxx100000: mux8to1 = port5; // port5 selected
8'bx1000000: mux8to1 = port6; // port6 selected
8'b10000000: mux8to1 = port7; // port7 selected
default: uumux32to1sp = 0;
endcase
I was asked to convert this code so as to be of a generic number of input ports instead of being fixed to 8 ports. The new range of ports is from 1 to 8 ports.
Here is my new code:
Code:
input [(30*`NUMBER_OF_PORTS)-1:0] portx;
reg [NUMBER_OF_PORTS-1:0] sel;
reg [29:0] mux8to1;
integer index;
always @ (portx or sel) begin
index = 0;
while (sel[index] == 0) begin
index = index + 1;
end
mux8to1 = portx[(index*30)+29:(index*30)];
end
The problem appeared when I tried to synthesize the code using Synplify. I got the following error regarding the loop:
Code:
Range bounds are not constant.
and it pointed to the "index" integer in this statement:
Code:
mux8to1 = portx[(index*30)+29:(index*30)];
So, what could be the problem here ? .. and if there is a problem about using an integer .. or a synthesizable while loop .. please advise regarding a different approach to parametrize this code ..