
Using 12-bit ADC for Conversions, Accumulation, and Triggering Events
This repository contains examples of bare metal source code for DAC as described in "Using 12-bit ADC for Conversions, Accumulation, and Triggering Events" document from Microchip.
The repository contains an Atmel Studio Solution with multiple projects inside.
Use Cases:
- ADC Differential Conversion
- ADC Event Triggered
- ADC Free Running
- ADC Sample Accumulator
- ADC Single Conversion
- ADC Temperature Measurement
- ADC Window Comparator
Related Documentation
More details and code examples on the AVR128DA48 can be found at the following links:
Software Used
Hardware Used
Setup
The AVR128DA48 Curiosity Nano Development Board is used as test platform, inserted into the Curiosity Nano Base.

Two setups will be used for the use cases described in this document:
- The Hardware Configuration A uses a POT click, inserted in mikroBUS slot 1, connects AN1 to the PD3(AIN3) pin of AVR® DA microcontroller.

The following configurations must be made for Hardware Configuration A:
Pin |
Configuration |
PD3 (AIN3) |
Analog Input |
PC6 (LED0) |
Digital Output |
- The Hardware Configuration B uses two POT clicks, inserted in mikroBUS slot 1 and slot 2. Slot 1
connects AN1 to the PD3 (AIN3) and slot 2 connects AN2 to PD4 (AIN4) pin of the AVR® DA microcontroller.

The following configurations must be made for Hardware Configuration B:
Pin |
Configuration |
PD3 (AIN3) |
Analog Input |
PD4 (AIN4) |
Analog Input |
PC6 (LED0) |
Digital Output |
Operation
ADC Differential Conversion
This example will initialize the ADC, configure two pins for reading the differential voltage, start the conversion and read the ADC result in an infinite loop.
The Hardware Configuration B will be used for this example
- Connect the board to the PC.
- Open the AVRDA_ADC_Examples.atsln solution in Atmel Studio
- Set ADC_Differential_Conversion project as StartUp project:

- Build the ADC_Differential_Conversion project: right click on ADC_Differential_Conversion and select Build

- Select the AVR128DA48 Curiosity Nano on-board debugger in the Tool section of the AVR-Dx_Bootloader project settings:
- Right click on the project and click Properties;
- Click Tool tab on the left panel, select the corresponding debugger and save the configuration (Ctrl + S)
- Select Debug → Start Debugging and Break (Alt+F5)
- Add a brake point on
adcVal
in the main function
- Result: Rotating the Potentiometers on the POT click boards (while pressing F5 key), the adcVal result will vary from a positive to a negative value:

ADC Event Triggered
This example will initialize the ADC and Real-Time Counter (RTC), configure the Event System (EVSYS) to trigger an
ADC conversion on the RTC overflow; an LED is toggled on after each ADC conversion.
The Hardware Configuration A will be used for this example
- Connect the board to the PC.
- Open the AVRDA_ADC_Examples.atsln solution in Atmel Studio
- Set ADC_Event_Triggered project as StartUp project
- Right click on ADC_Event_Triggered and select Build
- Select the AVR128DA48 Curiosity Nano on-board debugger in the Tool section of the AVR-Dx_Bootloader project settings:
- Right click on the project and click Properties;
- Click Tool tab on the left panel, select the corresponding debugger and save the configuration (Ctrl + S)
- Result: The LED0 will toggle with a frequency of
RTC_PERIOD
, that can be modified

ADC Free Running
This example will Initialize the ADC, enable Free Running mode, start the conversion and read the ADC result in an infinite loop.
The Hardware Configuration A will be used for this example
- Connect the board to the PC.
- Open the AVRDA_ADC_Examples.atsln solution in Atmel Studio
- Set ADC_Free_Running project as StartUp project
- Right click on ADC_Free_Running and select Build
- Select the AVR128DA48 Curiosity Nano on-board debugger in the Tool section of the AVR-Dx_Bootloader project settings:
- Right click on the project and click Properties;
- Click Tool tab on the left panel, select the corresponding debugger and save the configuration (Ctrl + S)
- Select Debug → Start Debugging and Break (Alt+F5)
- Add a brake point on
adcVal
in the main function
- Result: Rotating the Potentiometer on the POT click board (while pressing F5 key ), the adcVal result will vary:

ADC Sample Accumulator
This example will Initialize the ADC, enable accumulation of 64 samples, start the conversion and read the ADC result in a loop.
The Hardware Configuration A will be used for this example
- Connect the board to the PC.
- Open the AVRDA_ADC_Examples.atsln solution in Atmel Studio
- Set ADC_Sample_Accumulator project as StartUp project
- Right click on ADC_Sample_Accumulator and select Build
- Select the AVR128DA48 Curiosity Nano on-board debugger in the Tool section of the AVR-Dx_Bootloader project settings:
- Right click on the project and click Properties;
- Click Tool tab on the left panel, select the corresponding debugger and save the configuration (Ctrl + S)
- Select Debug → Start Debugging and Break (Alt+F5)
- Add a brake point on
adcVal
in the main function
- Result: Rotating the Potentiometer on the POT click board (while pressing F5 key), the adcVal result will vary:

ADC Single Conversion
This example will initialize the ADC, start the conversion and wait until it is completed, and read ADC result in a loop.
The Hardware Configuration A will be used for this example
- Connect the board to the PC.
- Open the AVRDA_ADC_Examples.atsln solution in Atmel Studio
- Set ADC_Single_Conversion project as StartUp project
- Right click on ADC_Single_Conversion and select Build
- Select the AVR128DA48 Curiosity Nano on-board debugger in the Tool section of the AVR-Dx_Bootloader project settings:
- Right click on the project and click Properties;
- Click Tool tab on the left panel, select the corresponding debugger and save the configuration (Ctrl + S)
- Select Debug → Start Debugging and Break (Alt+F5)
- Add a brake point on
adcVal
in the main function
- Result: Rotating the Potentiometer on the POT click board (while pressing F5 key), the adcVal result will vary:

ADC Temperature Measurement
This example will initialize the ADC, select the temperature sensor as input and acquire the data by running a 12-bit, right adjusted, single-ended conversion.
The Hardware Configuration A will be used for this example
- Connect the board to the PC.
- Open the AVRDA_ADC_Examples.atsln solution in Atmel Studio
- Set ADC_Temperature_Measurement project as StartUp project
- Right click on ADC_Temperature_Measurement and select Build
- Select the AVR128DA48 Curiosity Nano on-board debugger in the Tool section of the AVR-Dx_Bootloader project settings:
- Right click on the project and click Properties;
- Click Tool tab on the left panel, select the corresponding debugger and save the configuration (Ctrl + S)
- Select Debug → Start Debugging and Break (Alt+F5)
- Add a brake point on
temp_C
in the main function
- Result: Pressing the F5 key, the
temp_C
Value will show the ambient temperature in Celsius (25°C):

ADC Window Comparator
This example will set the conversion window comparator low threshold, enable the conversion Window mode,
enable the Free Running mode, start the conversion and wait until it is completed, read the ADC result in an
infinite loop, an LED is toggled on if the ADC result is below the set threshold.
The Hardware Configuration A will be used for this example
- Connect the board to the PC.
- Open the AVRDA_ADC_Examples.atsln solution in Atmel Studio
- Set ADC_Window_Comparator project as StartUp project
- Right click on ADC_Window_Comparator and select Build
- Select the AVR128DA48 Curiosity Nano on-board debugger in the Tool section of the AVR-Dx_Bootloader project settings:
- Right click on the project and click Properties;
- Click Tool tab on the left panel, select the corresponding debugger and save the configuration (Ctrl + S)
- Result: Rotating the Potentiometer on the POT click board will modify the adcVal untill LED0 will turn off:

Summary
The *TB3245 - Using 12-Bit ADC for Conversions, Accumulation, and Triggering Events document provides seven use cases for using the 12-bit ADC of The AVR® DA family of microcontrollers.