Arduino Forum

Products => Nano Boards (NEW types) => Nano Every => Topic started by: maninthehighshed on Aug 01, 2020, 01:16 pm

Title: How to set and test clock speed of Nano Every board.
Post by: maninthehighshed on Aug 01, 2020, 01:16 pm
The Nano Every is advertised as being able to run at 20Mhz, yet it is set to run at 16MHz out of the box.

A Google search on how to change the speed to 20Mhz shows numerous posts, many of which are complaining that once the setting is changed to 20Mhz, timer-based functions no longer work as expected.

After a bit of experimenting and a rummage though the ATmega4809 datasheet, I have found that there are two settings that need to be changed in Boards.txt not one.

The following additions to the good old blink sketch show the speed the processor is actually running at, either 16MHz or 20MHz, and the F_CPU value, which is the value used by timers, delay and serial functions to calculate how many clock cycles are required for their task. If these two values are mismatched, then timing errors will occur, and data sent to the serial monitor will be corrupted as the bit/baud rate on the Nano will be set incorrectly.

Code: [Select]
void setup() {
  char tString[ 10 ] ;
  Serial.begin( 9600 ) ;
  Serial.print( "F_CPU: " ) ;
  Serial.println( ltoa( F_CPU, tString, 10 )) ;

  Serial.print( "Clock Speed, 1=16MHz, 2=20MHz: " ) ;
  Serial.println( ltoa( FUSE.OSCCFG, tString, 10 )) ;


void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second

Run the sketch and time how long it takes for 10 state changes to occur to the led. If it's 10 seconds, give or take a tenth, all is well, if it's much longer or shorter than that, then the entries in Boards.txt are mismatched, and you'll get gibberish on the serial monitor.

For 16 MHz operations these lines in Boards.txt need to be set:
Code: [Select]

And for 20MHz they need to read:

Code: [Select]

On windows, Boards.txt is found in:


Where xxxxx is your login name.


Title: Re: How to set and test clock speed of Nano Every board.
Post by: almytom on Aug 02, 2020, 03:08 am
Time based functions do continue to work. PWM frequencies are 25% higher. USART baud rate range is higher as well moving the minimum rate from 1200bps to 2400 bps.