Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16557 Discussions

Convert real to integer in parameter

Altera_Forum
Honored Contributor II
5,713 Views

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.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
2,869 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
2,869 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,869 Views

 

--- 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
0 Kudos
Altera_Forum
Honored Contributor II
2,869 Views

 

--- 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.
0 Kudos
Altera_Forum
Honored Contributor II
2,869 Views

Glad to hear you've got a work-around! 

 

Cheers, 

Dave
0 Kudos
Reply