Trying to detect if Ping sensor is connected
Don M
Posts: 1,652
in Propeller 1
I'm looking at the Ping object and see that it returns a value when called. How do I abort the call when there isn't a Ping connected? Or maybe a better question is what is returned if there is no Ping connected? Does it just hang because it never sees the pin go high or low? If so how do I get past it? Maybe a watchdog timer?
Thanks for any help.
BTW- first post in the new forum format...
Don
Thanks for any help.
BTW- first post in the new forum format...
Don
Comments
The easiest thing to do is to comment out the Ping code rather than add more code for a watch dog timer or some sort of test of presence.
In fact, I have strong doubts that you can write code to see that the Ping is not attached. You might start having to track what is physically plugged in by building a special interlock.
As best as I can recall, the Ping only returns a pulse when it hears one and that can be a long, long time if it isn't moving and nothing moves in front of it.
I think the Ping object in the Propeller library will hang if no Ping connected. A watchdog timer is probably the easiest way to check if a Ping is connected. At least it's the easiest way I can think of.
Edit: If you have a spare I/O pin, I think there's a way to modify the Ping object so one I/O pin will change after a timeout period (using a counter). Instead of having the waitpxx wait for a change on a single pin, it could look for a change on two pins so the timeout pin will free the cog from continuing to wait.
There wasn't a timeout here but this shows what the line is doing while a measurement is taking place.
The Ping code toggles the signal line (the short pulse seen in the trace) and sets it as an input. The code both waits for the pin to go high and then waits for the pin to go low. If no Ping is connected, this will cause the cog to freeze.
Since the code leaves the signal line pin low and an input, it could be forced to terminate by another cog without the need of a second I/O pin. The other cog could set the pin as an output and toggle the line to stop the cog from waiting for the pin state changes.
Here is the code from this object and what I don't understand is where the variable "Echo_Length" gets it's value from. In the beginning of the repeat loop it is assigned to the variable "Distance" in this statement- Distance := Echo_Length >> 1
to this and it works when the Ping is disconnected but what I'm wondering is where the Echo_Length variable gets its value from in the first place.
It would be important to not change the order of the variables in VAR without changing line 8 in the pasm.
Tom