Hello,
I would generate PWM signal frequency with certain frequency on Leonardo(Atmega32u4) Timer4. After setting TCCR4A, TCCR4C, TCCR4D, TCCR4E and PLLFRQ registers on right values and uploaded sketch everything worked perfectly.. until disconnect Leonardo from PC and connect it again
When I reconnect Leonardo do PC PWM frequency decreased exactly on half. Using external power gives the same effect. Restarting Arduino after powering back PWM frequency to desired value.
After quick investigation I discover the reason is PLLFRQ register changed itself after reconnection.
After upload and before reconnecting is was:
01111010 //PLL output frequency 96MHz
After reconnecting:
00110100 //PLL output frequency 48MHz
I would like set PLL postscaler factor to /2 and not changing another bits so I set this register value as below:
void setup()
{
//other registers settings
PLLFRQ = (PLLFRQ & 0xCF) | 0x30;
}
and not change it later in code.
Can anyone know why PLLFRQ register changes after power connection and back to desired value after restart