Distance measurement using range sensor

Discussion in 'The Projects Forum' started by vivek20055, Jun 7, 2013.

  1. vivek20055

    Thread Starter Member

    Nov 4, 2012
    88
    0
    Hi,

    I am measuring the distance using range sensor SRFO5.

    The sensor is having the maximum range of 400 cm.

    When I trigger the sensor, it releases echo signal which is used to measure the distance of the object.

    The echo signal will become zero when the object is detected.

    The counter value increments which measures the echo width and beccomes zero when the object is detected.

    This counter value should be divided by 58 to convert it to cm.

    For division I am multiplying with 3 and then right shift by 13 places which converts the value to cm.

    Code ( (Unknown Language)):
    1.  
    2. code:
    3. process(echo, clk)
    4. begin
    5.   if clk'event and clk ='1' then
    6.     if echo = '1' then    
    7.      range_cm <= count1(23 downto 0)* "11";   --measuring distance
    8.      input <=range_cm(21 downto 13);     --
    9.      else
    10.     output <=input;
    11.     end if;
    12.   end if;
    13. end process;
    14.  
    I took only nine bits because the maximum range is 400 which can be represented in 9 bits

    My professor told me that I need to consider MSB bits also. But I do not understand why I need to consider those bits



    Regards
    xilinx1001
     
    Last edited by a moderator: Jun 7, 2013
  2. GopherT

    AAC Fanatic!

    Nov 23, 2012
    5,986
    3,729
    Right shifting by 13 places is equal to 2^{13} (like dividing by 8192).

    Is that really what you intended?
     
  3. Bob T.

    Member

    Oct 22, 2012
    35
    0
    What language is this
     
  4. vivek20055

    Thread Starter Member

    Nov 4, 2012
    88
    0
    Hi,

    Yes, you are right. I am dividing it by shifting 13 places to the right.

    Is there any other method of doing this?


    Regards
    vivek20055
     
  5. GopherT

    AAC Fanatic!

    Nov 23, 2012
    5,986
    3,729
    Multiplying by 3 then dividing by 8192 is like dividing by 2730. I don't understand why you are dividing by 2730 instead of dividing by 58 like you explained above.
     
  6. dougy83

    Member

    May 11, 2011
    11
    4
    You'd multiply by 141 then shift by 13 to divide by 58 (well, 58.099). You'll want to make sure that the multiplied value is stored in a variable of sufficient size and that the operation is not truncated.

    The reason you'd want to use the MS bits as well would be if it's possible for the count to be greater than what 9 bits can hold.
     
Loading...