microprocessors, lecture 10: analog to digital conversion...
TRANSCRIPT
![Page 1: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/1.jpg)
Analog to digital conversion in AVR Microcontrollers
Microprocessors, Lecture 10:
(Chapter 13 of the text book)
![Page 2: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/2.jpg)
University of Tehran 2
Contents
• ADC units of ATmega32
• ADC programming in C
![Page 3: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/3.jpg)
University of Tehran 3
ADC in AVR
![Page 4: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/4.jpg)
University of Tehran 4
ADC
• Typical usage of ADC (analog to digital convertors)
![Page 5: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/5.jpg)
University of Tehran 5
ADC
• A typical ADC• Vref= the maximum allowable volatge
![Page 6: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/6.jpg)
University of Tehran 6
ADC resolution
• Step size: the difference between two consecutive output nembers
• For a 8-bit output and Vref=5v, – step size= 5/246
![Page 7: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/7.jpg)
University of Tehran 7
ADC internal structure
• Successive approximation method– See page 468 of the book for algorithm details
• n steps for an n-bit output ADC• Requires n cycles to calculate digital output
![Page 8: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/8.jpg)
University of Tehran 8
ADC in ATmega32
• 7 analog input channels
– Just one ADC multiplexed by input channels
• 10-bit output– Kept in ADCL and
ADCH registers– 6 unused bits, can
be set the upper or lower 6 bits
![Page 9: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/9.jpg)
University of Tehran 9
AVR ADC Registers
• ADCL and ADCH to keep digital data• ADCSRA to control ADCs• ADMux to select one input channel for
conversion• SPIO, special function register
![Page 10: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/10.jpg)
University of Tehran 10
ADMUX register
![Page 11: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/11.jpg)
University of Tehran 11
ADMUX register
• Select the reference voltage (the maximum acceptable input channel voltage)
![Page 12: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/12.jpg)
University of Tehran 12
ADMUX register
• Which bits of ADCH and ADCL are unused
![Page 13: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/13.jpg)
University of Tehran 13
ADMUX register
• Which channel is selected to the ADC– Can also work in differential mode
![Page 14: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/14.jpg)
University of Tehran 14
ADCSRA register
• ADC control and status register– Control and monitor the ADC
![Page 15: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/15.jpg)
University of Tehran 15
ADCSRA register
• ADATE bit
• Sets the operation mode of ADC• 0= single conversion
– Converts the input just one time every time ADSC becomes 1
• 1= free running – Continuously converts the input to digital values
with some frequency– For ADATE=1 we have more ADC options, Take a
look at AVR documents for more details if you are interested!
![Page 16: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/16.jpg)
University of Tehran 16
ADCSRA register
• Selecting the ADC clock
![Page 17: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/17.jpg)
University of Tehran 17
ADC clock
• Determines the speed of sampling the input data
– Each conversion takes around 13 ADC clocks• Larger frequency has smaller accuracy• In AVR, frequency have to be less than 200
kHz• Set it to smaller frequency (ADPS[0..2]=111) if
speed is not critical
![Page 18: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/18.jpg)
University of Tehran 18
ADC programming in C
![Page 19: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/19.jpg)
University of Tehran 19
ADC programming in CA program that coverts the analog voltage of ADC0 and copies it to portD and portB--polling method
•The ADSC bit should be 1 for the ADC to start conversion•Returns to 0 automatically once the conversion is completed
![Page 20: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/20.jpg)
University of Tehran 20
ADC programming in CA program that coverts the analog voltage of ADC0 and copies it to portD and portB--interrupt method
![Page 21: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/21.jpg)
University of Tehran 21
Connecting sensors to AVR
• Transducer (sensor): convert environment parameters (temperature, pressure, velocity,…) to electrical quantities (voltage, current, capacitance, resistance)
• Signal conditioning: converting electrical quantities to voltage
![Page 22: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/22.jpg)
University of Tehran 22
Connecting sensors to AVR-example
![Page 23: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/23.jpg)
University of Tehran 23
Connecting LM35 to AVR
• In AVR:– Vref=2.56v– 10 bit output, 1024 values step size=2.56/1024= 2.5
mv
• In LM34:– for 1 degree increase in temperature, we have 10mv
increase in output voltage If the temperature increases by one degree:
– 10mv increase in sensor output– 10/2.5=4 increase in ADC output
• Divide the ADC result by 4 to get actual temperature (shift right 2 times)
![Page 24: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/24.jpg)
University of Tehran 24
Connecting LM35 to AVR
• Example: temp= 20 degrees, sensor output= 200mv (10mv for every degree), this voltage is converted to 0x1010000=80 (200mv/2.5mv=80) by the ADC
• Divide by 4 to get actual temperature by ADC
![Page 25: Microprocessors, Lecture 10: Analog to digital conversion ...ce.sharif.edu/courses/93-94/2/ce513-1/resources/root/Slides/Micro-L10-ADC.pdf · Analog to digital conversion in AVR Microcontrollers](https://reader030.vdocument.in/reader030/viewer/2022040906/5e7c276a3c266518f8235769/html5/thumbnails/25.jpg)
University of Tehran 25
ADC programming in C in CodeVision
• Set different values in the project setup wizard