Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

using MOD in a if-generate

Hello all,

I have some trouble getting this next piece of code to work. I don't know if this is valid code because the simulation result is always 'U', unless I enter a fixed number.

This doesn't work:

for x in 0 to (someConstant MOD 2) generate 

This does:

for x in 0 to 3 generate 

If this is not valid code, what is the correct way to do this?

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    its a little tricky to understand what you are doing without the proper code, but (someconstant mod 2) can only return 1 or 0, depending on the constant. so it's not the same as the loop below it.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Doesn't REM 2 only return 0 or 1?

    I use it to generate a number of multiplexors.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks, I think I was a bit too quick asking this question. Should have read a bit further on these operators than I did.