Beruflich Dokumente
Kultur Dokumente
ADC.1
Data
Bus
8
Timer0 Timer1 Timer2 ADC
PORTE
Synchronous RE0
CCPs Comparators USARTs
Serial Port RE1
RE2
RF3
RE4
RE5
RE6
Other Parallel LCD RE7
Modules Slave Port Drivers
PORTA
ADC.2
Figure 4-2 in the Reference Manual
Analog-to-Digital Conversion (ADC)
Example
Microcontroller
Electric
Circuit RA1/AN1
(ADC)
Analog Signal
x(t)
t
ADC.3
Analog-to-Digital
Conversion
Analog Signal Discrete-Time Signal
v(t) x[k]
t
k
Discrete-Amplitude Signal Digital Signal
v’(t) x’[k]
t k ADC.4
Digital-to-Analog Conversion (DAC)
Example
Microcontroller
DAC
Transducer
PIC16F877
t k
Basic Component:
ADC.6
ADC
1-bit Example
5V
2.5V
0V
5.00 V
4.375V < Vin ≤ 5.00V: Signal is 111 ‘111’
4.375 V
To A/D Converter
A/D Converter
Input Voltage
Binary Output
3.750 V
3.125V < Vin ≤ 3.750V: Signal is 101 ‘101’
3.125 V
2.500V < Vin ≤ 3.125V: Signal is 100 ‘100’
2.500 V
1.875V < Vin ≤ 2.500V: Signal is 011 ‘011’
1.875 V
1.250V < Vin ≤ 1.875V: Signal is 010 ‘010’
1.250 V
0.625V < Vin ≤ 1.250V: Signal is 001 ‘001’
0.625 V
0.000V ‹ Vin ≤ 0.625V: Signal is 000’ ‘000’
0.000 V
2.8756V 100
-0.234V 000
4.9876V 111
1.1V 001
3.2V 101
ADC.10
ADC
The PIC16F877 Microcontroller
• 10-bits:
– 210 = 1024 levels => 1023 thresholds
– Resolution = 5V/1024 = 0.0048828125 V
– Thresholds:
• 0.0048828125 V
• 0.009765625 V
• 0.0146484375 V
• Etc.
ADC.11
ADC
Implementation: Parallel-Encoded or Flash ADC
Vref = 5V
Vin
4.375V
I7
3.750V
I6
Example:
3.125V
3-bit ADC I5
O0
2.500V
I4 O1 Digital Value out
Priority
Encoder
1.875V O2
I3
1.250V
I2
0.625V I1
I0
ADC.12
Digital Logic – Revisited (?/)
Priority Encoder
I7 I6 I5 I4 I3 I2 I1 I0 O2 O1 O0
H H H H H H H L H H H
H H H H H H L X H H L
H H H H H L X X H L H
H H H H L X X X H L L
H H H L X X X X L H H
H H L X X X X X L H L
H L X X X X X X L L H
L X X X X X X X L L L
Vref = 5V Vin
4.375V
I7
3.750V
I6
Example:
3.125V
3-bit ADC I5
O0
2.500V
I4 O1 Digital Value Out
Priority
Encoder
1.875V O2
I3
1.250V
I2 Major drawback:
An n-bit ADC Requires 2n-1 comparators,
0.625V I1 thus expensive
I0 Advantage:
Highest speed ADC available
ADC.14
ADC in 16F877
- Successive Approximation ADC
Clock
Oscillator
Clear
Vin Successive Start
Approximation Data ready – End of conversion
Register
D7 Q7
D6 Q6
D5 D- Q5
D4 Flip Q4 Digital
D3
Flops
Q3 Output
D2 Q2
D1 (Latche)s Q1
D0 Q0
V
8-bit
D/A converter
Y Y Y
V < Vin V < Vin V < Vin V < Vin
N N N
ADC.16
Successive Approximation
Example – 4.3V – Step 1 – Bit 7 (D7)
5V
4.3V
D7 = 1 (1XXX XXXX)
Threshold = 2.5V
D7 = 0 (0XXX XXXX)
0V
D6 = 0 (10XX XXXX)
0V
Thresholds at : 0.01953125 V
2x0.01953125 V = 0.0390625 V
3x0.01953125 V = 0.05859375 V
…
…
ADC.19
ADC
As part of the microcontroller …
• Reference Manual:
– Section 21 & 22 (8-bit ADC),
– Section 23 (10-bit ADC)
• Datasheet:
– Section 11 (10-bit ADC)
ADC.20
ADC
As part of the microcontroller …
Timer0 Timer1 Timer2 ADC*
Data
Bus
8 PORTF
Synchronous RF0
CCPs Comparators USARTs
Serial Port RF1
RF2
RF3
RF4
RF5
RF6
Other Parallel LCD RF7
Modules Slave Port Drivers
PORTG
ADC.22
ADC.23
ADC Register (SFR) settings
ADC.24
ADC Register (SFR) settings
ADC.25
Digital input:
the standard
input as we used
it before!!
ADC.26
ADC
The result …
ADC.27
ADC
The result …
ADC.28
ADC
Outside & Inside
ADC.29
ADC
Timing …
ADC.30
Sample/Hold Acquisition Time
Tacq = Amplifier Settling Time (Tamp)
+ Holding Capacitor Charging Time (Tc)
+ Temperature Coefficient Time (Tcoff)
ADC.31
Calculations for Tc:
Capacitor Charges through Series Resistances:
ADC.32
Calculations for Tc (continued):
Tc = - (120 * 10 -12)*(18,000)*(-7.624)
Therefore: Tc = 16.5 µs
ADC.33
Finding Time for Temperature Coefficient Term (Tcoff) :
ADC.34
So total Acquisition time Tacq =
Tacq = 19.75 µs
ADC.35
ADC
Timing …
19.75 µs
(example)
ADC.36
ADC Conversion Time for
Successive Approx. Converter
Successive Approximation
ADC.37
Selecting TAD Clock Source Value
Using PIC’s in Lab:
Minimum TAD must be ≥ 1.6 µs
Select ADCS1, ADCS0 to 0,1 since this gives 2.0 µs time for TAD.
Note – You must wait at least 2 * TAD before next acquisition is started.
ADC.39
ADC
The configuration …
ADC.40
ADC
Use … Flow Chart
Configure A/D Module • Configure analog pins/
voltage reference and
digital I/O (ADCON1)
• Select ADC input
Configure A/D Interrupt*
channel (ADCON0)
• Select ADC conversion
clock (ADCON0)
Wait for TACQ • Turn on ADC module
(ADCON0)
ADC.43
ADC
Use … Flow Chart
Configure A/D Module
PIC16F877
Assume that the Oscillator
frequency clock is 4MHz
ADC.45
Example
Configure A/D Module
0 1 0 0 1 0 0 1
1 0 0 0 0 0 0 0
ADC.48
Example
Configure A/D Module
ADC.50
Code
Main Loop
…
MAIN: call DELAY ; Wait for TACQ
bsf ADCON0,2 ; Start conversion (set GO)
CHECK: btfsc ADCON0,2 ; Wait for conversion to complete*
goto CHECK ; use POLLING
movf ADRESH,W ; Read A/D result (high byte)
movwf TEMPH ; Write to TEMPH
bsf STATUS,RP0
movf ADRESL,W ; Read A/D result (low byte)
bcf STATUS,RP0
movwf TEMPL ; Write to TEMPL
nop ; 1 Wait for 4 instruction cycles
nop ;1
goto MAIN ;2
The Nyquist criterion states that, in order to prevent undesired aliasing, one
must sample a signal at a rate equal to at least twice its bandwidth.
fs > 2B
Signal
Sample bandwidth
frequency
ADC.53
Nyquist Criterion
Example
*GO/DONE = 0 ADC.56
ADC
An Example … with Push-button
VDD
RA5/AN4
RA1/AN1
Vss PIC16F877
NOTE that in this case RA5 is a DIGITAL input and RA1 is an ANALOG input
ADC.57
INIT_ADC: movlw B’01001001’
movwf ADCON0 ; Configure ADC via ADCON0
bsf STATUS, RP0 ; Access bank 1
movlw B’10000100’
movwf ADCON1 ; Configure ADC via ADCON1
movlw B’11111111’ ; Configure RA5 as an input pin
movwf TRISA
bcf STATUS, RP1
ADC.58