AVR®: Using and Testing the ADC

 In this video:

  • Provide a block diagram overview of the AVR® 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 of 64, since we have a F_CPU = 8 MHz.
  • Set the range of the ADC by setting the voltage reference (to AVcc).
  • Open a new project and set writing ADC_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, or 342.
  • 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

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.