Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp and Ping Sensor — Parallax Forums

Basic Stamp and Ping Sensor

Howad01Howad01 Posts: 6
edited 2006-02-16 19:30 in BASIC Stamp
I would like to compenste the Ping Sensor for the speed of sound at a given temperature with a Floating Point Processor and a Dallas 1620 Chip. The speed of sound is accurately approximated in meters per second by the equation (331.5+(0.6*Temperaure in Celsius)).

The way the ping sensor works is that it provides 40 Khz pulse bursts and stops when the echo is received.

This makes it much more complicated in my mind, because you have a varying pulse width for any given distance over temperature.

My question is there any way to control the pulse width versus temperature based on the speed of light from a hardware point of view ? Or I am I limited to temperature compensation versus the speed of sound in the software only. This is not clear to me. Does any one have any coments or examples.


Thank you,


Howard Epstein
Howard@FCC1.biz

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-02-14 01:44
    You might find this recent tread interesting...
    http://forums.parallax.com/showthread.php?p=556298

    about a snow depth sensor from Chris Nafis...
    www.howmuchsnow.com/ping/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-02-14 04:56
    You must do the temperature compensation in software. I'm not sure you understand how the PING)) works. The output burst is 8 cycles of 40khz (200 microseconds long). The timing interval starts when the PING)) receiver hears its own burst via the short direct path. The timing interval ends when the PING)) hears the echo from the remote object. From that you calculate the distance by dividing the pulse width (go and return time) by the speed of sound. For best accuracy you would apply temperature correction to the speed of sound as part of the calculation. What is so difficult about that? Maybe I am missing your intent.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Howad01Howad01 Posts: 6
    edited 2006-02-14 17:13
    Tracy,

    That is what I thought BUT without providing a stable 40 Khz signal the calculation is not valid. The Ping sensor outputs a 40 Khz signal. If the 40 Khz signal were either phase locked or had crystal stability the solution would be easy and rest totally in the software. Then the sensor echo signal can be accurately calculated based upon the speed of sound in air. But without providing a 40 Khz stable transmit signal the results will be based on two variables and you will get varying results with multiple ping sensors.

    Can I or NOT provide a feedback loop on the "signal" pin.

    The question really becomes How can a provide a accurate 40 Khz signal. My theory is that I would have to "tap" into ping sensor or base the operation on a crystal oscillator.

    Regards,


    Howard Epstein
  • BeanBean Posts: 8,129
    edited 2006-02-14 17:50
    I don't see how the 40KHz matters ? So what if it's 39KHz or 41kHz.
    That doesn't change the calculation does it ?
    If it does it cannot be that much compared to the change for temperature.

    The Ping does not "measure" the frequency of the sound, just it's presents.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • stamptrolstamptrol Posts: 1,731
    edited 2006-02-14 17:52
    So, the PING is rated more or less 0 to 10 feet. With a swing temperature of say 5 deg C up and down the speed of sound will vary approx 3 meters per second each way.

    Given that you plan to measure the ambient temp, (and persumably calculate a correction) the variable really is the actual or perceived jitter in the 40 kHz signal. With a total travel of only 20 feet, isn't the effect of jitter going to be quite small?

    How accurate are you trying to be with a $20 transducer?

    Cheers
  • Howad01Howad01 Posts: 6
    edited 2006-02-14 19:30
    Okay so the ping sensor initially provides a 40 Khz burst (25 microseconds).

    This I believe is important to anybody attempting to temperature compensate a ping sensor.

    I believe I am finally understanding how the ping sensor works. The PULSOUT command initiates the 40 Khz bust. After this the sensor does not not send another pule burst for 200 microseconds.

    The PULSIN command , is "key". It is independent of the PULSOUT command and is used soley to measure the distance. So that the 40 Khz pulse burst would have absolutely nothing to do with the calculation. In addition the 40 Khz burst varying to 30 or 50 Khz would have absolutely no effect on the PULSIN signal.


    Therefore we only have to compensenate for the speed of sound in the software to get accurate readiings.

    However, the components in the Ping Sensor have an unknown temperature tolerance and must be determined empiriaclly. To that end we have no direct answer as we do not have an environmental chamber.


    Regards,

    Howard Epstein
    jumpin.gif
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-02-14 20:42
    I think you got it! The Stamp triggers the PING with a single pulse, then, after a short delay, the PING itself generates the burst at very close to 40khz One cycle at 40khz is 25 microseconds, and the burst consists of 8 cycles, so the total length of the burst is 200 microseconds. That is the only burst that the PING sends out until the Stamp re-triggers it.

    The PING waits some time after the trigger before it starts the burst, to give the Stamp time to set up its PULSIN command. The line for PULSIN goes high and stays there until the PING detects the return echo of the burst.

    Sound travels at about one inch every 75 microseconds,, but that can vary by a couple of microseconds over the range of room temperature. The regular BS2 resolves PULSIN times to 2 microseconds, so the temperature effect is on the edge of detectability with a standard BS2. However with one of the faster Stamps you could detect and compensate the effect.

    I think you are on your own for seeing if there is any temperature effect from the components in the PING itself, separate from the speed of sound. I doubt if there is much of a drift. Let us know if you test it, though. You would not really need an environmental chamber. Just point the PING at a good solid wall a fixed distance away, and then heat the PING only with a hair dryer or a lamp, to ball park the drift.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-14 21:27
    Tracy,

    ·· Thank you, you just explain (regarding the resolution) what I tried to explain to him earlier.· At that point I realized I wasn't sure how much the variance was to say which Stamp could measure the changes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-02-15 17:38
    I didn't mean to imply that the temperature effect was insignificant. It does need to be compensated. You can see that from the following graph lifted here from Chris Nafis' web site:

    Grab63.jpg

    The site URL is ttp://www.howmuchsnow.com/. The blue line is I think the distance measured by the PING before temperature compensation (after applying constant 1130 ft/second) and the red line after temperature compensation for the speed of sound. The PING was, as I read it, pointed at a fixed distance from the dry ground before any snow fell.

    One question raised in the previous thread was, why is there a residual uncertainty of 0.3 inch after applying the temperature compensation? It should show a flat line when it points at a steady distance from the ground. Even at 2 microsecond resolution, the original BASIC stamp can resolve that easily, because each 2 microseconds represents 0.027 inch (0.69 mm), and the discrepancy is ten times that, 0.3 inch. Note that 0.3" over 63 inches is an error of 0.5%, over a temperature change of around 15 degrees Fahrenheit. And the residual 0.3" does not appear to be highly correlated with temperature.

    Other possible causes for the residual 0.3":
    -- temperature measurement not accurate (it was an RCTIME scheme)
    -- temperature measurement not representative (it was measured inside the Davis 7714 radiation shield, which may not accurately represent the free air temperature of the sound path. This is always an issue with accurate ultrasonic measurements.)
    -- the mounting support for the assembly itself has a slip or temperature bend effect.
    -- other factors like wind, extraneous noise, or electrical noise may be a factor.
    -- the PING itself may have component temperature drift, although from the principle of the thing, that seems unllikely at the 0.3" level.
    -- Most likely, however, sound travels 0.3 inches in about 22 microseconds, which is less than one period of sound at 40 khz (25 microsecond period). Remember that the burst of sound is 8 cycles, a total of 200 microseconds) The electro-mechanical inertia of the sound transducer in the PING)), and phase delays in its amplifier/detector, would certainly limit the accuracy to not much better than one wavelength. (That is why medical ultrasound probes are done at 100s of kHertz.)

    In developing anything like this, it is essential to consider it from all angles!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-15 21:07
    Another thing to consider in temperature compensation is that the controller on the PING is responsible for generating the pulse as well as the timing of those pulses, including those that represent the return time.· This controller's clock can be affected by temperature as well, which will affect its timing to some degree.· That of course will in turn affect your readings and is more difficult to compensate for.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-02-15 21:22
    Ummm... May I add something here....
    I read all the stuff on Chris Nafis's site. And there is one thing no one has meationed yet. The temperature is being read at one place, where as the actual distance is measured else where. Hence the 62 inches away from the sensor. We all know the ground is a different temperature then the air. And the air at gound level is different the the air at the sensor. I would also place a small wager that the air between the ground and sensor is different as well. Temperature inversions, also known as layers, are well documented throughout meterlogical sites, and I believe it's evident here. I believe the issues (more then one) are temperature range (from the sensor to the object and back), and the period of measurment (see Tracy Allen's post). For sensors like PING)), where outside sources can effect the outcome, data smoothing or averaging needs to be done, or other sensors to agument the measurment. This would really need to be used in something as "low ended" as the PING)) unit. I'm not knocking it, it's a wonderful sensor, and for the money, it works great. But if percicison is paramount in your project, get a better sensor. Remember:GIGO
    ----
    Ok, thanks... [noparse]:)[/noparse]
    ----

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Just tossing my two bits worth into the bit bucket
    KK
    ·
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-02-15 21:22
    Does the PING)) clock use a resonator/crystal for its time base?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-16 19:26
    Tracy,

    ·· No it doesn't, it uses the internal RC resonator...And KK, I think Tracy was getting at what you mentioned in his previous reply.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-02-16 19:30
    Chris... Your right...

    Well, for some poeple, putting the same thought into different words helps???
    Ok, I'll stop digging for the moment...

    Maybe it was a 'caffeen deficent moment'...

    [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Just tossing my two bits worth into the bit bucket
    KK
    ·
Sign In or Register to comment.