View Full Version : How to get around cog lock up with pulsin (BS2 Functions)
07-20-2009, 06:04 PM
I'm using the PULSIN command (from Martin Hebel's BS2 Functions on obex) to read servo pulses from a receiver. It works really well except that the cog running PULSIN will lock up if there is no input signal when PULSIN is called. The receiver needs to be able to be turned on/off independently of the propeller so they're not always going to be in synch i.e there isn't always going to be a signal. I need some way to prevent/handle this lock up to make things a bit more robust. Is there any way around this?
07-21-2009, 02:25 AM
Using waitpeq and waitpne for a pin that doesn't change will cause a program to snag; you could create a PASM object that is able to measure the pulse in the background and let you know when the measurement is ready. You could check the ready flag instead of holding for a measurement that isn't coming.
07-21-2009, 03:29 AM
I recently uploaded an object that might work. RX Input (http://obex.parallax.com/objects/482/).
A pulse needs to be present when started but you can remove the pulse without anything hanging. If the input has no pull down, you may get erratic readings when no pulse is being sent.
07-21-2009, 03:53 AM
Instead of a WaitPQE/PNE use a Timeout loop while testing for the pin state and checking for a time out.
This works OK in SPIN if your timing is not too tight. If it is then use PASM to do the same thing.
07-21-2009, 04:31 AM
Another option would be to use WAITPNE on TWO pins at once. One pin would be the input, while the other pin would be driven by a counter in NCO mode an FRQx of 1 and PHSx would then be set to -Timeout_seconds * CLKFREQ (this is negative number) before every WAITPNE. A quick check for a low on the counter driven pin would tell if the WAIT timed out. Could be done from spin with single clock precision, but needs a spare pin and counter.
Lunch cures all problems! have you had lunch?
07-21-2009, 03:55 PM
Thanks for all the suggestions. Timing is quite important, the faster ,the better. Looks like I might need to look into learning some PASM! I'll post what I come up with - it may take a while though, I haven't looked at PASM yet.