Everyone,
I stumbled over the initialization of the compare registers for timers 3 and 4 for the Atmel Mega controllers. This is used to set the PWM rate. In Output.cpp there is the following line:
ICR3 |= 0x3FFF; // TOP to 16383;
If ICR3 is set to 16383, the PWM frequency will be half of (16 MHz / 16383) or half of 976.6 Hz or 488.3 Hz - just below the 500 Hz theoretical limit. This is what is intended and I verified that the resulting PWM frequency on my board really is 488 Hz.
However why is this a "|=" and not a plain "="? The two highest order bits are left unaffected and might have any value during initialization. That would lead to PWM frequencies of less than 488 Hz - could be as low as 122 Hz. Although copters will still fly at that frequency, this is undesired (and unpredictable).
I consider the line above a bug. Am I missing something?
Best, Leco
Initialization of PWM for Mega boards
Re: Initialization of PWM for Mega boards
you could be onto something, though i know little about this topic, ive been looking at it recently and found other spots where higher bits weren't set and wondered why not ... ?