AVR®: Using and Testing the ADC

 In this video:

  • Provide a block diagram overview of theAVR® MCU's 10-bit Successive Approximation ADC.
  • Input voltage reference options and input channels.
  • Discuss prescale and conversion timing requirements, keeping the ADC clock between 50 and 200 kHz, setting a prescalar of64, since we have aF_CPU = 8 MHz.
  • Set the range of the ADC by setting the voltage reference (to AVcc).
  • Open a new project and set writingADC_init ( ) using the datasheet as a coding reference.
  • Choose ADC1 as ADC input channel, connected to port C1 on the ATmega328P Xplained mini.
  • Configure the options in the ADC status and control register and ADC Auto Trigger Enable (ADATE).
  • Toggle an LED in the ADC ISR, so that we have a line of code to set a breakpoint on.
  • Connect a potentiometer to vary the voltage on the ADC pin.
  • Debug to verify the register configuration.
  • Example reading on the ADC result register:0x156, or342.
  • Vin = ADC * Vref / 1024 = 342 * 3.297 = 1.1011 measured by ADC, 1.104 measured by voltmeter, so 2.9 mV error or 1 LSB.
  • "AVR120: Characterization and Calibration of the ADC on the AVR MCU".

Next Video:

Updating PWM Duty Cycle from ADC Sensor Reading