Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Honored Contributor I
2,988 Views

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.
0 Kudos
5 Replies
Highlighted
Honored Contributor I
144 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
Highlighted
Honored Contributor I
144 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
Highlighted
Honored Contributor I
144 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
Highlighted
Honored Contributor I
144 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
Highlighted
Honored Contributor I
144 Views

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

 

Cheers, 

Dave
0 Kudos