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
Revisions of PwmIn.h
Revision | Date | Message | Actions |
---|---|---|---|
7:2a58e3363242 | 2014-05-19 | Removed mutex. Bad and incorrect of mutex for an ISR | File Diff Annotate |
6:e1df0b4f36e4 | 2014-05-19 | Added mutex for protection of pulsewidth and period during ISR | File Diff Annotate |
5:7dc060aa0222 | 2014-05-18 | Rearranged ISRs | File Diff Annotate |
4:44dd41c989d0 | 2014-05-16 | Declared pulsewidth and period volatile per Jason Stapels' notification | File Diff Annotate |
3:38bd7aa1d4d2 | 2014-05-08 | Tidied, added in comment, and licence for publishing | File Diff Annotate |
2:1f00548c2aa6 | 2014-05-08 | Comment added for clarity | File Diff Annotate |
0:1ae106ada18a | 2014-04-30 | PwmIn: Moved to separate library, included lost signal control | File Diff Annotate |