Nano Every: main clock freq and prescaler

This is just to avoid long investigations for people working with Timers/Counters and frequencies experiencing time mismatch in their applications:

The AT4809 doc says it is factory preset at 20MHz (chapter, but the Arduino preset is at 16Mhz.

Chip doc also says the factory preset of the prescaler is 6, and one deduces enabled by default (chapter 10.3.3), but the prescaler is actually disabled.

You can check with:

    Serial.print("Freq main clk: ");Serial.println(FUSE.OSCCFG & 3 , BIN) ;  //0x01 for 16M, 0x02 for 20M
    Serial.print("Prescaler main clk: ");Serial.println(CLKCTRL.MCLKCTRLB  , BIN) ; // bit 0 is at 1 if enabled, bits [4:1] define the prescaler division.

I get:

Freq main clk: 1
Prescaler main clk: 0

which means frequency preconfig 0x01 (16Mhz), and no bit enabled in MCLKCTRLB register, then prescaler disabled.

The frequency can be changed between 16MHz and 20MHz by modifying the boards.txt file.
By default Arduino IDE will set the fuse bits and set the operating frequency to 16MHz. This is done with the two lines:

To run at 20MHz, change them to:

Note that not all library functions correctly support this change. If you keep it at 16MHz there won't be any issues.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.