parameterized mux issue

D

daluu

Guest
I'm working on a lab which has given parameterized mux code but has compile
problems in ModelSim and we are supposed to fix it.

The code below gives a range must be bounded by constant expression
error:

-----------
for(Index = 0; Index < N_channel; Index = Index +1)
if(Index == Sel)
D_out = D_in[Data_width*Index+Data_width-1:Data_width*Index];
else
D_out = 8'bx;
------------

I found a possible workaround in from a post in this forum, don't have URL
at moment, but that just fixes the bound error but the simulation is
incorrect.

I'm using a inner for loop to handle assigning the data from input to
output bit by bit. I believe the problem lies in the outer for loop or the
if/else statement.

When I run a simulation in modelsim, the output is always 8'bx unless Sel
= 3. When sel = 3, then it selects the appropriate section of input as
output. So it looks like 90% of the time, all output is set by the else
section. And I have set a range of values for Sel in the testbench but
like I said only sel=3 outputs the right result other sel values come up
as 8'bx when it shouldn't.

Did I miss something in the code that causes this?
 
"daluu" <cuuld@yahoo.com> wrote in message news:<62a18a5d3c96f3e1b48dbce58ce157f3@localhost.talkaboutprogramming.com>...
I'm working on a lab which has given parameterized mux code but has compile
problems in ModelSim and we are supposed to fix it.

The code below gives a range must be bounded by constant expression
error:

-----------
for(Index = 0; Index < N_channel; Index = Index +1)
if(Index == Sel)
D_out = D_in[Data_width*Index+Data_width-1:Data_width*Index];
else
D_out = 8'bx;
------------

The D_out does not seem to be a single bit, is it ok?
 
Suppose your Sel is 2.
Your loop will go through Index values of 0 and 1 with D_out assigned 8'bx
each time.
When you hit Index 2, the D_out will be assigned D_in>>2*Data_width (limited
to the D_out width).
Then you go to your last Index value of 3 (N_channel) which reassigns D_out
to 8'bx.

What is the 8'bx intended *for* anyway?


"daluu" <cuuld@yahoo.com> wrote in message
news:62a18a5d3c96f3e1b48dbce58ce157f3@localhost.talkaboutprogramming.com...
I'm working on a lab which has given parameterized mux code but has
compile
problems in ModelSim and we are supposed to fix it.

The code below gives a range must be bounded by constant expression
error:

-----------
for(Index = 0; Index < N_channel; Index = Index +1)
if(Index == Sel)
D_out = D_in[Data_width*Index+Data_width-1:Data_width*Index];
else
D_out = 8'bx;
------------

I found a possible workaround in from a post in this forum, don't have URL
at moment, but that just fixes the bound error but the simulation is
incorrect.

I'm using a inner for loop to handle assigning the data from input to
output bit by bit. I believe the problem lies in the outer for loop or the
if/else statement.

When I run a simulation in modelsim, the output is always 8'bx unless Sel
= 3. When sel = 3, then it selects the appropriate section of input as
output. So it looks like 90% of the time, all output is set by the else
section. And I have set a range of values for Sel in the testbench but
like I said only sel=3 outputs the right result other sel values come up
as 8'bx when it shouldn't.

Did I miss something in the code that causes this?
 

Welcome to EDABoard.com

Sponsor

Back
Top