Arduino Helicopter Autopilot

Hi Ed, thanks for posting.

The advantage of your implementation over the ServoDecode library linked in post #9 above is that it doesn't grab timer1, so PWM outputs on pins 9 and 10 are available. But your code has some drawbacks that may limit its use.

Your decoding is done in software so the application can't do anything else while waiting for the channel pulses. There may only be three or four milliseconds between frames so 80% of the available processing time is not available for running application code. ServoDecode does all the pulse counting in hardware using Timer1 so practically all of the available processing power is available to run the application.

Also, it appears that the code above is measuring to an accuracy of 4 hpticks. I think each hptick is 4 microseconds so your accuracy is to 16 microseconds, which would give around 64 discrete steps between 1ms and 2ms, this is less than the resolution of the rc systems I have looked at. TheServoDecode library clocks timer1 at 0.5microseconds which is 8 times faster than an hptick, 64 times higher resolution than the 4xhptick code.

Other advantages of ServoDecode are that it automatically detects positive or negative going pulses and the number of channels. It has failsafe supporting preset or last good value. And it s library that is easy to integrate into an application.

I don't want to discourage you in enhancing your code, but knowing what else is out there may help you decide where best to apply your efforts.

Have fun!