In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Zoot wrote: Ummm.. where did the conversion number come from: RawToCm CON 2257 ' 1cm / 29.034us. see docu RawToMm CON 22572 ' 1mm / 2.9034us. see docu Remember your ticks are 10us -- not 2us or .8us like on some of the Stamps. So.......hitting the docs: [code] Host Device Input Trigger Pulse tOUT 2 µs (min), 5 µs typical Echo Holdoff tHOLDOFF 750 µs ' quite a bit until pulse will start Burst Frequency tBURST 200 µs @ 40 kHz Echo Return Pulse Minimum tIN-MIN 115 µs ' min pulse Echo Return Pulse Maximum tIN-MAX 18.5 ms ' max pulse PING))) Sensor Delay before next measurement 200 µs ' could be good to know if they are being triggered too fast RawToIn CON 889 ' 1 / 73.746 (with **) RawToCm CON 2257 ' 1 / 29.034 (with **) ' At sea level sound travels through air at 1130 feet per second. This ' equates to 1 inch in 73.746 uS, or 1 cm in 29.034 uS). [/code] So you want to divide in the form 1/29.034 where 1 = [b]1us[/b]. But you are counting [b]10 us[/b] increments. So you need to multiply the fractional constant by 10. That means: distance = raw ** ((1/2.9034)*$FFFF) distance = raw ** ( 22571.812357925192 ) distance = raw ** 22572 But you need to divide by two, ideally before scaling, to minimize error: distance = (raw+1)/2 ' cleaner rounding distance = distance ** 8887 Picking a random sample of say 9000us (approx halfway through the Ping's useful distance), that should give something like 150 cm: 9000us = 900 ticks ( 900 ticks + 1 ) / 2 = 450 return trip 450 ** 22572 = 154.99198901350423 or 155 cm. Sounds about right. ** is better if the fractional part is less than 1, i.e. multiplying by .7564 or something. */ is required if the fraction part is greater than 1, i.e. multiplying by 1.345. ** is more precise. The rest looks OK. The anamalous data on the longer measurements is sure odd. Perhaps grasping at straws -- is the ping close to the floor/surface? What did you use for a test object? Are you just watching these values in the debugger? Without a "break" in a known location how do you know you are seeing the most recent full measurement, rather than a value in progress? ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=394074#m401264 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)