The repository provides an MPLAB® X IDE project, highlighting the Internal High-Frequency Oscillator Calibration Using the Auto-Tune Feature present on the AVR® DA family of microcontrollers as described in TB3234 - Internal High-Frequency Oscillator Calibration Using the Auto-Tune Feature.
More details and code examples on the AVR128DA48 can be found at the following links:
- TB3234 - Internal High-Frequency Oscillator Calibration Using the Auto-Tune Feature
- AVR128DA48 Product Page
- AVR128DA48 Code Examples on GitHub
- MPLAB X IDE v6.25 or newer
- MPLAB XC8 v3.10 or newer
- Microchip AVR-Dx Series Device Support v2.7.321 or newer
- The AVR128DA48 Curiosity Nano Development board (DM164151) is used as test platform:

-
Configure the OSCHF to run at 1 MHz and activate or deactivate the auto-tune feature.
- Use case description: The purpose of this use case is to configure the OSCHF to run at 1 MHz, drive the main clock, and enable frequency output on the CLKOUT pin. Two frequency measurements on the CLKOUT pin will be made using an oscilloscope with auto-tune feature activated and deactivated.
- Result: A comparison between the two scenarios (auto-tune feature activated and auto-tune feature deactivated) will be made.
-
Configure the OSCHF to run at 4 MHz and activate or deactivate the auto-tune feature.
- Use case description: The purpose of this use case is to configure the OSCHF to run at 4 MHz, drive the main clock, and enable frequency output on the CLKOUT pin. Two frequency measurements on the CLKOUT pin will be made using an oscilloscope with auto-tune feature activated and deactivated.
- Result: A comparison between the two scenarios (auto-tune feature activated and auto-tune feature deactivated) will be made.
-
Configure the OSCHF to run at 24 MHz and activate or deactivate the auto-tune feature.
- Use case description: The purpose of this use case is to configure the OSCHF to run at 24 MHz, drive the main clock, and enable frequency output on the CLKOUT pin. Two frequency measurements on the CLKOUT pin will be made using an oscilloscope with auto-tune feature activated and deactivated.
- Result: A comparison between the two scenarios (auto-tune feature activated and auto-tune feature deactivated) will be made.
-
Configure the OSCHF to run at 4 MHz with incorrect tuning value.
- Use case description: The purpose of this use case is to configure the OSCHF to run at 4 MHz, drive the main clock, and enable frequency output on the CLKOUT pin. An error injection will be made to the tune register to check if the auto-tune mechanism will be able to correct it. Two frequency measurements on the CLKOUT pin will be made using an oscilloscope with the incorrect frequency tune input and with auto-tune feature activated.
- Result: A comparison between the two scenarios (auto-tune feature activated and incorrect tune setting) will be made.
To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.
The following peripheral and clock configurations are set up using the bare metal code inside the main.c source file for the AVR128DA48.
Setup for Use Case #1 - Configure the OSCHF to Run at 1 MHz and Activate or Deactivate the Auto-Tune Feature
The following configurations must be made for this project:
Clock:
- OSCHF as main clock source
- OSCHF frequency set to 1 MHz (CLKCTRL_FRQSEL_1M_gc)
- Enable external 32 kHz crystal oscillator
- Enable CLKOUT on PA7 pin
| Pin | Configuration |
|---|---|
| PC7 (SW0) | Digital input |
Pressing the SW0 button on the AVR128DA48 Curiosity Nano will enable the auto-tune feature, then it will disable it.
Results
The following figure presents the output signal on PA7 pin (CLKOUT) with auto-tune feature deactivated (CLK configured to run at 1 MHz).

The following figure presents the output signal on PA7 pin (CLKOUT) with auto-tune feature activated (CLK configured to run at 1 MHz).

Setup for Use Case #2 - Configure the OSCHF to Run at 4 MHz and Activate or Deactivate the Auto-Tune Feature
The following configurations must be made for this project:
Clock:
- OSCHF as main clock source
- OSCHF frequency set to 4 MHz (CLKCTRL_FRQSEL_4M_gc)
- Enable external 32 kHz crystal oscillator
- Enable CLKOUT on PA7 pin
| Pin | Configuration |
|---|---|
| PC7 (SW0) | Digital input |
Change the frequency settings to 4 MHz as described in TB3234 - Internal High-Frequency Oscillator Calibration Using the Auto-Tune Feature and program the project to the board (see instructions above).
Results
The following figure presents the output signal on PA7 pin (CLKOUT) with auto-tune feature deactivated (CLK configured to run at 4 MHz).

The following figure presents the output signal on PA7 pin (CLKOUT) with auto-tune feature activated (CLK configured to run at 4 MHz).

Setup for Use Case #3 - Configure the OSCHF to Run at 24 MHz and Activate or Deactivate the Auto-Tune Feature
The following configurations must be made for this project:
Clock:
- OSCHF as main clock source
- OSCHF frequency set to 24 MHz (CLKCTRL_FRQSEL_24M_gc)
- Enable external 32 kHz crystal oscillator
- Enable CLKOUT on PA7 pin
| Pin | Configuration |
|---|---|
| PC7 (SW0) | Digital input |
Change the frequency settings to 24 MHz as described in TB3234 - Internal High-Frequency Oscillator Calibration Using the Auto-Tune Feature and program the project to the board (see instructions above).
Results
The following figure presents the output signal on PA7 pin (CLKOUT) with auto-tune feature deactivated (CLK configured to run at 24 MHz).

The following figure presents the output signal on PA7 pin (CLKOUT) with auto-tune feature activated (CLK configured to run at 24 MHz).

The following configurations must be made for this project:
Clock:
- OSCHF as main clock source
- OSCHF frequency set to 4 MHz (CLKCTRL_FRQSEL_4M_gc)
- Enable external 32 kHz crystal oscillator
- Enable CLKOUT on PA7 pin
| Pin | Configuration |
|---|---|
| PC7 (SW0) | Digital input |
Change the frequency settings to 4 MHz with incorrect tune value as described in TB3234 - Internal High-Frequency Oscillator Calibration Using the Auto-Tune Feature and program the project to the board (see instructions above).
Results
The following figure presents the output signal on PA7 pin (CLKOUT) with incorrect tuning value (CLK configured to run at 4 MHz).

The following figure presents the output signal on PA7 pin (CLKOUT) with auto-tune feature activated (CLK configured to run at 4 MHz).

The TB3234 - Internal High-Frequency Oscillator Calibration Using the Auto-Tune Feature document provides four use cases for auto-tune implementation.
This chapter demonstrates how to use the MPLAB X IDE to program an AVR device with an Example_Project.X. This is applicable to other projects.
-
Connect the board to the PC.
-
Open the Example_Project.X project in MPLAB X IDE.
-
Set the Example_Project.X project as main project.
Right click the project in the Projects tab and click Set as Main Project.
-
Clean and build the Example_Project.X project.
Right click the Example_Project.X project and select Clean and Build.
-
Select AVRxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
Right click the project and click Properties.
Click the arrow under the Connected Hardware Tool.
Select AVRxxxxx Curiosity Nano (click the SN), click Apply and then click OK:
-
Program the project to the board.
Right click the project and click Make and Program Device.
