Você está na página 1de 27

AVR Microcontroller

Prepared by:
Eng. Ashraf Darwish

Ashraf.emad.darwish@gmail.com

Session 7

Analog To Digital Converter (ADC)


Temperature sensor (LM 35)

Introduction
Electrical quantities can be classified into :
Analoge

Digital

Range of voltage

Only two values

There are infinite values of the


volte in the range

Logic zero
0V
Logic one
5V
Any value between logic one
and logic zero is undefined.

ADC
ADC :
It

is a technique to convert analog signals to


its corresponding digital signal .

The

digital output can be saved , compared


to other digital values , pass by some
processing easily.

ADC

We have some concepts we have to know :


Resolution
Reference voltage
Error

ADC
Electrical Resolution :

electrical resolution
(voltage per step)

EF full scale voltage range


SR EFSR = VRefHi

VRefLow
M

ADC resolution in bits

ADC
Example:

If the analog input range is from 0V to 5V


the number of digital output bits (M) is 10
Then :
Electrical

resolution Q= 5/(2^10)
Q= 5/1024 = 4.88 mv

Which

means that the IC wont sense any change


less than 4.88mv

ADC

Error :
There is no ACD without error. Simply because the
analog value is approximated to the nearest digital
value Theoretically
Practically

Each analog input has corresponding


digital output

Every input sub-range has


corresponding digital output

ADC
ATmega 16 has 8 ADC channels

ADC
1- ADC Multiplexer Selection Register

(ADMUX)

2- ADC Control and Status Register A

(ADCSRA)

3- The ADC Data Register


ADCH)
4- Special Function IO Register

(ADCL and
(SFIOR)

ADC
1- ADC Multiplexer Selection Register

Reference voltage
selection

(ADMUX)

Input channel and gain


selection:
Select the ADC input pin(s)
and the gain

Left Adjust Result:


To make the output left
adjusted in the
registers

ADC

Bit 7:6 REFS1:0: Reference


Selection Bits
These bits select the reference voltage for
ADC

ADC

Bit 5 ADLAR: ADC Left Adjust Result


Write one to ADLAR to adjust the output to left. Otherwise,
the result is adjusted to right.
The

output of ADC is 10-bits so it is saved in two registers


(ADCL,ADCH). It can be left adjusted or right adjusted as
follow:

Right adjustment

Left

adjustment

ADC

Bits 4:0 MUX4:0: Analog Channel and Gain


Selection Bits
Single Ended
Mode

ADC

diferential Ended
Mode

Bits 4:0 MUX4:0: Analog Channel and Gain


Selection Bits

ADC
2- ADC Control and Status Register A

Bit 7 ADEN: ADC Enable

Bit 6 ADSC: ADC Start Conversion

(ADCSRA)

In Single Conversion mode, write this bit to one to start each


conversion.

In

Free Running
mode, write this bit to one to start the first conversion.

ADC
2- ADC Control and Status Register A

Bit 5 ADATE: ADC Auto Trigger Enable

When

this bit is written to one, Auto Triggering of the ADC is enabled.


The ADC will start a conversion on a positive edge of the selected trigger
signal. The trigger source is selected by setting the ADC Trigger Select bits, ADTS in SFIOR.

Bit 4 ADIF: ADC Interrupt Flag

This

(ADCSRA)

bit is set when an ADC conversion completes

Bit 3 ADIE: ADC Interrupt Enable

ADC

Bits 2:0 ADPS2:0: ADC Prescaler Select Bits

These bits determine the division factor of the XTAL frequency to


generate input clock to the ADC(ADC frequency).

ADC
3- The ADC Data Register ADCL and ADCH
When an ADC conversion is complete, the result is
found in these two registers
When
ADLAR=0

When
ADLAR=1

ADC
4- Special Function IO Register (SFIOR)

Bit

7,6,5:

The value of these bits selects which source will trigger an ADC
conversion

ADC
Modes of Operation :
1- single conversion mode:
Only one conversion and repeated by request (ADSC=1)
2- Auto triggering mode:
A conversion can be triggered automatically by various
sources. The trigger source is selected by setting the ADC
Trigger Select bits, ADTS in SFIOR
3- Free running mode:
Starting new conversion as soon as the ongoing conversion
has finished. The first conversion must be started by writing
one to ADSC bit in ADCSRA register

ADC Example
- I want to run ADC0 (pin 40).
- Single conversion mode.
- left adjusted and only the 8 MSB will be used.
- No ADC interrupts.
- Speed=500 000 bps.

Then:
//ADMUX =0x60
//ADCSRA= 0x80
//To start conversion
//ADCSRA|=0x40 or
//ADCSRA.6=1

ADC Example
- I want to run ADC0 (pin 40).
- Single conversion mode.
- left adjusted and only the 8 MSB will be used.
- No ADC interrupts.
- Speed=500 000 bps.

Then:
//ADMUX =0x60
//ADCSRA= 0x80
//To start conversion
//ADCSRA|=0x40 or
//ADCSRA.6=1

Temperature sensor
The most known Application of ADC

Temperature sensors (LM 35)


LM 35 is a sensor, its resistance varies with
temperature change.

It

has 3 pins
VCC
GND
Output

Final Project

links

http://www.atmel.com/products/microc
ontrollers/default.aspx?src=parent
http://www.avrfreaks.net/
http://ram-e-shop.com/oscmax/catalo
g/
http://www.nekhely.com/home-new.h
tm
http://sa.rsdelivers.com/
http://www.sparkfun.com/

Thank you
Contact:
http://www.facebook.com/groups/263197427113025
/
Ashraf.darwish@ymail.com
Ashraf.emad.darwish@gmail.com
+201064897791

Você também pode gostar