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

History

Removed mutex. Bad and incorrect of mutex for an ISR default tip

2014-05-19, by pHysiX [Mon, 19 May 2014 16:04:34 +0000] rev 7

Removed mutex. Bad and incorrect of mutex for an ISR


Added mutex for protection of pulsewidth and period during ISR

2014-05-19, by pHysiX [Mon, 19 May 2014 15:43:02 +0000] rev 6

Added mutex for protection of pulsewidth and period during ISR


Rearranged ISRs

2014-05-18, by pHysiX [Sun, 18 May 2014 09:05:32 +0000] rev 5

Rearranged ISRs


Declared pulsewidth and period volatile per Jason Stapels' notification

2014-05-16, by pHysiX [Fri, 16 May 2014 23:19:34 +0000] rev 4

Declared pulsewidth and period volatile per Jason Stapels' notification


Tidied, added in comment, and licence for publishing

2014-05-08, by pHysiX [Thu, 08 May 2014 09:52:48 +0000] rev 3

Tidied, added in comment, and licence for publishing


Comment added for clarity

2014-05-08, by pHysiX [Thu, 08 May 2014 09:42:36 +0000] rev 2

Comment added for clarity


Tidied up: Need to put in proper acknowledgement

2014-05-03, by pHysiX [Sat, 03 May 2014 02:54:48 +0000] rev 1

Tidied up: Need to put in proper acknowledgement


PwmIn: Moved to separate library, included lost signal control

2014-04-30, by pHysiX [Wed, 30 Apr 2014 06:37:19 +0000] rev 0

PwmIn: Moved to separate library, included lost signal control