Forum Discussion

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

Convert real to integer in parameter

Hello.

I am trying to synthesize some Verilog modules that are parametrized using real numbers. The real numbers get converted to actual integer values that are used for the module configuration using some simple calculations (all constants and constant functions). However, I have been unable to find a way to pass those numbers from the real to integer domain that can be accepted as an input for Quartus synthesis.

The functions I have tried are $rtoi (obviously), and I also have $floor and $ceil (that I could just ditch if $rtoi was working). All those functions are supported on my other tools except Quartus, which puzzles me, particularly on the case of $rtoi because the output of that function should be supported integer functionality like $clog2, which in turn is supported.

For example, the following

parameter RateCounterTop = $rtoi(RateCounterNominal * (1 + RateErrorFraction)); ///< Bit rate counter

gives me the error

Error (10174): Verilog HDL Unsupported Feature error at XXXXX.v(54): system function "$rtoi" is not supported for synthesis

I tried compiling in SystemVerilog mode, but the error is the same.

Does any one know the recommended way to convert constant real values to constant integer parameters?

Thanks.

5 Replies

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

    I don't code much in Verilog, but I didn't have trouble using reals in the attached "blinky LEDs" example (synthesized on the BeMicro-SDK). Perhaps the use of localparam makes a difference ... or perhaps its the SystemVerilog extension ...

    Cheers,

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

    Hello Dave. Thank you for replying.

    Your code works, because as I stated above, you are using $clog2 which IS supported. The problem is converting to an integer value that is not an exponent of 2, usually done through a function like $rtoi.

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

    --- Quote Start ---

    The problem is converting to an integer value that is not an exponent of 2, usually done through a function like $rtoi.

    --- Quote End ---

    The line

    
    localparam integer COUNT = CLK_FREQ*BLINK_PERIOD;
    

    Is a conversion from real to integer ... isn't that what you want?

    Cheers,

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

    --- Quote Start ---

    The line

    
    localparam integer COUNT = CLK_FREQ*BLINK_PERIOD;
    

    Is a conversion from real to integer ... isn't that what you want?

    Cheers,

    Dave

    --- Quote End ---

    Hey, I missed that.

    Let me try and I'll report.

    Thanks!

    --- EDIT ---

    Yes, it seems to be working reliably. At least the floating point numbers that I tried and can't be represented exactly as integers are converted precisely to the cast-respective integer value. With this I can also emulate ceils and floors. Both parameter and localparam work.

    Thanks again! Best.