Lecture 4 - Analog Interfacing

advertisement
EGC433
Embedded Systems
Lecture 4
Analog Interfacing: DAC and ADC
References
• Chapter 7 from Mazidi’s (Blue) STM32 ARM
Book
• https://training.ti.com/ti-rslk-module-15-lecturevideo-part-i-data-acquisition-systemstheory?context=1135347-1139306-1134813
• https://training.ti.com/ti-rslk-module-15-lecturevideo-part-ii-data-acquisition-systemsperformance-measurements?context=11353471139306-1134814
The Analog World
• Most everything in the physical world is an analog
signal
– Sound, light, temperature, pressure
• Need to convert into electrical signals
– Transducers: converts one type of energy to another
• Electro-mechanical, Photonic, Electrical, …
– Examples
• Microphone/speaker
• Thermocouples
• Accelerometers
Digitizing the World
• Analog versus Digital
• Why Digital?
• Digitization
– Combined operations of sampling and quantization,
aka Analog-to-Digital Conversion
• Sampling
– Recording values (typically amplitudes) of a signal at
specific time intervals
• Quantization
– Changing sampled values to nearest discrete levels
Examples of Digitization
Sampling Rate
• Dividing the time axis
• Sampling rate = sampling frequency = number
of samples (measurements) per second
• Greater than “two samples” per cycle needed to
represent each frequency.
• Otherwise, have “aliasing.”
• Aliasing means that we interpret the frequency
as a much lower frequency
Sampling an Analog Signal
Nyquist Sampling Theorem
• A bandlimited analog signal that has been sampled can be perfectly
reconstructed from an infinite sequence of samples if the sampling rate fs
exceeds 2fmax samples per second, where fmax is the highest frequency in
the original signal.
– i.e., fs > 2 x fmax (Nyquist rate)
– If the analog signal does contain frequency components larger than
(1/2)fs, then there will be an aliasing error.
– Aliasing is when the digital signal appears to have a different
frequency than the original analog signal.
• Valvano (UT Austin) Postulate: If fmax is the largest frequency
component of the analog signal, then you must sample more than ten
times fmax in order for the reconstructed digital samples to look like the
original signal when plotted on a voltage versus time graph. If you
sample slightly greater than two times fmax you will get the correct frequency,
but the reconstructed signal’s amplitude will look strange.
Sampling (fs = 10 x fmax)
• 200Hz signal sampled at 2000Hz
4000
Points are digital data, solid curve is the truth. What is the frequency?
Signal
3000
2000
1000
0
0.000
0.001
0.002
0.003
0.004
Time (sec)
0.005
0.006
0.007
0.008
Sampling (fs = 2 x fmax)
• 1000Hz signal sampled at 2000Hz
4000
Points are digital data, solid curve is the truth. What is the frequency?
Signal
3000
2000
1000
0
0.000
0.001
0.002
0.003
0.004
Time (sec)
0.005
0.006
0.007
0.008
Sampling (fs = 0.909 x fmax)
• 2200Hz signal sampled at 2000Hz
4000
Points are digital data, solid curve is the truth. What is the frequency?
Signal
3000
2000
1000
This is aliasing
0
0.000
0.001
0.002
0.003
0.004
Time (sec)
0.005
0.006
0.007
0.008
Under-sampled Image
Anti-aliasing Low-pass Filter
Removes frequency components above one-half the sampling frequency
(Prevents corruption of lower frequencies by first removing high frequencies)
Quantization
• The process of changing sample values to
discrete levels.
• Rounding is the most common form.
A Sampled Signal
Signal Has Been Quantized
(2-bit Quantization Shown at Blue Dots)
Quantized Samples
Stored Values Shown In Orange Using 4 Levels (2-bits)
Quantizing
(a) 3-bits, (b) 4 bits, and (c) 16 bits
Quantization Errors (Noise)
Introduction to Analog I/O
• Physical phenomena are often analog in value -- they
can take on a continuous range of values rather than
discrete values
– Examples include temperature, speed, position, pressure,
voltage, current, resistance,…
• For a microprocessor to operate on continuous physical
values, conversion between analog and digital values is
needed
• Building blocks to perform the conversions are:
– Digital to Analog Converters (DACs)
– Analog to Digital Converters (ADCs)
Transducers
• Convert energy from one form to another
– Sensors
•
•
•
•
•
Potentiometer (position)
Strain gauge, piezoelectric device (force)
Thermistor, thermocouple (temperature)
Photoconductive cell, phototransistor (light)
Microphone (sound)
– Actuators
• Solenoids, relays, speakers
• Darlington transistors, SCRs, thyristors
Sensor Interfacing and Signal Conditioning
• Temperature sensors - temperature is converted to
electrical signals using a transducer called a thermistor. A
thermistor responds to temperature change by changing
resistance, but response is not linear, as shown below.
• Complexity associated with writing software for such
nonlinear devices has led many manufacturers to market a
linear sensor.
Sensor Interfacing and Signal Conditioning
• Thermocouple - an electrical device that responds to a
difference in temperature by producing an electric current.
Thermocouples are used as measuring instruments and as
control devices.
• The thermocouple is based on the Seebeck effect. In its
simplest form, the thermocouple consists of two wires of
dissimilar metals or alloys joined at their ends, with a
potentiometer (or a voltmeter) connected in one side of the
circuit. Still non-linear.
Sensor Interfacing and Signal Conditioning
• LM34 temperature sensors - are precision
integrated-circuit temperature sensors whose
output voltage is linearly proportional to the
Fahrenheit temperature.
– LM34 requires no external calibration as it is internally
calibrated to output 10 mV for each degree Fahrenheit
Sensor Interfacing and Signal Conditioning
• LM35 temperature sensors - are precision
integrated-circuit temperature sensors whose
output voltage is linearly proportional to the
Celsius (centigrade) temperature.
– LM35 requires no external calibration as it is internally
calibrated to output 10 mV for each degree centigrade
LM34/35 Connection to ARM
and Its Pin Configuration
LM34 and LM35
Sensor Interfacing and Signal Conditioning
• Signal conditioning are typically
current-to-voltage conversion or a
signal amplification.
• Signal conditioning & interfacing
the LM35
– We need to convert & scale signals to
voltage in order to send input to an
ADC.
Signal conditioning
• Most transducers output low-level signals
– Usually less than 1V, may be millivolts or microvolts
• Signal may also be noisy
• Need to apply signal conditioning before A/D conversion
– Amplification
– Filtering
– Linearization
Operational Amplifiers
• Useful in the design of DACs and ADCs because
of their performance characteristics
– Open loop gain of several hundred thousand
– Input current approximately zero
– Output impedance approximately zero
Typical Op-Amp Circuits
Digital to Analog Conversion
• A DAC takes an n-bit digital input and outputs a
corresponding analog voltage
• DAC systems normally consist of three components:
– An accurate reference voltage
– The DAC itself
– Op amp for output buffering
• Ideal DAC would convert n-bit code Bn-1 ... B1 B0 to
output voltage as shown below:
– Vout = Span x ( Bn-1 2-1 + Bn-2 2-2 + ... B0 2-n ) + Offset
– Vout will be a fractional value of the "full scale" voltage
(span-offset)
• Maximum is the digital value of 111111...111 (all 1s)
Digital to Analog Conversion
• Definitions
– Offset: minimum analog voltage
– Span: (Maximum analog value) – (minimum analog value)
• Common spans: 0-5 V, 0-10 V, 4-20 mA, +/- 5 V
– Step size (aka Resolution): span / 2n (where n is the number
of bits in code), also the weight of the LSB
– Weight: analog change corresponding to a change in a bit
position of the digital number (varies by bit position)
– Example: Analog signal in range +5 to -5 volts, 8-bit digital
number:
•
•
•
•
Span = 10 volts
Offset = -5 volts
Step size = 10 / 256 = 39.1 mV
Weights: 5, 2.5, 1.25, 0.625, ... 0.0391
External (Parallel) DAC
DAC using PWM
Low Pass Filter
(Passive Integrator)
Improved PWM-based DAC
Analog to Digital Conversion
• The function of an ADC is to quantize the analog
voltage and then output the corresponding digital
code value
• A full-scale analog value will be divided into 2N
quantization levels or steps for an N-bit digital
coding scheme
Decisions in Analog to Digital Conversion
• In sampling (digitizing) waveforms, we address both
the horizontal axis (time) and the vertical axis
(amplitude, voltage, pressure, etc.)
• Horizontal Axis: How many samples
(measurements) do we need to make per second?
– If not enough, signal will be distorted (“aliasing”)
– If too many, we will use more uC resources (memory) than
needed
• Vertical Axis: How many levels do we need to
represent the signal?
– If not enough, signal will be distorted (“quantization error”)
– If too many, we will use more uC resources (memory) than
needed
A/D Converters
• An N-bit A/D converter can represent 2N levels
• The N bits represent place values from 1 (20) to 2(N-1)
• The numbers represented range from 0 to 2N-1
Example: 8-bit converter
– can represent 28 or 256 levels or “steps”.
– place values range from the ones place (20) to the 128’s
place (27).
– The lowest number is 0; the highest is 255, which is written
11111111.
Vref Relation to Vin Range for
an 8-bit ADC
Vref (V)
5.00
4.00
3.00
2.56
2.00
1.28
1.00
Vin in Range (V)
Step Size (mV)
0 to 5
5 / 256 = 19.53
0 to 4
4 / 256 = 15.62
0 to 3
3 / 256 = 11.71
0 to 2.56
2.56 / 256 = 10
0 to 2
2 / 256 = 7.81
0 to 1.28
1.28 / 256 = 5
0 to 1
1 / 256 = 3.90
Note: In an 8-bit ADC, step size is Vref/256
Vref Relation to Vin Range for a
10-bit ADC
Vref (V)
5.00
4.96
3.00
2.56
2.00
1.28
1.024
VinRange (V)
Step Size (mV)
0 to 5
5 / 1024 = 4.88
0 to 4.096
4.096 / 1024 = 4
0 to 3
3 / 1024 = 2.93
0 to 2.56
2.56 / 1024 = 2.5
0 to 2
2 / 1024 = 2
0 to 1.28
1.28 / 1024 = 1.25
0 to 1.024
1.024 / 1024 = 1
Note: In a 10-bit ADC, step size is Vref/1024
Resolution versus Step Size for
ADC (Vref = 5V)
n-bit
Number of steps
Step size
8
256
5V /256 = 19.53 mV
10
1024
5V /1024 = 4.88 mV
12
4096
5V /4096 = 1.2 mV
16
65,536
5V /65,536 = 0.076 mV
Note: Vref = 5V
Analog-to-Digital Circuit
Using Counting Conversion
•
•
•
•
•
Conversion from analog to digital form
inherently involves comparator action where
the value of the analog voltage at some point
in time is compared with some standard.
A common way to do that is to apply the
analog voltage to one terminal of a
comparator and trigger a binary counter
which drives a DAC.
The output of the DAC is applied to the
other terminal of the comparator.
Since the output of the DAC is increasing
with the counter, it will trigger the
comparator at some point when its voltage
exceeds the analog input.
The transition of the comparator stops the
binary counter, which at that point holds the
digital value corresponding to the analog
voltage.
ADC Using Counting Conversion
Another Look
Successive Approximation ADC
Typically Much Faster Than Counting Conversion
• VIN is approximated as a static value in a sample and hold (S/H) circuit
• The successive approximation register (SAR) is a counter that increments
each clock as long as it is enabled by the comparator
• The output of the SAR is fed to a DAC that generates a voltage for
comparison with VIN
• When the output of the DAC = VIN the value of SAR is the digital
representation of VIN
Successive Approximation ADC
Operation
• SA/ADC with a precision of n is clocked n times
• At each clocking, a bit is determined, starting at
the most significant bit
voltage
5V
0V
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001
0000
3.75V
3.4375V
3.125V
2.5V
step 1
step 2
step 3
step 4
Vin = 3.5V
Download