Ping ))) code miss understanding

hey ,
In every code used for ping ultra sonic they use these commands:

   ' Create the divisor for cm distance conversion
   PING_Scale.highword = 0
   PING_Scale.lowword = 2251         ' 0.03434 * 65535 cm conversion factor
   result = PING_Echo */ PING_Scale
   PING_Distance = result / 2

would anyone answer me how does it work??
why we use 2^16 (65535)

please answer me ??
i need to know so i could do it with the p16f877a micro-controller

Have you read the documentation for it? parallax.com/Portals/0/Downl … G-v1.6.pdf

There is sample code in the documentation for several different platforms. Should not be hard to convert.

Kurt

yes , i did , it’s not hard :wink:, but i tried all the possible code to get the right measurements but all the measures is wrong ,
and there’s something i cant get :
in the code that is here
lynxmotion.net/viewtopic.php?t=1819&postdays=0&postorder=asc&highlight=pro+ping+code&start=0

the rctime command gets the value in .5 us why dont we multilpy by 2 to get the time in us??
and what is the use of fractional multiplication??

thanx for answering

The code you mentioned from Linuxguy was using the fractional multiplication, which I have never used and had to look up in the manual. The units returned by the command he used was .in .5us instead of us, so the value is twice as big as it should be, which is why he then divided the result by 2. He obviously could have combined this with the previous command. The value 65535 is the largest value that can be held in a word (16 bit) variable, which is why it is often used.

If like the above code you are trying not to use floating point math, you could also achieve the same results of multiplying the time by: 0.03434 by writing the code something like:
result = (PING_Echo * 3434)/100000

However you also have to be careful to not overflow your calculations. i.e. you would want to use 32 bit math for this.

Kurt