- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
first of all - thank you very much for help !
secondly - it is for synthesis , what can i do in this case ?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it doesnt matter - you cannot use reals.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes i did . i will try that...
thank you very much !!!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page