Reading PWM duty cycle
2012-03-26 by Philippe Habib
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.