Go Down

Topic: Mega PWM issues (Read 757 times) previous topic - next topic

franzix

Hello all,

This might be my first post here, I'm not sure.  Either way, I've found strange behavior with analogWrite on atmega2560 and 1280.

For some reason, the PWM rate is double for pins that run off timers other than Timer0.  With a simple sketch that just sets analogWrite(2:13,127), the PWM rate is ~980Hz on pins 13 and 4, but ~490Hz on pins 2,3,5-12.  The duty cycle is correct on all.

Is this intended behavior?  I realize that TIMER0 is the different than 1,3,4, and 5, but shouldn't they all be capable of the same rate?

Coding Badly


Yes and yes.  The millis timer (timer 0) is configured for Fast PWM.  The others are configured for Phase Correct PWM.  For the code to work correctly the millis timer really has to be configured for Fast.  The other timers can be configured however you want.

franzix

Makes sense.  Thanks for the reply.

Go Up