Lecture8 Analog
Lecture8 Analog
Lecture 8
Interfacing with
The Analog World
Wireless Embedded Systems
Aaron Schulman
Outline
• Sampling
• ADC
2
We live in an analog world
• 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
3
Going from analog to digital
• What we want…
Physical Engineering
Phenomena Units
• How we get there?
4
Representing an analog signal digitally
• How do we represent an analog signal (e.g. continuous voltage)?
– As a time series of discrete values
On MCU: read ADC data register (counts) periodically (Ts)
f (x) Counts
Voltage (discrete)
(continuous)
f sampled (x)
t
5
TS
Choosing the range
• Fixed # of bits (e.g. 8-bit ADC)
• Span a particular input voltage range
• What do the sample values represent?
– Some fraction within the range of values
What range to use?
Vr Vr
Vr Vr
t t
Range Too Small Range Too Big
Vr
Vr
t
Ideal Range
6
Choosing the granularity
• Resolution
– Number of discrete values that
represent a range of analog values
– MSP430: 12-bit ADC
• 4096 values
• Range / 4096 = Step
Larger range less info / bit
• Quantization Error
– How far off discrete value is from actual
– ½ LSB Range / 8192
Larger range larger error
7
Choosing the sample rate
f (x)
f sampled (x)
8
t
Shannon-Nyquist sampling theorem
f samples 2 f max
• Example:
– Humans can process audio signals 20 Hz – 20 KHz
– Audio CDs: sampled at 44.1 KHz
9
Converting between voltages,
ADC counts, and engineering units
• Converting: ADC counts Voltage
Vr
Vin
N ADC
Vr
t
10
A note about sampling and arithmetic*
• Converting values in fixed-point MCUs
VTEMP 0.986
TEMPC
0.00355
11
Try it out for yourself…
$ cat arithmetic.c
#include <stdio.h>
int main() {
$ gcc arithmetic.c
$ ./a.out
vtemp: 0.000000
tempc: -277.746490
12
Use anti-aliasing filters on ADC inputs to
ensure that Shannon-Nyquist is satisfied
• Aliasing
– Different frequencies are indistinguishable when they are sampled.
13
Do I really need to condition my input
signal?
• Short answer: Yes.
15
Oversampling a 1-bit ADC w/ noise &
dithering (cont)
Voltage Count
uniformly “upper edge”
distributed of the box
random noise
±250 mV
1
Vthresh = 500 mV
N1 = 11
500 mV
375 mV
N0 = 32
500 mV
Vrand =
0 mV
Note:
N1 is the # of ADC counts that = 1 over the sampling window
N0 is the # of ADC counts that = 0 over the sampling window 16
Oversampling a 1-bit ADC w/ noise &
dithering (cont)
• How to get more than 1-bit out of a 1-bit ADC?
• Add some noise to the input
• Do some math with the output
• Example
– 1-bit ADC with 500 mV threshold
– Vin = 375 mV ADC count = 0
– Add ±250 mV uniformly distributed random noise
to Vin
– Now, roughly
• 25% of samples (N1) ≥ 500 mV ADC count = 1
• 75% of samples (N0) < 500 mV ADC count = 0 17
Can use dithering to deal with quantization
• Dithering
– Quantization errors can result in
large-scale patterns that don’t
accurately describe the analog
signal
– Oversample and dither
– Introduce random (white) noise
to randomize the quantization
error.
18
Direct Samples Dithered Samples
Selection of ADC