Notifications
Clear all

PWM frequency decrease itself during Arduino Leonardo starts

2 Posts
2 Users
0 Reactions
142 Views
(@gorek)
Member
Joined: 3 years ago
Posts: 10
Topic starter  

Hello,

I want generate PWM signal with certain frequency (let's say 10 KHz) on Leonardo(Atmega32u4) using Timer4. After setting TCCR4A, TCCR4C, TCCR4D, TCCR4E and PLLFRQ registers on right values and uploaded sketch everything worked perfectly.. until I disconnect power from Arduino and connect it again☹️ 

When I reconnect Leonardo do PC (or external pupply) PWM frequency decreased to 5 KHz.
Restarting Arduino causes back PWM frequency to desired value.
I confirm this on my (not very expensive but working😉) scope.

After short investigation I discover the reason of frequency decrease is PLLFRQ register changing between start and restart board.
In Atmega32u4 datasheet I can find "The PLL is used to generate internal high frequency (up to 96MHz) clock for USB interface and/or High Speed Timer" (Timer4) and PLL frequency settings resides in PLLFRQ register.

When board starts PLLFRQ was:

01111010
//PLL output frequency 96MHz (last 4 bits),
//USB frequency 48MHz (PLL output divided by two, bit number 6 coutned from LSB)
//Timer4 input 48MHZ (PLL output divided by two, bit number 5:4)

 After restart:

00110100
//PLL output frequency 48MHz (last 4 bits),
//USB frequency 48MHz (no division, direct connection to PLL output, bit number 6 coutned from LSB)
//Timer4 input 24MHZ (PLL output divided by two, bit number 5:4)

 Detailed bits description is in chapter 6.11.6 of datasheet.

Can anyone know why PLLFRQ register changing between start and restart board? 🤔 

This topic was modified 2 months ago by gorek

   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7935
 

@gorek All greek to this old tube guy.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote