Shop OBEX P1 Docs P2 Docs Learn Events
How can I change the timeout of the Ping Sensor? — Parallax Forums

How can I change the timeout of the Ping Sensor?

ArtLaArtLa Posts: 3
edited 2014-07-29 12:02 in Accessories
I am using 7 ea. Ping sensors with a short range to the target, about 6 to 10 inches. I am activating each sensor and waiting for a response from the sensor until I trigger the next one to avoid crosstalk. I am using C. The update rate from the array is great when every sensor detects a target, however, when a target is missed and one or more sensors time out, the update rage drops because of the approximately 20ms timeout for each sensor. Is it possible to change the Ping timeout? I'd like a timeout of arpound 2 ms, which is further than any of my targets, and I can then use that timeout to detect a missing targe and still get a fast update from the other sensors.It would be great to do this in C, by changing some parameter, for example in the simpletools.hor soime other file.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-07-28 16:40
    If you're certain that there are no further targets beyond your 6-to-10-inch range, you do not need to wait for the sensor to time out before triggering the next sensor. You only need to wait until it times out before triggering the same sensor again. So wait 2 ms. If there's no response, trigger the next sensor, and so forth. When you get back to each sensor in rotation, just make sure that it has timed out before retriggering.

    BTW, welcome to the Parallax Forum, ArtLa!

    -Phil
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-07-28 16:41
    Welcome to the forums! I couldn't explain how to do it in C, but if you don't mind losing some range you could calculate the minimum range for your application and create a software timeout for each sensor and when that time has been reached if the PING))) hasn't received its return pulse you ignore it and move on to the next sensor. The idea is that by the time you come back around the sensors will be ready to re-trigger.

    Note that the timeout equates to the maximum distance, therefore changing that means reducing the effective range.

    Edit: Great Minds, Phil. :nerd:
  • ArtLaArtLa Posts: 3
    edited 2014-07-28 22:18
    Thank you for the responses.If I were programming with SPIN, I could implement your suggestions, however, I am programming using C, and all of the 7 sensors are in the same cog, trigered sequentially with a sequence of ping calls for each sensor. when there is no target, the ping call hangs and does not return until it times out. I'd be happy to trigger the next sensor after 2 msec, or whenever the ping call returns after I shortened the timeout, but the ping C call routine does not return until it times outat around 20msec when the target is missing,. I have only a range of interest less than 10 inches,and there are no targets beyond this range.Is there any way I can alter the timeout of the sensor when using C perhaps by changing the C support software routine to timeout after 2 msec instead of waiting the full default time?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-07-29 02:07
    ArtLa,

    You don't have to use the Ping library function to use the Ping))) in C. Take a look at the C source code to glean what you need to know to write your own Ping function.

    -Phil
  • ArtLaArtLa Posts: 3
    edited 2014-07-29 12:02
    I looked at the C code which support the ping sensor, and the trail led me to simpletools.h. where I found the set_io_timeout was used in the pulse_in function which was called by the ping function. So before I called the ping functions for the array of sensors, I called the set_io_timeout function with this line of code:

    set_io_timeout(CLKFREQ/350);

    After that change, the timeout is about 2.2msec, and with a missing target the ping function returns a time of slightly over 2220usec. This is perfect for my needs and now the response of the sensor array is high and missing targets does not slow down the response due to the 20msec default timeout.

    Thanks for the suggestion to look at the ping C code.

    Art
Sign In or Register to comment.