Code to read a PPM/PWM pulse, interrupt driven. Most useful for RC receivers. Code is non-blocking, and a poll of the stall timer can detect if a signal has been lost (signal changes will reset the timer). Code originally written by Simon Ford, modified by me to add in a lost-signal guard.
Dependents: triforce-control usbjoystick_prg
Code is simple to use.
Will add a quick tutorial on use, and how to use the lost-signal/stall detection in due course.
Pulsewidth and period variables are:
- Declared volatile to make sure the value read is not compiler optimised, since the values are modified through an ISR; and
Edit: WITHDRAWN:
- Protected by mutex to make sure that values read are true (such as when an ISR is occurring, but a thread tries to read the value during the ISR). Reason:
- Mutexes are not meant to be called in an ISR (asynchronous). They are costly and may block a thread
Changes
Revision | Date | Who | Commit message |
---|---|---|---|
7:2a58e3363242 | 2014-05-19 | pHysiX | Removed mutex. Bad and incorrect of mutex for an ISR |
6:e1df0b4f36e4 | 2014-05-19 | pHysiX | Added mutex for protection of pulsewidth and period during ISR |
5:7dc060aa0222 | 2014-05-18 | pHysiX | Rearranged ISRs |
4:44dd41c989d0 | 2014-05-16 | pHysiX | Declared pulsewidth and period volatile per Jason Stapels' notification |
3:38bd7aa1d4d2 | 2014-05-08 | pHysiX | Tidied, added in comment, and licence for publishing |
2:1f00548c2aa6 | 2014-05-08 | pHysiX | Comment added for clarity |
1:110bf6405123 | 2014-05-03 | pHysiX | Tidied up: Need to put in proper acknowledgement |
0:1ae106ada18a | 2014-04-30 | pHysiX | PwmIn: Moved to separate library, included lost signal control |