Need help with odd behavior from Ping code
I recently started playing around with a Boe Bot and am running into trouble with my Ping sensor.· I have searche dthrough all the documentation and posts I could find but can't find anything that explains the behavior I am getting.· Here is the situation -
The code below always results in a ping_dist of 0
· IF (avoid_timer // 66 = 0) THEN
··· LOW PING
··· PULSOUT PING, 5
··· PULSIN· PING, 1, ping_dist
· ENDIF
The section of·code runs roughly every 3-3.5 seconds as timed by debug statements and a stopwatch.
If I modify the code (shown below) by adding a pause of 15 or more, ping_dist is populated just fine
· IF (avoid_timer // 66 = 0) THEN
··· PAUSE 15
··· LOW PING
··· PULSOUT PING, 5
··· PULSIN· PING, 1, ping_dist
· ENDIF
There are no other sections of code that send a pulse out or read a pulse in from the Ping.· I feel like I must be missing something very obvious but I can't understand why·this is happening.· Any thoughts or help would be greatly appreciated.·
The code below always results in a ping_dist of 0
· IF (avoid_timer // 66 = 0) THEN
··· LOW PING
··· PULSOUT PING, 5
··· PULSIN· PING, 1, ping_dist
· ENDIF
The section of·code runs roughly every 3-3.5 seconds as timed by debug statements and a stopwatch.
If I modify the code (shown below) by adding a pause of 15 or more, ping_dist is populated just fine
· IF (avoid_timer // 66 = 0) THEN
··· PAUSE 15
··· LOW PING
··· PULSOUT PING, 5
··· PULSIN· PING, 1, ping_dist
· ENDIF
There are no other sections of code that send a pulse out or read a pulse in from the Ping.· I feel like I must be missing something very obvious but I can't understand why·this is happening.· Any thoughts or help would be greatly appreciated.·
Comments
1) If you're calling this section of code multiple times, you'll need the PAUSE and it probably should actually be at least 18ms.
2) If you're only calling it once every few seconds, something is odd because it's behaving as if you're calling it rapidly at least twice.