Issue with Ping driver?

Code for robot waits for ping reading to be less than 12 inches and then do something.

But, a loop that only calls ping driver does not work...
repeat
    j:=ping.Inches(PING_Pin)
    if j<12
       (do something)

The Ping LED doesn't even turn on if you do this...

Adding a delay to the loop seems to fix the issue.

Maybe that's a "feature", but I'm tempted to call that a bug...
Prop Info and Apps: http://www.rayslogic.com/

Comments

  • 8 Comments sorted by Date Added Votes
  • Mike GreenMike Green Posts: 22,577
    edited October 31 Vote Up0Vote Down
    The library PING))) driver is very simple and written completely in Spin (about a dozen lines). How do you have the PING))) wired? It should be running off 5V and the signal line should have a 3.3K resistor between it and the Propeller I/O pin. What's your system clock?
  • RaymanRayman Posts: 8,316
    edited October 31 Vote Up0Vote Down
    I'm using the P17 header on the WX Activity Board.
    The jumper is set to 5V.

    But, come to think of it, I didn't have this issue running the same code on an old Activity Board...
    Strange...
    Prop Info and Apps: http://www.rayslogic.com/
  • The servo headers already have 3.9K series resistors. You shouldn't have additional resistance in series.
  • Not using any series resistors... Counting on the ones already part of the Activity Board...

    There must be some difference between old Activity Board and Activity Board WX.
    Or, maybe I have a bad WX board...
    Tried two different Ping modules, so I don't think there's a problem there...

    I tried both P16 and P17 headers on the WX board and they both have this issue.
    This isn't horrible, I just insert a delay and then it seems to work.

    Still, left me scratching my head...
    Prop Info and Apps: http://www.rayslogic.com/
  • If your ping is SPIN code then there are 11 code lines in it.
    In your loop there are only 3 code lines, so it's much faster.
    What happens when you call ping over and over before it's done with the first result?
    Taken from:
    http://obex.parallax.com/sites/all/modules/pubdlcnt/pubdlcnt.php?file=http://obex.parallax.com/sites/default/files/obj/id/454/Ping_Demo_- _Archive__Date_2011.06.13__Time_14.44.zip & nid = 454
    Yes Frida is my watchdog!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,321
    edited October 31 Vote Up0Vote Down
    The Ping))) requires a minimum 200uS delay between the end of one measurement and the beginning of the next. Most program examples show a 100ms delay.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • RaymanRayman Posts: 8,316
    edited October 31 Vote Up0Vote Down
    Adding a 50 us delay in the loop makes it work.

    But, I'm 99% sure my old Activity Board worked without this delay.
    (Wish I hadn't just gave it away now).

    I suppose it's possible that I remember wrong and had some debug code in there that I removed and thereby broke the code...

    If that's the case, then I'm back to thinking there should be a, say, 100 us delay added to the driver.
    Or, some note that a delay is needed...
    Prop Info and Apps: http://www.rayslogic.com/
  • I would recommend an even longer delay, say the 100ms that example programs use. The reason is that you want secondary echoes to die out before taking a new sample, as they could register as primary echoes in a sample requested too soon.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
Sign In or Register to comment.