On Mar 25, 2012, at 5:58 PM, Philippe Habib wrote: > Has anyone used the Atmel sample code from ap note AVR135 to read duty cycle of a PWM input? > > I'm using it on an ATMEGa48 and running into some interaction with another timer/counter. I am using the internal oscillator at 8Meg as my clock. > > My PWM input signal goes into PB0/ICP1. > > I need to generate an output PWM based on the input PWM using PD6/Timer0. > > My output PWM is fixed at 125Hz. The input could vary between a low of 60Hz and a high of 1kHz. > > When my input frequency is at or above my output frequency, it all works fine. > > When the input frequency drops below the output frequency, the output loses stability and moves around by maybe 10% +/-. > > I have added a running average of last samples to smooth out the bumps but it hasn't really helped. > > Could there be some interaction between the two timers? > > Thanks. > Expect NO interaction between the timers. The interaction will be in your code, how you are reading the incoming signal and how you are writing to the output. In particular, you should be keeping the contents of any interrupt service routines to an absolute minimum. One possibility is that you are waiting too long in the input ISR when the input frequency is low. Read the timer value on every edge, set a flag (indicating if the value applies to a period or pulse width) and get out. Jim Wagner Oregon Research Electronics [Non-text portions of this message have been removed]
Message
Re: [AVR-Chat] Reading PWM duty cycle
2012-03-26 by Jim Wagner
Attachments
- No local attachments were found for this message.