This example shows how to configure the Analog-to-Digital Converter (ADC) on the AVR® DB Family of microcontrollers to trigger an ADC conversion on a specific event. The Timer/Counter type A (TCA) overflow is used to trigger the ADC sample accumulation. The ADC supports sample accumulation where configurable number of conversion results are accumulated into a single ADC result. This feature is used in the example application to accumulate 128 samples and perform averaging and measure voltage at analog pin. Measured voltage is transmitted to serial terminal through USART.
- MPLAB® X IDE v5.45 or newer
- MPLAB® Xpress IDE (alternative to MPLAB X IDE)
- XC8 Compiler v2.31 or newer
- MPLAB® Code Configurator (MCC) v4.1.0 or newer
- MPLAB® Melody Library 1.37.26 or newer or newer
- MCC Device Libraries 8-bit AVR MCUs 2.7.0 or newer
- Microchip AVR128DB48 Device Support Pack AVR-Dx_DFP 1.2.88 or newer
- MPLAB Data Visualizer in MPLAB X IDE or any other serial terminal application
- CPU Clock 4 MHz
- ADC Clock 1 MHz
- 128 samples accumulated
- 12-bit resolution
- Analog pin AIN6
- Reference Voltage VDD
- VDD = 3.3 V
- TCA clock : System Clock/4 = 1 MHz
- Timer mode: 16 bit Normal mode
- Timeout : 60ms
- Since Timeout is configured 60 ms, ADC conversion is triggered every 60 ms here
- Printf support enabled
- Baud rate: 9600
- TX and RX enabled
- Channel0 : TCA Timer overflow
- Event User: ADC START
- Event system is configured so that ADC conversion starts on TCA overflow
- USART3 TX: PB0
- USART3 RX: PB1
- ADC AIN6: PD6
- Digital input buffer is disabled on Analog pin PD6 to reduce power consumption
- Connect the AVR128DB48 Curiosity Nano board to your computer using a USB cable
- Download and install all software components as listed under 'Software Used' (note that MPLAB Xpress IDE is an online tool that cannot be downloaded)
-
Download the zip file or clone the example to get the source code
-
Open the .X file with the MPLAB® X IDE
-
Program the AVR128DB48 Curiosity nano by clicking the Make and Program Device Main Project icon as shown below
-
Open Data Visualizer or any other serial terminal on PC.
-
Connect the Curiosity Nano Virtual COM Port and configure baud rate to 9600.
-
Connect any analog sensor at pin PD6 for example pot meter.
-
Observe voltage sent to terminal.
-
Change pot meter and observe changed voltage on terminal.
This example shows how to configure the Analog-to-Digital Converter (ADC) to trigger a conversion on a specific event. The Timer/Counter type A (TCA) overflow is used to trigger the ADC sample accumulation and ADC result is transmitted through USART.