Clase 12 - Adc

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 57

Course: Microcontrollers

Prof. Andrés Gómez


andres.gomez@docentes.umb.edu.co

UNIVERSIDAD
MANUELA BELTRÁN
Analog to Digital
Converter
Motivation

Usually, the microcontroller has to interface with analog signals from


sensor measurements (i.e. LDR, ECG, EEG, etc.). But the
microcontroller can only process digital signals.

The ADC converts an analog signal into a digital number, so that the
microcontroller can interpret the information.

There are a large number of applications of ADC like in a biometric


application, environment monitoring, gas leakage detection etc.

*http://www.electronicwings.com/pic/pic18f4550-adc
What is an ADC?

An ADC takes an analog input and generates a digital


output of n-bits
Basics of A/D Conversion

 Can convert only electrical voltages to digital values.

 A transducer is needed to convert a non-electric quantity into an


electrical voltage.

 Different transducers are used for different physical quantities.

 A data acquisition system refers to those systems that perform A/D


conversions.

𝐶𝑃𝑈

Optional but
it is useful
Basics of A/D Conversion

A/D Conversion consist of two basics steps:

1) Sampling the analog input

2) Quantization of the samples


Basics of A/D Conversion
Sampling: Captures the amplitude values (Samples) of the
time-continuous analog signal at every given sampling time.

Nyquist Theorem
for a given sample rate fs, perfect reconstruction of the sampled
signal is guaranteed possible for a signal bandlimit B < fs/2.
Basics of A/D Conversion

Characteristics of some bioelectric signals


Basics of A/D Conversion

The digital quantization is the process of mapping the


amplitude values to a discretized set of values

The number of conversion levels defines the ADC resolution.


This depends on the number of n- bits.
Basics of A/D Conversion

This figure shows how the samples can be quantized


Basics of A/D Conversion

Nyquist Theorem
for a given sample rate fs,
perfect reconstruction of the
sampled signal is
guaranteed possible for a
signal bandlimit B < fs/2.
Basics of A/D Conversion

Ideal ADC
- Digital code increases Linearly with input voltage
- Needs infinite quantized levels (bits) to encode the infinite possible voltages
- Unachievable and impractical

0V 5V
There are infinite numbers in between
Basics of A/D Conversion
Real Practical ADC
The real practical A/D converter has a transfer function with a uniform
staircase formation
A/D Module
A/D Module
An ADC compares the analog input voltage with fractions of a
voltage reference (𝑽𝑹𝑬𝑭 = 𝑽𝑹𝑬𝑭+ − 𝑽𝑹𝑬𝑭− )

𝑽𝒎𝒂𝒙

𝑽𝒎𝒊𝒏
𝑽𝑹𝑬𝑭
A/D Module – Basic Definitions
Voltage Range=𝑽𝑹𝑬𝑭+ − 𝑽𝑹𝑬𝑭−
The voltage range is divided
into 2𝑛 levels. The size of
𝑽𝑹𝑬𝑭
the level is given by: 𝒏
𝟐
𝑽𝑹𝑬𝑭 𝑽𝑹𝑬𝑭+ − 𝑽𝑹𝑬𝑭−
𝑸 = 𝟏 𝑳𝑺𝑩 = 𝒏 =
𝟐 𝟐𝒏
Quantization
Level 1 LSB corresponds to the
minimum voltage change
the system can convert

𝑽𝑭𝑺
Full Scale Voltage: sets
digital output at max level
𝑽𝑭𝑺 = 𝑽𝑹𝑬𝑭 − 𝟏𝑳𝑺𝑩
A/D Module – Basic Definitions

𝑉𝑅𝐸𝐹 = 4𝑉
𝑛=3
4𝑉
𝐿𝑆𝐵 = 3 = 0.5 𝑉
2
A/D Module – Basic Definitions

ADC RESOLUTION
The Resolution of an A/D converter is the number
of output bits it has (3 bits, in this example).

The Resolution of an A/D converter can also be


defined as the size of the LSB (Least Significant
Bit) or one count (1 Volt, in this example).

𝑽𝑹𝑬𝑭
𝑸 = 𝟏 𝑳𝑺𝑩 = 𝒏
𝟐

Q corresponds to the minimum voltage change the system can detect


A/D Module – Basic Definitions

ADC RESOLUTION
The more bits the output word has, the better the resolution!!.

Example: 3-bit ADC  8 (=23) LEVELS


10-bit ADC  1024 (=210) LEVELS

Number of LEVELS doubles when number of bits increases


A/D Module – Basic Definitions

ADC RESOLUTION
The value of an LSB depends upon the ADC Reference Voltage and Resolution

𝑽𝑹𝑬𝑭
𝑸 = 𝟏 𝑳𝑺𝑩 = 𝒏
𝟐
A/D Module – Basic Definitions

Exercise: consider an ADC which will capture data from a thermocouple


giving an output of 0.5 mV/C. What will be the n bits required for the ADC if
temperature of 0-200 °C are to be measured with a resolution of 0.5 °C?.

Solution:
Voltage Range=200x0.5=100 mV

𝟏𝟎𝟎
With n bits, this voltage will be divided into mV steps.
𝟐𝒏

For a resolution of 𝟎. 𝟓 °𝑪 we must be able to detect a signal from


the sensor of:
𝟎. 𝟓𝒙𝟎. 𝟓 = 𝟎. 𝟐𝟓 𝒎𝑽

𝟏𝟎𝟎𝒎𝑽
𝟎. 𝟐𝟓𝒎𝑽 = → 𝒏 = 𝟖. 𝟔 thus 9 bit word length is required
𝟐𝒏
ADC RESOLUTION IMPROVEMENT

Better resolution (accuracy) can be realized if we did either (or both) of two
things:

(1) use a higher resolution converter (more bits)

The problem with higher resolution (more bits) is the cost. Also, the smaller
LSB means it is difficult to find a really small signal as it becomes lost in the
noise.

(2) use a smaller reference voltage.

The problem with reducing the reference voltage is a loss of input dynamic
range.
Quantization Error

The digital output is not


always equal to the
analogue input value and
thus there will be an error
termed quantization error.

The maximum error being


equal to 1 LSB.

The maximum error we


have here is 1 LSB.
Quantization Error - Offset

But an error of 0 to 1 LSB is


not as desirable as an error of
±½ LSB. Thus, an offset is
introduced into the A/D
converter to force an error
range of ±½ LSB.

The maximum error


becomes ±𝟎. 𝟓 LSB.
Least Significant Bit
 The ADC divides the voltage reference in small levels
 There are 28 = 256 levels in an 8-bit ADC.
 The counts will look like those in the Figure below.

𝑽𝑹𝑬𝑭 𝟐𝒏 − 𝟏
𝑽𝑭𝑺 = 𝑽𝑹𝑬𝑭 − 𝟏𝑳𝑺𝑩 𝑽𝑭𝑺 = 𝑽𝑹𝑬𝑭 − 𝒏 = 𝑽𝑹𝑬𝑭 = 𝑽𝑭𝑺
𝟐 𝟐𝒏

1 LSB can be defined as follows:


𝑽𝑹𝑬𝑭 𝑽𝑭𝑺
1𝑳𝑺𝑩 = 𝒏 1𝑳𝑺𝑩 = 𝒏−𝟏
𝟐 𝟐
1) Digital Value Calculation
𝑽𝒐𝒍𝒕𝒂𝒈𝒆 𝑹𝒂𝒏𝒈𝒆 = 𝑽𝑹𝑬𝑭+ − 𝑽𝑹𝑬𝑭−

(𝑉𝑖𝑛 − 𝑉𝑅𝐸𝐹− )
𝑛
𝐷 = 𝑒𝑛𝑡 2 ⋅
𝑉𝑅𝐸𝐹+ − 𝑉𝑅𝐸𝐹−

Quantization
Level
𝑉𝑖𝑛
𝐷 = 𝑒𝑛𝑡 2𝑛 ⋅
𝑉𝐷𝐷
0 ≤ 𝑉𝑖𝑛 < 𝑉𝐷𝐷
𝑽𝑭𝑺

1 1 2
So the first digital level will span from [0 ), the second [ ),
2𝑛 2𝑛 2𝑛
2 3
the third [ ), and so...
2𝑛 2𝑛
1) Digital Value Calculation

Ejercicio:
Se dispone de un ADC de 8 bits de resolución, con voltajes de referencia
Vref+ = +10V y Vref- a tierra. Determine:

a. Valor del LSB


b. Resultado digital si se aplica VIN = 4.68 V
c. Resultado digital para VIN = 10 V.
2) Converted Voltage Calculation

Weight:
Number of LSB that
each bit represents

𝑉𝑅𝐸𝐹 𝑉𝐹𝑆
𝑉𝑂𝑈𝑇,𝐴𝐷𝐶 = 𝐷 ⋅ 𝐿𝑆𝐵 = 𝐷 ⋅ 𝑛 = 𝐷 ⋅ 𝑛
2 2 −1
*D is the digital word converted to decimal
2) Converted Voltage Calculation

Example: 8bit ADC 𝑉𝑅𝐸𝐹 = 5𝑉

𝑉𝑅𝐸𝐹 = 5𝑉

5
𝑉𝑂𝑈𝑇,𝐴𝐷𝐶 = 𝐷 ⋅ 𝐿𝑆𝐵 = 44 ∗ 8 = 0.8593
2
2) Converted Voltage Calculation
Types of Analog to
Digital Converter
Flash ADC
The flash ADC is the fastest type available.

 A flash ADC uses comparators,


one per voltage step, and a string
of resistors.

 A 4-bit ADC will have 16


comparators, an 8-bit ADC will
have 256 comparators.

 All of the comparator outputs


connect to a block of logic that
determines the output based on
which comparators are low and
which are high.

 Flash ADCs have a large power


consumption.
Successive Approximation
A successive approximation converter uses a comparator
and counting logic to perform a conversion.

𝑁𝑏𝑖𝑡𝑠
𝑡𝑐𝑜𝑛𝑣𝑒𝑟𝑠𝑖𝑜𝑛 =
𝐹𝑐𝑙𝑜𝑐𝑘

1) Check if the input is greater than half the reference voltage. If it is, the
MSB of the output is set.
2) This value is then subtracted from the input, and the result is checked for
one quarter of the reference voltage.
3) This process continues until all the output bits have been set or reset.
https://www.youtube.com/watch?v=TYCn33udOac
Successive Approximation
Algorithm Flowchart:

https://www.youtube.com/watch?v=TYCn33udOac
Sigma-Delta ADC

 A sigma-delta ADC achieves very accurate conversions. The


conversion accuracy is controlled by the input reference and the
input clock rate.

 The primary advantage of a sigma-delta converter is its high


resolution. The flash and successive approximation ADCs use a
resistor ladder whose precision affects the accuracy of the
conversion. The sigma-delta converter does not have a resistor
ladder but instead takes a number of samples to converge on a
result.

 The primary disadvantage of the sigma-delta converter is speed.


Because the converter works by oversampling the input, the
conversion takes many clock cycles. For a given clock rate, the
sigma-delta converter is slower than other converter types.
ADC Comparison
Sample and Hold
if the input signal varies by more than one least significant bit (LSB) during
the conversion time, the ADC will produce an incorrect result. One way to
handle changing inputs is to add a sample-and-hold (S/H) circuit ahead of the ADC.

 While the control signal is low


(sample), the output follows the
input.

 When the control signal goes high


(hold), the output stays at the
value the input had when the S/H
switched to hold mode.

 Typically, the S/H will be switched


to hold mode just before the ADC
conversion starts, and switched
back to sample mode after the
conversion is complete.
Sample and Hold
Imperfections:

In a perfect world, the hold capacitor would have no leakage and the buffer
amplifier would have infinite input impedance, so the output would remain
stable forever.

In the real world:

1) The hold capacitor will leak and the buffer amplifier input impedance is
finite, so the output level will slowly drift down toward ground as the
capacitor discharges.

2) The ability to hold a value is dependent on the quality of the capacitor


(leakage), the quality of the buffer amplifier (input impedance), and the
quality of the sample/hold switch (leakage).

3) Some of the input signal appears at the output, even in hold mode. This
is called feedthrough effect.
Common ADC Errors
PIC ADC
Programming
Analog to Digital Converter

 PIC18f4550 has inbuilt 10-


bit 13 channel ADC.

 13-channels of ADC (AN0-


AN12) means we can
connect 13 different sensors
at the same time.

 10-bit ADC means: It will


give digital count in the
range of 0-1023 (2^10).

The port pins needed as analog


inputs must have their
corresponding TRIS bits set to 1
(input)
Analog to Digital Converter

10 bits with digital


output
ADCON0 REGISTER

It is set to 1 to start conversion and it


automatically changes to 0 when
conversion is done
ADCON1 REGISTER

Defines the range of


the input signal to the
ADC
ADCON2 REGISTER

Result:
ADCON2 REGISTER - ACQT

Acquisition time (sampling time): time required to settle a voltage at the


holding capacitor (CHOLD). If sufficient time is not allowed, the conversion
will be inaccurate.

The required acquisition time is based on a number of factors:


• holding capacitor value (CHOLD)
• impedance of the internal analog multiplexer,
• output impedance of the analog source (RSOURCE)
• switch impedance (RSS).
ADCON2 REGISTER - ADCS

ADC Conversion Time: Time required to obtain the digital result, i.e., the
time it takes to complete a single conversion. Conversion time does not
include the acquisition time. The conversion time is usually specified in
analog-to-digital clock cycles and the minimum period for the clock is
specified to obtain the specified accuracy for the ADC.
ADCON2 REGISTER - ADCS
ADCON2 REGISTER

𝒇𝑻𝑨𝑫 = 𝑭𝑶𝑺𝑪/𝑫𝑰𝑽

𝑻𝑨𝑫 = 𝑫𝑰𝑽/𝑭𝑶𝑺𝑪

𝑇𝐴𝐶𝑄𝑇,𝑚𝑖𝑛 = 2.45𝑢𝑠 The A/D conversion time per


bit is defined as 𝑇𝐴𝐷

𝑇𝐴𝐷𝑚𝑖𝑛 = 0.8𝑢𝑠
ADCON2 REGISTER
Programming ADC
Initialization:
1. Set analog input port as input (TRIS)
2. Configure ADCON1 to select Vref (VCFG1: VCFG0), and to select port pins
required as an analog input (PCFG3: PCFG0)
3. Configure ADCON2 to select A/D result format, A/D clock and acquisition time.
4. Configure ADCON0 to select channel (CHS) and enable ADC module.
5. Flush ADC output register

OJO
Verificar!
Programming ADC
A/D conversion and Read digital values
1. Flush ADC output register
2. Start A/D conversion (Go/done’=1)
3. Wait for G0/done’ bit which is cleared when the conversion is completed.
4. Then copy conversion stored in ADRESH and ADRESL to a desired register.
Programming ADC

Make a Voltmeter and show:


a) The digital word using 10 LEDs.
b) The sensed voltage (float number) using the LCD.
Example: Programming ADC
pasos para una correcta conversión AD
- a Tabla de verdad
+ abc y1 y0 y1
- b 000 0 0
+ 001 0 1 y0
011 1 0
- c 111 1 1
+
Circuito Encoder

You might also like