Skip to content

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.

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/avr128db48-timer-triggered-adc-sampling-mplab-mcc

Repository files navigation

MCHP

Timer Triggered ADC Sampling

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.

Related Documentation

Software Used

Hardware Used

Peripherals Configuration using MCC

Added Peripherals

Peripherals

System Configuration: CLKCTRL

  • CPU Clock 4 MHz

CLk Conroller

ADC0 Configuration

  • ADC Clock 1 MHz
  • 128 samples accumulated
  • 12-bit resolution
  • Analog pin AIN6

ADC0

VREF Configuration

  • Reference Voltage VDD
  • VDD = 3.3 V

VREF

TCA0 Configuration

  • 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

TCA0

USART3 Configuration

  • Printf support enabled
  • Baud rate: 9600
  • TX and RX enabled

USART3

EVENT SYSTEM Configuration

  • Channel0 : TCA Timer overflow
  • Event User: ADC START
  • Event system is configured so that ADC conversion starts on TCA overflow

Event Sys

PINS Grid View

  • USART3 TX: PB0
  • USART3 RX: PB1
  • ADC AIN6: PD6

PIN GRID

System Configuration: PINS

  • Digital input buffer is disabled on Analog pin PD6 to reduce power consumption

Peripherals

Setup

  • 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)

Operation

  1. Download the zip file or clone the example to get the source code

  2. Open the .X file with the MPLAB® X IDE

  3. Program the AVR128DB48 Curiosity nano by clicking the Make and Program Device Main Project icon as shown below

    make_and_prog

  4. Open Data Visualizer or any other serial terminal on PC.

  5. Connect the Curiosity Nano Virtual COM Port and configure baud rate to 9600.

  6. Connect any analog sensor at pin PD6 for example pot meter.

  7. Observe voltage sent to terminal.

  8. Change pot meter and observe changed voltage on terminal.

Peripherals

Summary

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published