This is an example for noise countermeasures for ADC applications on the ATmega4809, this is a general example which is applicable to the whole megaAVR® 0-series. In the ADCs implemented in megaAVR® 0-series, the input signal is fed through a Sample-and-Hold circuit which ensures that the input voltage to the ADC is held at a constant level during sampling.
The example code is based on the application note AN2551.
- MPLAB X IDE v6.25 or later
- Data Visualizer
- ATmega_DFP 3.4.282 or later
- XC8 (v3.00) alternatively AVR/GNU C Compiler 5.4.0 can be used
- The ADC input is mapped to
PD5
and will change the ADC values being sent over UART depending on the voltage applied
- Download the zip file or clone the example to get the source code.
- Open
atmega4809-noise-countermeasures-adc-mplab.X
in MPLAB - Connect the ATmega4809 Xplained Pro to your computer with a micro usb cable.
- Use these defines to plot a graph without noise
#define HARMONIC_NOISE 0 #define ADC_64X_ACCUMULATOR_ENABLE 0 #define SAMPLING_DELAY 0 #define ENABLE_ASDV 0
- Make sure the kit is selected as the tool to be programmed under project settings.
- Press the make and program button to program the device.
- Open data visualizer to interact with the virtual comport over UART on the devkit. The baud rate is
19200
. - Follow Appendix A in AN2551 for step by step instructions on how to graph the samples.
- Alternatively, the MPLAB Data Visualizer can be used. To start plotting data, click load workspace and choose the provided config file
MPLAB_Data_Visualizer_Config_Noise_Countermesure.json
. Make sure the correct COM port is selected when it is opened. Documentation for the MPLAB Data Visualizer can be opened inside the visualizer by clicking the ‘?’ symbol or by pressing F1
- Alternatively, the MPLAB Data Visualizer can be used. To start plotting data, click load workspace and choose the provided config file
Filtered ADC values will be passed over the UART port, these can be parsed or graphed for a visual understanding of ADC value.
We have here shown how to get started with the AN2551 appnote. For more details about the code and theory of operation please inspect the appnote itself.