Analog to digital conversion in AVR Microcontrollers (Chapter 13 of - - PowerPoint PPT Presentation

analog to digital conversion in avr microcontrollers
SMART_READER_LITE
LIVE PREVIEW

Analog to digital conversion in AVR Microcontrollers (Chapter 13 of - - PowerPoint PPT Presentation

Microprocessors, Lecture 10: Analog to digital conversion in AVR Microcontrollers (Chapter 13 of the text book) Contents ADC units of ATmega32 ADC programming in C University of Tehran 2 ADC in AVR University of Tehran 3 ADC


slide-1
SLIDE 1

Analog to digital conversion in AVR Microcontrollers

Microprocessors, Lecture 10:

(Chapter 13 of the text book)

slide-2
SLIDE 2

University of Tehran 2

Contents

  • ADC units of ATmega32
  • ADC programming in C
slide-3
SLIDE 3

University of Tehran 3

ADC in AVR

slide-4
SLIDE 4

University of Tehran 4

ADC

  • Typical usage of ADC (analog to digital

convertors)

slide-5
SLIDE 5

University of Tehran 5

ADC

  • A typical ADC
  • Vref= the maximum allowable volatge
slide-6
SLIDE 6

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

slide-7
SLIDE 7

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
slide-8
SLIDE 8

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

slide-9
SLIDE 9

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
slide-10
SLIDE 10

University of Tehran 10

ADMUX register

slide-11
SLIDE 11

University of Tehran 11

ADMUX register

  • Select the reference voltage (the maximum

acceptable input channel voltage)

slide-12
SLIDE 12

University of Tehran 12

ADMUX register

  • Which bits of ADCH and ADCL are unused
slide-13
SLIDE 13

University of Tehran 13

ADMUX register

  • Which channel is selected to the ADC

– Can also work in differential mode

slide-14
SLIDE 14

University of Tehran 14

ADCSRA register

  • ADC control and status register

– Control and monitor the ADC

slide-15
SLIDE 15

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!

slide-16
SLIDE 16

University of Tehran 16

ADCSRA register

  • Selecting the ADC clock
slide-17
SLIDE 17

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

slide-18
SLIDE 18

University of Tehran 18

ADC programming in C

slide-19
SLIDE 19

University of Tehran 19

ADC programming in C

A 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

  • nce the

conversion is completed

slide-20
SLIDE 20

University of Tehran 20

ADC programming in C

A program that coverts the analog voltage of ADC0 and copies it to portD and portB

  • -interrupt method
slide-21
SLIDE 21

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

slide-22
SLIDE 22

University of Tehran 22

Connecting sensors to AVR- example

slide-23
SLIDE 23

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)

slide-24
SLIDE 24

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
slide-25
SLIDE 25

University of Tehran 25

ADC programming in C in CodeVision

  • Set different values in the project setup wizard