Upload
jhonson-arturo-jorges-huaman
View
224
Download
0
Embed Size (px)
Citation preview
8/9/2019 The ADC of the AVR1
1/14
The ADC of the AVRAnalog to Digital Conversion
Most real world data is analog. Whether it be temperature,
pressure, voltage, etc, their variation is alwas analog in nature. !or e"ample, the
temperature inside a boiler is around #$$%C. During its light&up, the temperature
never approaches directl to #$$%C. 'f the ambient temperature is ($$%C, it will
start increasing graduall to ()$%C, )$$%C and thus reaches #$$%C over a period
of time. This is an analog data.
*ignal Ac+uisition rocess
-ow, we must process the data that we have received. ut analog signal
processing is +uite inefficient in terms of accurac, speed and desired output.
/ence, we convert them to digital form using an Analog to Digital Converter 0ADC1.
*ignal Ac+uisition rocess'n general, the signal 0or data1 ac+uisition process has 2 steps.
'n the Real World, a sensorsenses an phsical parameter and converts
into an e+uivalent analog electrical signal.
!or efficient and ease of signal processing, this analog signal is converted
into a digital signal using an Analog to Digital Converter (ADC).
http://maxembedded.wordpress.com/2011/06/18/sensor-fundamentals/http://maxembedded.wordpress.com/2011/06/18/sensor-fundamentals/8/9/2019 The ADC of the AVR1
2/14
This digital signal is then fed to the Microcontroller (MCU)and is
processed accordingl.
ADC ins 3 ATM45A67829
'nterfacing *ensors'n general, sensors provide with analog output, but a MC: is a digital one. /ence
we need to use ADC. !or simple circuits, comparator op&s can be used. ut
even this won;t be re+uired if we use a MC:. We can straightawa use the inbuilt
ADC of the MC:. 'n ATM45A67829,
8/9/2019 The ADC of the AVR1
3/14
Right now, we are concerned about the 8 channel 10 bit resolutionfeature.
8 channelimplies that there are # ADC pins are multiple"ed together. >ou
can easil see that these pins are located across
8/9/2019 The ADC of the AVR1
4/14
The ADC of the AVR converts analog signal into digital signal at some regular
interval. This interval is determined b the cloc fre+uenc. 'n general, the ADC
operates within a fre+uenc range of )$/F to 9$$/F. ut the C: cloc
fre+uenc is much higher 0in the order of M/F1. *o to achieve it, fre+uenc division
must tae place. The prescaler acts as this division factor. 't produces desired
fre+uenc from the e"ternal higher fre+uenc. There are some predefined division
factors 3 9, (, #, 67, 29, 7(, and 69#. !or e"ample, a prescaler of 7( implies
!GADC B !GC:87(. !or !GC: B 67M/F, !GADC B 67M87( B 9)$/F.
-ow, the maHor +uestion is? which fre+uenc to selectI
8/9/2019 The ADC of the AVR1
5/14
ADC Voltage Reference ins
The ADC needs a reference voltage to wor upon. !or this we have a three pins
AR4!, AVCC and 5-D. We can suppl our own reference voltage across AR4!
and 5-D. !or this, choose the irst o,tion. Apart from this case, ou can either
connect a capacitor across AR4! pin and ground it to prevent from noise, or ou
ma choose to leave it unconnected. 'f ou want to use the VCC 0J)V1, choose
the second o,tion.
8/9/2019 The ADC of the AVR1
6/14
8/9/2019 The ADC of the AVR1
7/14
'nput Channel and 5ain *elections
Thus, to initialiFe ADM:, we writeADMUX = (1
8/9/2019 The ADC of the AVR1
8/14
ADC rescaler *elections
Assuming TAE fre+uenc of 67M/F and the fre+uenc range of )$/F&9$$/F,
we choose a prescaler of 69#.
Thus, !GADC B 67M869# B 69)/F.
Thus, we initialiFe ADC*RA as follows.ADCSRA = (1
8/9/2019 The ADC of the AVR1
9/14
ADC Data Registers 0ADEAR B 61
>ou can ver well see the the effect of ADEAR bit 0in ADM: register1. :pon
setting ADEAR B 6, the conversion result is left adHusted.
*!'
8/9/2019 The ADC of the AVR1
10/14
These options are will be discussed in the posts related to timers. Those who have
prior nowledge of timers can use it. The rest can leave it for now, we won;t be
using this anwa.
ADC 'nitialiFationThe following code segment initialiFes the ADC.1
2
3
4
5
6
7
8
9
!"#a#c$"%"&()' // AREF = Acc ADMUX = (1
8/9/2019 The ADC of the AVR1
11/14
EDR Connections
-ow suppose we want to displa the corresponding ADC values in an ECD. *o, we
also need to connect an ECD to our MC:. Read this post to now about ECD
interfacing.
*ince it is an EDR, it senses the intensit of light and accordingl change its
resistance. The resistance decreases e"ponentiall as the light intensit increases.
*uppose we also want to light up an E4D whenever the light level decreases. *o,
we can connect the E4D to an one of the 5'< pins, sa C$.
-ote that since the ADC returns values in between $ and 6$92, for dar conditions,
the value should be low 0below 6$$ or 6)$1 whereas for bright conditions, the value
should be +uite high 0above N$$1.
-ow let;s write the complete code.
4"ample CodeTo learn about ECD interfacing, view thispost. >ou can tpe, compile and build it in
AVR *tudio ). View thispage to now how. To now about the '8< port operations
in AVR, view thispage.I
1
2
?"%cl.#e
8/9/2019 The ADC of the AVR1
12/14
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
?"%cl.#e Blc#@B
?#e*"%e RES ,00?#e*"%e RRES ,00
// "%"&"al"e a#c!"#a#c$"%"&()' // AREF = Acc ADMUX = (1
8/9/2019 The ADC of the AVR1
13/14
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
3"le(1) ' a#c$res.l&0 = a#c$rea#(0); // rea# a#c al.e a& PA0 a#c$res.l&1 = a#c$rea#(1); // rea# a#c al.e a& PA1
// c!%#"&"!% *!r le# &! l!3
"*(a#c$res.l&0 < RES 99 a#c$res.l&1 < RRES) PRC = 0:01; else PRC = 0:00;
// %!3 #"spla6 !% lc#
"&!a(a#c$res.l&0> "%&$.**er> 10); lc#$!&!:6(12>0); lc#$p.&s("%&$.**er);
"&!a(a#c$res.l&0> "%&$.**er> 10);
lc#$!&!:6(12>1); lc#$p.&s("%&$.**er); $#ela6$s(,0); --
*ensor CalibrationCalibration means lining our real world data with the virtual data. 'n the problem
statement given earlier, ' have mentioned that the E4D should glow if the light
intensit reduces. ut whenshould it start to glowI The MC:8code doesn;t now
b itself. >ou get the readings from the sensor continuousl in between $ and 6$92.
*o, the +uestion is how do we know that below such and such level the LED
should glow?
This is achieved b calibration. >ou need to phsicall set this value. What ou do
is that ou run the sensor for all the lighting conditions. >ou have the ADC values
for all these levels. -ow, ou need to phsicall see and chec the conditions
ourself and then appl a threshold. elow this threshold, the light intensit goes
sufficientl down enough for the E4D to glow.
8/9/2019 The ADC of the AVR1
14/14
The potentiometer connected in the circuit is also for the same reason. -ow, b the
basic nowledge of electronics, ou could easil sa that upon changing the pot
value the ADC value changes. Thus, for various reasons 0lie poor lighting
conditions, ou are unable to distinguish between bright and dar conditions, etc1,
ou can var the pot to get desired results.
This is wh ' have given the two thresholds 0RT/R4* anf ET/R4*1 in the
beginning of the code.
*o, this is all with the ADC. ' hope ou enHoed reading this. 7lease ,ost the
coents belo! or an# suggestion9 doubt9 clariication9 etc: