Lecture 11
Lecture 11
Chapter 13
Week 11
Biomedical Engineering Department
College of Engineering 1
5-Arithmetic, Logic
3-Branch, Call and Time 4-PIC I/O Port
Instructions, and
Delay Loop Programming
Programs
2
ADC Devices
3
ADC Devices
Analog-to-digital converters are among the most widely used
devices for data acquisition. Digital computers use binary
(discrete) values, but in the physical world everything is
analog (continuous).
4
ADC Devices
Transducers:
are also referred to as sensors.
5
Microcontroller Connection to Sensor Via ADC
Temperature, Pressure ,
light or Bio-signals
6
Microcontroller Connection to Sensor Via ADC
+VREF and – VREF
Provides the Maximum
0–5v
+ VREF and minimum digital
mapping
0 – 10V
Analog Input 8 bit
10 bit
12 bit Binary Data Output
Start Conversion 16 bit
24 bit
BITs Digital Level
8 bits 256
10 bits 1024
- VREF
12 bit 4096
16 bit 65536 7
Some of the Major Characteristics of the ADC
1) Resolution
3) Conversion time
8
Resolution
ADC has n-bit resolution, where n can be 8, 10, 12, 16, or even
24 bits.
9
Resolution Versus Step size for ADC (Vref = 5V)
Some widely used resolutions for ADCs are shown in Table 13-1
10
Conversion time
In addition to resolution, conversion time is another
major factor in judging an ADC.
Conversion time :
is defined as the time it takes the ADC to convert
the analog input to a digital (binary) number.
11
VREF
VREF is an input voltage used for the reference voltage. The
voltage connected to this pin, along with the resolution of the
ADC chip, dictate the step size.
For an 8-bit ADC, the step size is Vref / 256 because it is an 8-bit
ADC, and 2 to the power of 8 gives us 256 steps.
13
Digital data output
In an 8-bit ADC we have an 8-bit digital data output of DO-D7
while in the10-bit ADC the data output is DO--D9.
Resolution
Where Dout = digital data output (in decimal),
Vin = analog input voltage
Step size (resolution) is the smallest change, which is VREF /256
for an 8-bit ADC. 14
Digital data output
15
ADC Programing in PIC18F458
16
Analog Input Voltage
Port E (A5 to A 7)
17
PIC18F458 ADC Channel and Reference Selection
Channel Select
Port E
Analog Input
Port Configuration (PCFG)
VREF +
Port A
VREF -
18
ADC Programing in PIC18F458
The ADC peripheral of the PIC18 has the following
characteristics:
It is a 10-bit ADC
It has 8 analog input channels (RA0,1,2,3 and RA5 to RE0-RE2)
The converted output binary data is held by two SFR called
ADRESL (A/D result low) and ADRESH (A/D result high)
ADRESH:ADRESL registers gives 16 bits and the ADC data out is
only 10 bits wide, 6 bits of the 16 are unused. The upper 6 bits or
the lower 6 bits can be made unused.
ADRESH ADRESL
D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
19
ADC Data out
ADC Programing in PIC18F458
Vdd (Vcc), the voltage source of PIC18 chip itself can be used as Vref
or can be connected to an external voltage source.
The Fosc for PIC18 can be as high as 40 MHz, the conversion time
cannot be shorter than 1.6 μs.
ADON Bit:
1) The ADC feature is turned off when the microcontroller is
powered up.
2) We turn on the ADC with the ADON bit of the ADCONO
register.
ADCONO Register
21
ADCONO register
GO/DONE bit.
This bit to start conversion and monitor it to see
if conversion has ended.
The conversion time is set with the ADCS bits.
1) ADCS0
2) ADCS1
3) ADCS2
While ADCS1 and ADCS0 are held by the ADCONO
register, ADCS2 is part of the ADCON I register.
ADCONO Register
22
ADCON0
Two main things:
1) Set the conversion time 2) Select the analog input channel
23
ADCON0
Select the Analog input channel
Channel Select 8 Channels
24
ADCON0 / ADCON1
Set the conversion time:
ADCON1
25
ADCON1 register
The ADCONI register is used :
ADCON1 Register 26
ADCON1 Register
27
ADCON1 Register
ADRESH ADRESL
D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
ADRESH ADRESL
D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
28
ADCON1 Register (Port Configuration)
With PCFG = 0110, we can use all the pins of the PORTA as the
digital I/O.
In that case Vref = Vdd, the same voltage source used by the
PIC18 chip itself 30
Port Configuration (PCFG)
In many applications we need Vref other than Vdd.
In this case the Vss (Gnd) pin of the PIC18 is used for the
Vref (-). See Examples 13-2 and 13-3 (Next slide)
31
4
32
Calculating A/D Conversion time
A/D conversion time is calculated using the ADCS (A/D clock
source) bits of both the ADCON0 and ADCON1 register.
For PIC18, the conversion time is 12 times the Tad and Tad
cannot be faster than 1.6 μs.
33
Acquisition Time (Tacq)
When a specific channel is selected the voltage from that input
channel is stored in an internal holding capacitor. It takes
some time for the capacitor to get fully charged and become
equal to the applied voltage. This time is called acquisition
time (Tacq).
Although many factors (e. g., Vdd and temperature) affect the
duration of the Tacq, generally the typical value is 15 μS
34
ADC clock and conversion time
ADC Requires a clock source to do its conversion, this is called ADC
Clock.
The time period of the ADC Clock is called TAD. TAD is conversion
time per bit.
For PIC18 family, the ADC requires 12 TAD to do a 10 bit conversion.
Conversion time = 12 × TAD
FOSC/16; FOSC/32
and FOSC/64
FOSC/2 ,FOSC/4 and
36
37
& Exam
38
1 0 0 0 0 0 0 1 81
ADCONO register
1 1 0 0 1 1 1 0 CE
ADCON1 register
39
Programming PIC18F458
40
Programming PIC18F458
41
Programming PIC18F458
Unconditional branch
42
Programming PIC18F458
ADCON0
1 0 0 0 0 0 0 1 81
ADCON1
1 1 0 0 1 1 1 0 CE 43
Programming PIC18F458 in Assembly
Select an input channel