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

please help !

Altera_Forum
Honored Contributor II
1,469 Views

i defined a port in the entity which is : distance : out integer ; 

 

and i also defined a signal : signal echo_width : integer :=0; 

 

i tried to assign multiplication by this way : 

 

distance <= echo_width*(0.02/58);  

 

and i got an error line : 

 

"can't determine definition of operator ""*"" -- found 0 possible definitions" 

 

what is the problem with my assignment and how should i resolve it ?  

thank you about your responds.
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
299 Views

0.02 is a real, so you need to first cast the integers to reals, then back to integer: 

 

distance <= integer( real(echo_width) * (0.02 / 58.0) ); 

 

But, remember that real types are not synthesisable, so I assume this is just testbench code.
0 Kudos
Altera_Forum
Honored Contributor II
299 Views

first of all - thank you very much for help ! 

secondly - it is for synthesis , what can i do in this case ?
0 Kudos
Altera_Forum
Honored Contributor II
299 Views

so if its for synthesis - dont use real types. You can only use reals for set up information, not runtime arithmatic. Have a look into the fixed point packages. 

 

www.vhdl.org/fphdl
0 Kudos
Altera_Forum
Honored Contributor II
299 Views

is it synthesisable ? 

 

i defined an integer variable called "temp_distance" ,changed echo_width to a variable and used it like that : 

 

temp_distance:=integer(real(echo_width) * (0.02 / 58.0)); 

distance<=temp_distance; 

 

reminder : 

distance : out integer ; (entity port) 

echo_width : variable integer; 

temp_distance: variable integer;
0 Kudos
Altera_Forum
Honored Contributor II
299 Views

it doesnt matter - you cannot use reals.

0 Kudos
Altera_Forum
Honored Contributor II
299 Views

Hi 

 

your output is integer so whatever the real data you get the decimal point digits will be truncated to integer 

so you have to find the nearest integer number to the real one 

 

for instance if we have the following operation: 

out = num * 0.05; 

 

you can find that 0.05 is nearly 13/256 (0.05078) 

 

so first multiply num by 13 and the division is simply removing the 8 digits from the right the right 

note that using integer is the same of std_logic_vector(31 downto 0) which is more flexible  

you can try this : 

 

 

signal num:std_logic_vector(31 downto 0); 

signal temp:std_logic_vector(35 downto 0); 

signal out1:std_logic_vector(31 downto 0); 

 

num <= x"0000028E"; -- test value 654 

temp<=num * x"d"; -- 654 * 13 = 8502 

out1 <= "00000000"&temp(31 downto 8);-- 8502 / 256 = 33 

 

 

this result 33 is near to 654 * 0.05 = 32.7 

 

this what I do to deal with float numbers 

did you got it?
0 Kudos
Altera_Forum
Honored Contributor II
299 Views

yes i did . i will try that... 

thank you very much !!!
0 Kudos
Reply