0% found this document useful (0 votes)
9 views54 pages

T7 Adc

The document discusses the principles of analog to digital conversion (ADC) and digital to analog conversion (DAC), highlighting the importance of resolution and sampling frequency in accurately representing analog signals in digital form. It describes various types of ADCs, their components, and the specific registers used in the PIC18 microcontroller for managing these conversions. Additionally, it addresses the Nyquist criterion for sampling rates to avoid aliasing and provides examples of practical applications such as temperature control and barometric measurement.

Uploaded by

Miguel Carrasco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views54 pages

T7 Adc

The document discusses the principles of analog to digital conversion (ADC) and digital to analog conversion (DAC), highlighting the importance of resolution and sampling frequency in accurately representing analog signals in digital form. It describes various types of ADCs, their components, and the specific registers used in the PIC18 microcontroller for managing these conversions. Additionally, it addresses the Nyquist criterion for sampling rates to avoid aliasing and provides examples of practical applications such as temperature control and barometric measurement.

Uploaded by

Miguel Carrasco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Analog Interfaces

Connecting analog world


to digital computers
Dpt. Enginyeria de Sistemes, Automàtica i Informàtica Industrial
Some analog magnitudes

Barometer / altimeter
Air pressure.

Audio

… Temperature
Analog to Digital Conversion

World is analog …
but computers deal with digital information.

ADC: Representing a continuously varying


physical quantity by a sequence of discrete
numerical values.

03, 07, 10, 14, 09, 02, 00, 04, …


Basic of A/D Conversion
Analog to digital converter concept (ADC)

ADC Scheme (with a synchrony signal End of conversion)

VREF+

N bits
Vin
ADC Dout

End of conversion

VREF-

Conversion command
Analog versus Digital
N bits
Vref+ 11…1111
Vref+ 11…1110
11…1101
11…1100

2N
Output
Vref-
codes
00…0110
Resolution of ADC = (Vref+ - Vref- )/(2N - 1) 00…0101
00…0100
00…0011
¿Digital codes obtained represent 00…0010
EXACTLY the original analog value? 00…0001
… NO! There’s an ERROR Vref- 00…0000
Quantization error: ± 0.5 LSB
V

00…0100 4 LSB

00…0011 3 LSB
Exact value

Error 00…0010 2 LSB

Obtained value
00…0001 1 LSB

Resolution
00…0000
t

Ts
Sampling Maximum conversion error = ADCresolution / 2
period
Average conversion error = 0
Devices

1. ADC: A/D Flash Converter

2. DAC: Digital to Analog Converter *

3. ADC: Slope A/D Converter

4. ADC: Successive approximations A/D Converter *

* These devices can be found on PIC18F45K22


1. A/D Flash

Comparator
2. Digital to Analog Converter (DAC)
Possible implementation:
Symbol String Resistor ladder

VREF+

N bits
Vout
Din DAC

VREF-

Convert

D0 D1 D2
2. Digital to Analog Converter (DAC)
Possible implementation:
R/2R Resistor ladder
3. Slope A/D converter
Counter
Register

VREF+
VREF-
4. Successive approximations A/D Converter
(SAR)
ADC: sample and hold + converter

VREF+

Sampling switch
N bits
Vin Rswitch
Converter Dout

CHold

VREF-

ΔT

Conversion command End of conversion


Acquisition & Conversion times
Multiplexed inputs

Analog Mux VREF+


Vin0

Vin1 N bits
Vin
ADC

VinP-1

VREF-
M bits
Convert
#Input Select
Symmetrical ADC output

+127 *VIN/VREF
Example of a 8 bits
symmetrical ADC

VIN

-128 *VIN/VREF
The PIC18 A/D Converter

- The PIC18 has a 10-bit A/D Successive Approximations converter.

- The number of analog inputs varies among different PIC18 devices.

- The A/D converter has the following registers:


• A/D Result High Register (ADRESH)
• A/D Result Low Register (ADRESL)
• A/D Control Register 0 (ADCON0) (source selection)
• A/D Control Register 1 (ADCON1) (reference selection)
• A/D Control Register 2 (ADCON2) (timing selections)

- The contents of these registers vary with the PIC18 members.


- Other registers must be considered:
ANSELx (pin configurations),
ADIF, ADIE, ADIP (for AD interrupt)
ADC schematic
ADCON0
Register
ADCON1 Register
ADCON2 Register

10 bit data result format!

Acquisition time for AD

Base clock for AD


Result format
AD Conversion
Timing example for TACQ = 4 TAD
A/D Acquisition Time Requirements
- The A/D converter has a sample-and-hold circuit for analog input.
- The sample-and-hold circuit keeps the voltage stable when it is converted.
- The sample-and-hold circuit is shown in Figure 17-5.
- The capacitor CHOLD holds the voltage to be converted. It must be
charged to a stable value in order to get the maximum precision.
- The required minimum acquisition time TACQ is computed as follows:
Other Time Requirements

TAD ≥ 1 µs
TACQ ≥ 1.4 µs (but TACQ ≥ 7.45 µs in the example)
TCNV = 11, we need 11 TAD for conversion.
TDIS = 1 TCY cycle
Automatic and manual modes
Procedure for Performing A/D Conversion
The PIC18 D/A Converter
- The PIC18F45K22 has a 5-bit D/A converter.
It is driven by registers VREFCON1
… and VREFCON2
The PIC18 Fixed Voltage Reference
- FVR1 and FVR2 are used in ADC and DAC modules

- These voltages are independent on supply voltage (VDD) and can be


used as an absolute reference system.
Register VREFCON0 drives the FVR module

- FVRST bit is set when the circuitry reaches a stable output.


Proper digitizing of analog signals
When using an ADC to obtain the digitized codes of a
varying analog signal, we want these codes to represent
the original analog signal as good as possible.

There are two factors to take into consideration:

• Resolution

• Sampling Frequency
Sensors and Resolution
Common usage of ADC is to read information from an
analog sensor, to get the value of a physical magnitude
(e.g. temperature, audio, etc.)

Sensors datasheet tell us how output voltage changes


depending on measured magnitude. Usually is a linear
function, defined by:

• A point: e.g. 250mV at 25ºC

• A slope: e.g. 10mV/ºC


Obtaining Resolution
given N bits ADC
Suppose a binary number with N bits is to
represent an analog value ranging from
0 to A Volts AND these are also the Vref margins

There are 2N possible numbers

Resolution = A / (2N-1)
Resolution Example
Temperature range of 0 K to 300 K to be linearly
converted to a voltage signal of 0 to 2.5 V, then
digitized with an 8-bit A/D converter

2.5 / (28-1) = 0.0098 V, or about 10 mV per step


300 K / (28-1) = 1.18 K per step
Resolution Example

Temperature range of 0 K to 300 K to be linearly


converted to a voltage signal of 0 to 2.5 V, then
digitized with a 10-bit A/D converter

2.5 / (210-1) = 0.00244V, or about 2.4 mV per step


300 K / (210-1) = 0.29 K per step

Is the noise present in the system well below 2.4 mV ?


Obtaining N bits ADC
given a resolution
AD converter Example 1:
needed ? Heatsink Range Temp: 0 – 60ºC
Needed resolution: 1º PTC
sensor

Bits of ADC: log2 [(60/1)+1] = Min. 6 bits

Example 2:

Current Sensor for motor: 0 – 20A


Needed resolution: 1mA
Bits of ADC: log2 [(20/0.001)+1] = Min. 15 bits  Difficult
Resolution for 12 bits ADC standard?
Current sensor
212=4096  20/4095  4.5 mA
… what if analog voltage range
DOES NOT match Vref margins?
e.g. this example:

Measure air temperature:


-20ºC to 60ºC with a
0.5ºC resolution
Vref+ =5V and Vref- =0V

Define the required bits


of the ADC.
Sampling (time)
Original
signal

Conversion
order

Obtained
samples

Ts Sampling period Data throughput [bits/s]= 1/Ts * N bits ADC


Nyquist criterion
To avoid aliasing

fsampling > 2· f signal max frequency

Nevertheless, higher sampling frequencies, higher quality


Data Collection – Sampling Rate
The Nyquist Rate
A signal must be sampled at a rate at least twice that of the highest
frequency component that must be reproduced.

Example – Hi-Fi sound (20-20,000 Hz) is generally sampled


at about 44 kHz.

External temperature during flight need only be sampled


every few seconds at most.
Original signal
& Sampling

Original signal
vs Sampled version
Aliasing (1D)

Original signal
Reconstructed signal

Samples

Aliasing example
(fsample  f signal)
Aliased signal
Aliasing (2D)

Aliased signal
Anti-aliasing filter

+VREF
Low pass filter
N bits
Vin 1 Vin’
ADC
f (Hz)
fcutoff

-VREF
Convert

Anti-aliasing filter
f CLK > 2·fcutoff
Signal characteristics: basic concepts
A periodic signal can be described as a sum of sinusoidal and cosinusoidal
signals (Fourier series decomposition).

i.e. A square wave x(t) is decomposed as:


x(t) = 4/π (sin(w0t) + 1/3 sin(3w0t) + 1/5 sin(5w0t) + ...)
Period (T)
Amplitude

f = 1 / T [Hz]
w = 2π f [rad/seg]
Fundamental frequency and harmonics
Amplitude Fundamental frequency (ωo)

Frequency (k·ωo)

Harmonics (k·ωo)

...
Signal’s Frequency Spectrum
Piano spectrum
(note D4)

Voice signal and its associated spectrum


Time and frequency characteristics of audio signals

Audio facts
Range of audible frequencies: 20 Hz to 20KHz (individual depending)
Frequency range of an analog phone call: 350 Hz to 3500 Hz
Violin frequency range: 96 Hz to 10 kHz (approx.)

8 Hz Lowest organ note (note = fundamental freq)


32 Hz Lowest note on a standard 88-key piano
80 Hz Lowest note reproducible by the average female human voice
500 Hz Fundamental frequency of a crying baby
1050 Hz Highest note reproducible by the average female human voice
4186 Hz The highest note on a standard 88-key piano
16K Hz The highest harmonic of a female human voice

120 dB The loudest sound that can be tolerated (I.e. Chainsaw)


60 dB Level of a normal conversation
20 dB A whisper Decibel: dB = 10 log10 (Ps/Pe)
0 dB The faintest audible sound (at 1KHz)
Example Application

Temperature control

ADC

ADC
PWM0 PWM1 PWM2
Example Barometric Measurement
The SenSym ASCX30AN Pressure Sensor

- The range of barometric pressure is between 28 to 32 in-Hg or 948 to


1083.8 mbar.
- The ASCX30AN output voltage would range from 2.06 V to 2.36 V.

Pin 1: External offset adjust


Pin 2: VS
Pin 3: VOUT
ASCX30AN Pin 4: GND
Pin 5: N/C
Pin 6: N/C

1 2 3 4 5 6

Figure 12.18 ASCX30AN pin assignment

You might also like