Results 1 to 8 of 8

Thread: please help !

  1. #1
    Join Date
    Nov 2012
    Posts
    20
    Rep Power
    1

    Default please help !

    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.

  2. #2
    Tricky is online now Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    6,050
    Rep Power
    1

    Default Re: please help !

    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.

  3. #3
    Join Date
    Nov 2012
    Posts
    20
    Rep Power
    1

    Default Re: please help !

    first of all - thank you very much for help !
    secondly - it is for synthesis , what can i do in this case ?

  4. #4
    Tricky is online now Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    6,050
    Rep Power
    1

    Default Re: please help !

    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

  5. #5
    Join Date
    Nov 2012
    Posts
    20
    Rep Power
    1

    Default Re: please help !

    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;

  6. #6
    Tricky is online now Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    6,050
    Rep Power
    1

    Default Re: please help !

    it doesnt matter - you cannot use reals.

  7. #7
    Join Date
    Feb 2010
    Posts
    12
    Rep Power
    1

    Default Re: please help !

    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?

  8. #8
    Join Date
    Nov 2012
    Posts
    20
    Rep Power
    1

    Default Re: please help !

    yes i did . i will try that...
    thank you very much !!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •