0% found this document useful (0 votes)
19 views44 pages

Lecture 11

Desc for whole micro

Uploaded by

nqm9frn4vq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
19 views44 pages

Lecture 11

Desc for whole micro

Uploaded by

nqm9frn4vq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 44

BIOEN 442: Microprocessor

Chapter 13

Analog To Digital Converter

Week 11
Biomedical Engineering Department
College of Engineering 1

Imam Abdulrahman Bin Faisal University, Saudi Arabia


Today's topic

0- Course 1- Pic 2- PIC Architecture PIC


Overview /Introduction Microcontrollers:history Programming using
to Computing and features Assembly Language

5-Arithmetic, Logic
3-Branch, Call and Time 4-PIC I/O Port
Instructions, and
Delay Loop Programming
Programs

17- Motor Control:


12-LCD and Keypad 13- ADC, DAC and
Relay, PWM, DC and
Interfacing sensor interfacing
Stepper Motors

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).

 Temperature, pressure (wind or liquid), humidity, and


velocity are a few examples of physical quantities that we deal
with every day.

 A physical quantity is converted to electrical (voltage,


current) signals using a device called a transducer.

4
ADC Devices
 Transducers:
are also referred to as sensors.

 Sensors for temperature, velocity, pressure, light, and


many other natural quantities produce an output that is
voltage (or current). Therefore, we need an analog to-
digital converter to translate the analog signals

5
Microcontroller Connection to Sensor Via ADC

Electrical form Digital form

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

2) Reference voltage VREF

3) Conversion time

4) Digital data output

8
Resolution
 ADC has n-bit resolution, where n can be 8, 10, 12, 16, or even
24 bits.

 The higher-resolution ADC provides a smaller step size, where


step size is the smallest change that can be discerned by an
ADC.

 The resolution of an ADC chip is decided at the time of its


design and cannot be changed, we can control the step size
with the help of what is called Vref.

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.

The conversion time is dictated by the clock source


connected to the ADC

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.

 For example: If the analog input range needs to be 0 to 4 volts,


VREF is connected to 4 volts. That gives 4 V/256 = 15.62 mV
for the step size of an 8-bit ADC.

 In another case, if we need a step size of 10 mV for an 8-bit


ADC, then Vref = 2.56 V, because 2.56 V/256 = 10 mV.
12
Vref Relation to Vin Range for an 8-bit ADC

Vref Relation to Vin Range for an 10-bit ADC

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.

 To calculate the output voltage, we use the following formula :

Analog input voltage

Digital data output

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 A (A0 to A4)

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 conversion time is dictated by the Fosc of crystal frequency


connected to the OSCs pins.

 The Fosc for PIC18 can be as high as 40 MHz, the conversion time
cannot be shorter than 1.6 μs.

 It allows the implementation of the differential Vref voltage using the


Vref (+) and Vref (-) pins where Vref = Vref (+)-Vref (-)

The above features can be programmed by way of


ADCON0 (A/D control register 0) and ADCON1 (A/D control register 1)
20
ADCONO register
 The ADCONO register is used to:
1) Set the conversion time
2) Select the Analog input channel

 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

Channel Select 8 Channels

23
ADCON0
Select the Analog input channel
Channel Select 8 Channels

24
ADCON0 / ADCON1
Set the conversion time:

Conversion Time ADCON0

ADCON1

25
ADCON1 register
 The ADCONI register is used :

 To select the VREF voltage.

 After the A/D conversion is complete, the result sits in reg-


isters ADRESL (A/D Result Low Byte) and ADRESH
(A/D Result High Byte).

 The ADFM bit of the ADCON1 is used for making it


right-justified or left-justified because we need only 10 bits
of the 16

ADCON1 Register 26
ADCON1 Register

Set the conversion time

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)

 A=Analog input, D=Digital I/O


 C/R= # of analog input channels / # of pins used for A/D voltage reference
 The default is option 0000, which gives us 8 channels of analog input and
uses the Vdd of PIC18 as Vref. 29
Port Configuration (PCFG)
 The port configuration for A/D channels is handled by the PCFG
(A/D port configuration) bits.

 The PORTA pins of RA0-RA3 and RA5 and RE0-RE2 of


PORTE are used for the analog input channels.

 With PCFG = 0110, we can use all the pins of the PORTA as the
digital I/O.

 The default is PCFG = 0000, which allows us to use all 8 pins


for analog inputs.

 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.

 The AN3 pin can be used as an external source of voltage


for Vref.

 For example, option PCFG = 0101 allows us to use two


channels for analog inputs, AN3 = Vref, and the other 5 pins
for the digital I/O.

 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.

 The conversion time is defined as Tad, where Tad is the


conversion time per bit.

 To calculate the Tad, a conversion clock source of Fosc/2, Fosc/4,


Fosc/8, Fosc/16, Fosc/32 or Fosc/64
where Fosc is the speed of the crystal frequency
connected to the chip.

 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).

 Once acquisition time is over the input channel is disconnected


from the source and the conversion begin.

 Since ADC provides a programmable acquisition time,


acquisition time it can be set.

 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

 TAD can be derived from the CPU clock by dividing it by a suitable


division factor. FOSC is the crystal frequency
connected to the PIC18 Chip

TAD cannot be faster than 1.6 μS

Conversion time = 12 × 1.6 = 19.2 μS

  Internal RC clock can also be used instead of FOSC
 In that case TAD is 4 to 6 μS

 Conversion time = 12 × 6 = 72 μS
 35
BIOEN 442: Microprocessor
FOSC/8

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

Select output channels

Send the control data

Activate the start conversion (SC) signal to start the conversion of


analog input
DELAY Conversion in
progress
Keep monitoring the
end-of-conversion (EOC) signal
1
0

After the EOC has been activated, read data out of


the ADC chip and send to output port
44

You might also like