Professional Documents
Culture Documents
ADC.15
If 4.3 volts is input to A/D converter,
What is the binary output from the A/D converter?
4.3V / resolution = 220.16 => 220 = binary value = 1101 1100
Example: 10-bit A/D
Voltage input range: 0V 5V
Number of bits: 10 => 2
10
= 1024 levels (= 1023 thresholds) Number of bits: 10 => 2 = 1024 levels (= 1023 thresholds)
Resolution = 5V / 1024 = 0.004882813 V
Thresholds at : 0.004882813 V
2x 0.004882813 V = 0.009765625 V
3x 0.004882813 V = 0.014648438 V
ADC.16
If 4.3 volts is input to A/D converter,
What is the binary output from the A/D converter?
4.3V / resolution = 880.64 => 880 = binary value = 11 0111 0000
9
ADC
As part of the microcontroller
Reference Manual:
Section 21 & 22 (8-bit ADC),
Section 23 (10-bit ADC)
Datasheet:
ADC.17
Section 11 (10-bit ADC)
ADC
As part of the microcontroller
Timer0 Timer1 Timer2 ADC*
Data
PORTF
RF0
RF1
RF2
RF3
RF4
RF5
RF6
RF7
CCPs Comparators
Synchronous
Serial Port
USARTs
Other
Modules
Parallel
Slave Port
LCD
Drivers
8
Bus
ADC.18
PORTG
RG0
RG1
RG2
RG3
RG4
RG5
RG6
RG7
Voltage
Reference
Data
EEPROM
*or A/D
10
ADC
The configuration
ADC.19
ADC.20
11
ADC Register (SFR) settings
ADC.21
ADC Register (SFR) settings
ADC.22
12
Digital input:
the standard
input as we
used it before!!
ADC.23
used it before!!
ADC
The result
ADC.24
13
ADC
The result
ADC.25
ADC
Outside & Inside
ADC.26
14
ADC
Timing
ADC.27
Sample/Hold Acquisition Time
Tacq = Amplifier Settling Time (Tamp) q p g ( p)
+ Holding Capacitor Charging Time (Tc)
+ Temperature Coefficient Time (Tcoff)
Tacq = Tamp + Tc + Tcoff
Tamp = 2 s for PIC 16F877
ADC.28
p
Next few slides find Tc & Tcoff:
15
Calculations for Tc:
Capacitor Charges through Series Resistances:
Rs = External signals source resistance (use 10,000 in lab)
Ric = Interconnect Resistance (Ric 1 000 ohm) Ric = Interconnect Resistance (Ric 1,000 ohm)
Rss = Sample Switch Resistance (function of Vdd)
(for Vdd = 5v, Rss = 7,000 ohm)
CHOLD = Capacitor = 120 * 10
-12
farads
ADC.29
So Time for capacitor to charge:
Tc = - CHOLD*( Rs + Ric + Rss) * ln (1/2047)
Calculations for Tc (continued):
Tc = - CHOLD( Rs + Ric + Rss) * ln (1/2047)
Tc = - (120 * 10
-12
)( 10,000 + 1,000 + 7,000) * ln (1/2047)
Tc = - (120 * 10
-12
)*(18,000)*(-7.624)
ADC.30
Tc = 16.5 s Therefore:
16
Finding Time for Temperature Coefficient Term (Tcoff) :
Tcoff = (Operating Temp in C - 25C)*(0.05s/C
Lets assume worst case Operating Temperature is 50C (= 122F)
Tcoff = (50C - 25C)*(0.05s/C)
ADC.31
Therefore: Tcoff = 1.25 s
So total Acquisition time Tacq =
Tacq = Tamp + Tc + Tcoff q p
Tacq = 2 s + 16.5 s + 1.25 s
Tacq = 19.75 s
ADC.32
With our 4 MHz PICs in lab (1 s instruction cycle)
We would delay 20 s before we start conversion (GO is set)
17
ADC
Timing
19.75 s
(example)
ADC.33
(example)
ADC Conversion Time for
Successive Approx. Converter
Successive Approximation
T must be 1 6s
Takes 11.5 TAD for conversion
ADC.34
T
AD
must be 1.6s
18
Selecting T
AD
Clock Source Value
Using PICs in Lab:
Minimum T
AD
must be 1.6 s
PICs in Lab use 4 MHz oscillator, so Tosc = 0.250 s
We need to set ADCS1, ADCS0 bits in ADCON0 to select T
AD
:
ADCS1,ADCS0 Operation T
AD
Time
0 0 2 * Tosc 0.50 s
0 1 8 * T 2 00
ADC.35
0 1 8 * Tosc 2.00 s
1 0 32 * Tosc 8.00 s
1 1 use internal RC ( 2 6 s )
Select ADCS1, ADCS0 to 0,1 since this gives 2.0 s time for T
AD
.
So A/D conversion Time = 11.5 * 2.0 s = 23 s
Time for A/D Conversion - Summary
19.75 s
(example)
11.5 * TAD
= 23 s
ADC.36
Note You must wait at least 2 * TAD before next acquisition is started.
19
ADC
The configuration
ADC.37
ADC
Use Flow Chart
Configure A/D Module
Configure analog
pins/voltage reference
and digital I/O
(ADCON1)
Configure A/D Interrupt*
Wait for T
ACQ
Start Conversion (set GO)
W i f i
(ADCON1)
Select ADC input
channel (ADCON0)
Select ADC conversion
clock (ADCON0)
Turn on ADC module
(ADCON0)
ADC.38
*if desired
Wait for conversion
to complete
Read A/D Result
Wait for at least 2T
AD
before next acquisition
20
ADC
Use Flow Chart
Configure A/D Module
Clear ADIF bit
Configure A/D Interrupt*
Wait for T
ACQ
Start Conversion (set GO)
W i f i
Clear ADIF bit
Set ADIE bit
Set PEIE bit
Set GIE bit
ADC.39
*if desired
Wait for conversion
to complete
Read A/D Result
Wait for at least 2T
AD
before next acquisition
ADC
The interrupt
ADC.40
21
ADC
Use Flow Chart
Configure A/D Module
Configure A/D Interrupt*
Wait for T
ACQ
Start Conversion (set GO)
W i f i
Use POLLING:
Keep checking the DO/DONE
bit, if it is cleared the
conversion is done.
Use INTERRUPTS:
Wait for the ADC interrupt
ADC.41
*if desired
Wait for conversion
to complete
Read A/D Result
Wait for at least 2T
AD
before next acquisition
ADC
An Example
PIC16F877
RA1/AN1
Write a program that makes
continuous measurements of
the output voltage of the microphone
and writes the results to TEMPH (0x20)
and TEMPL (0x21)
Assume that the Oscillator
ADC.42
frequency clock is 4MHz
22
Example
Configure A/D Module
Configure A/D Interrupt* Configure A/D Interrupt
Wait for T
ACQ
Start Conversion (set GO)
Wait for conversion
ADC.43
f
to complete
Read A/D Result
Wait for at least 2T
AD
before next acquisition
Example
Configure ADC Module
0 1 0 0 1 0 0 1
RA1/AN1 thus
CHS2:CHS0 = 001
Conversion clock
4MHz < 5MHz thus
ADCS1:ADCS0 = 01
Turn on Module:
ADON = 1
ADC.44
RA1/AN1 thus
PCFG3:PCFG0 = 0000
1 0 0 0 0 0 0 0
Result is Right Justified
thus ADFM = 1
23
Code
Configure ADC Module
ADCON0 equ 0x1F ADCON0 equ 0x1F
ADCON1 equ 0x1F
org 0x000
INIT_ADC: movlw B01001001
movwf ADCON0 ; Configure ADC via ADCON0
bsf STATUS, RP0 ; Access bank 1
movlw B10000000
movwf ADCON1 ; Configure ADC via ADCON1
bcf STATUS, RP0 ; Switch back to bank 0
ADC.45