Forum: FPGA, VHDL & Verilog In Verilog, why can't I compare my (genvar) with an integer value in my (for) loop?

von Kevin S. (kvnsmnsn)

Rate this post
0 useful
not useful
I've written a bit of Verilog code that takes two input operands 
(leftOp) and (rightOp) and outputs (result), with a parameter (nmBits) 
that is the common length of all three of those operands, set to one by 
default. My code is:
module bwEqu ( result, leftOp, rightOp);
parameter nmBits = 1;
integer highBit = nmBits - 1;
output [ highBit:0] result;
input  [ highBit:0] leftOp;
input  [ highBit:0] rightOp;

integer poolSize = 3 * nmBits;
integer highPool = poolSize - 1;
wire pool [ highPool:0];
genvar ix;

for (ix = 0; ix <= highPool; ix = ix + 3)
  nand2 na0( pool[ ix], leftOp[ ix / 3], rightOp[ ix / 3]);
  nor2 no0( pool[ ix + 1], leftOp[ ix / 3], rightOp[ ix / 3]);
  nt1 nt0( pool[ ix + 2], pool[ ix + 1]);
  nor2 no1( result[ ix / 3], pool[ ix], pool[ ix + 2]);

When I try to simulate this with Icarus I get the following error 
D:\Hf\Verilog\Unpacked\Common>\Icarus\bin\iverilog -g2009 -o bwEqu.out bwEqu.sv
bwEqu.sv:13: error: Unable to bind parameter `highPool' in `bwEqu'
bwEqu.sv:13: error: Cannot evaluate genvar conditional expression: (ix)<=(highPool)
2 error(s) during elaboration.

Now I realize that there are much more simple ways of accomplishing my 
bit-wise equal that won't suffer from these problems; this is sort of a 
simplification of a problem I'm having with a considerably more 
complicated piece of code. The problem is the same; I've got an integer 
value, in this case (highPool), that I'm using to control my (for) loop, 
and for some reason the simulator is balking when it comes to comparing 
(ix) with that value. Anybody have any idea why Icarus is having this 
problem, and what I can do to solve the problem (short of splitting 
(pool) into three separate arrays)?

von Klakx (Guest)

Rate this post
0 useful
not useful
make use of localparam (constants), like this

localparam integer poolSize = 3 * nmBits;

von Kevin S. (kvnsmnsn)

Rate this post
0 useful
not useful
Klakx, thanks again! It looks like (localparam) is a good thing to know 


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig