On Tue, Apr 26, 2005 at 12:25:58AM +0300, Joel Haasnoot wrote:
> I would like to decode PWM signals, for servos, such as those on
> model pr rc airplanes. Does anybody have any experience, hints,
> tips, code, google keywords or anything of the like?
For high resolution pulse width measurement, use the Input Capture
function. Most AVRs have at least one available. Basically you set
the pin to detect whichever transition you are looking for and when it
happens, the timer value of when it occured is latched into a register
and a flag is set letting you know it happened. You can optionally
have this trigger an interrupt as well. You then look at the input
capture register to get your pulse width:
1) wait for rising edge
3) set timer value to 0
2) set input capture edge detect to "falling edge"
4) wait for capture event
5) pulse width = input capture register
If the pulse width can exceed the max timer value, then you need to
account for timer roll-over. Do this with the timer overflow
interrupt to extend the range of the timer.
The input capture feature can give you pulse width measurement
accuracy down to near the timer resolution, which can be as few as
62.5 nanoseconds when using a 16 MHz clock.
The beauty of this is that most of the work is done by hardware so you
don't have to poll the input line to determine when it changes state.
Your program can be off doing other things and you will be notified by
flag or IRQ when the pulsed ended happened.
-Brian
--
Brian Dean
BDMICRO - ATmega128 Based MAVRIC Controllers
http://www.bdmicro.com/Message
Re: [AVR-Chat] Decode Servo PWM Signals
2005-04-27 by Brian Dean
Attachments
- No local attachments were found for this message.