lecture adcs
TRANSCRIPT
-
8/11/2019 Lecture Adcs
1/35
2008 EECS194-5 1
Deal ing w ith Analog SignalsA Micro contro l ler View
Jonathan HuiUniversity of California, Berkeley
-
8/11/2019 Lecture Adcs
2/35
2008 EECS194-5 2
An Analog World
Everything in the physical world is an analogsignal
Sound, light, temperature, gravitational force
Need to convert into electrical signals Transducers: converts one type of energy to another
Electro-mechanical, Photonic, Electrical,
Examples
Microphone/speaker
Thermocouples
Accelerometers
-
8/11/2019 Lecture Adcs
3/35
2008 EECS194-5 3
An Analog World
Transducers Allow us to convert physical phenomena to a voltage
potential in a well-defined way.
-
8/11/2019 Lecture Adcs
4/35
2008 EECS194-5 4
Going From Analog to Digital
What we want
How we have to get there
SoftwareSensor ADC
Physical
Phenomena
Voltage ADC Counts Engineering
Units
Physical
Phenomena
Engineering
Units
-
8/11/2019 Lecture Adcs
5/35
2008 EECS194-5 5
Sampling Basics
How do we represent an analog signal? As a time series of discrete values
On the MCU: read th e ADC data register per iodical ly
)(xfsampled
)(xf
t
ST
V Counts
-
8/11/2019 Lecture Adcs
6/35
2008 EECS194-5 6
Sampling Basics
What do the sample values represent? Some fraction within the range of values
What range to use?
rV
t
Range Too Small
rV
t
Range Too Big
rV
rV
t
Ideal Range
rV
rV
-
8/11/2019 Lecture Adcs
7/352008 EECS194-5 7
Sampling Basics
Resolution Number of discrete values that
represent a range of analog values
MSP430: 12-bit ADC
4096 values
Range / 4096 = StepLarger range less inform at ion
Quantization Error
How far off discrete value is from
actual LSBRange / 8192
Larger range larger error
-
8/11/2019 Lecture Adcs
8/35
-
8/11/2019 Lecture Adcs
9/352008 EECS194-5 9
Sampling Basics
Converting values in 16-bit MCUs
vtemp = adccount/4095 * 1.5;
tempc = (vtemp-0.986)/0.00355;
tempc = 0
Fixed point operations
Need to worry about underflow and overflow
Floating point operations
They can be costly on the node
00355.0
986.0TEMP TEMPC
V
4095TEMP
RR
ADC
VVNV
-
8/11/2019 Lecture Adcs
10/352008 EECS194-5 10
Sampling Basics
What sample rate do we need? Too little: we cant reconstruct the signal we care about
Too much: waste computation, energy, resources
Example:
2-bytes per sample, 4 kHz8 kB / second
But the mote only has 10 kB of RAM
)(xfsampled
)(xf
t
-
8/11/2019 Lecture Adcs
11/352008 EECS194-5 11
Shannon-Nyquist Sampling Theorem
If a cont inuo us- t ime signal con tains nofrequencies high er than , i t can be completely
determ ined by disc rete samp les taken at a rate:
Example:
Humans can process audio signals 20 Hz20 KHz
Audio CDs: sampled at 44.1 KHz
)(xfmax
f
maxsamples 2ff
-
8/11/2019 Lecture Adcs
12/352008 EECS194-5 12
Sampling Basics
Aliasing Different frequencies are indistinguishable when they
are sampled.
Condition the input signal using a low-pass filter
Removes high-frequency components
(a.k.a. anti-aliasing filter)
-
8/11/2019 Lecture Adcs
13/352008 EECS194-5 13
Sampling Basics
Dithering Quantization errors can result
in large-scale patterns that
dont accurately describe the
analog signal
Introduce random (white)
noise to randomize the
quantization error.
Direct Samples Dithered Samples
-
8/11/2019 Lecture Adcs
14/352008 EECS194-5 14
Analog-to-Digital Basics
So, how do you convert analog signals to adiscrete values?
A software view:1. Set some control registers :
Specify where the input is coming from (which pin)
Specify the range (min and max)
Specify characteristics of the input signal (settling time)
2. Enable interrupt and set a bit to start a conversion
3. When interrupt occurs, read sample from data register
4. Wait for a sample period
5. Repeat step 1
-
8/11/2019 Lecture Adcs
15/352008 EECS194-5 15
Block Diagram (MSP430)
-
8/11/2019 Lecture Adcs
16/352008 EECS194-5 16
ADC Features
Texas InstrumentsMSP430
AtmelATmega 1281
Resolution 12 bits 10 bits
Sample Rate 200 ksps 76.9 ksps
Internally GeneratedReference Voltage
1.5V, 2.5V, Vcc 1.1V, 2.56V
Single-Ended Inputs 12 16
Differential Inputs 0 14 (4 with gain amp)
Left Justified Option No Yes
Conversion Modes Single, Sequence,
Repeated Single,
Repeated Sequence
Single, Free Running
Data Buffer 16 samples 1 sample
-
8/11/2019 Lecture Adcs
17/352008 EECS194-5 17
ADC Core
Input Analog signal
Output
12-bit digital value of input
relative to voltage references
Linear conversion
4095
4095
RRADCin
RR
RinADC
VVNV
VV
VVN
RV
RV
inV
-
8/11/2019 Lecture Adcs
18/352008 EECS194-5 18
SAR ADC
SAR = Successive-Approximation-Register Binary search to find closest digital value
-
8/11/2019 Lecture Adcs
19/352008 EECS194-5 19
SAR ADC
SAR = Successive-Approximation-Register Binary search to find closest digital value
1 SampleMultiple cycles
-
8/11/2019 Lecture Adcs
20/352008 EECS194-5 20
SAR ADC
1 SampleMultiple cycles
-
8/11/2019 Lecture Adcs
21/352008 EECS194-5 21
Sample and Conversion Timing
Timing driven by: TimerA
TimerB
Manually using ADC12SC bit
Signal selection using SHSx
Polarity selection using ISSH
-
8/11/2019 Lecture Adcs
22/35
-
8/11/2019 Lecture Adcs
23/35
2008 EECS194-5 23
Sample Timing Considerations
Port 6 inputs default to high impedance When sample starts, input is enabled
But capacitance causes a low-pass filter effect
Must wait for the input signal to converge
ns800pF40011.9)k2( Ssample Rt
-
8/11/2019 Lecture Adcs
24/35
2008 EECS194-5 24
Software Configuration
How it looks in code:
ADC12CTL0 = SHT0_2 | REF1_5V |
REFON | ADC12ON;
ADC12CTL1 = SHP;
-
8/11/2019 Lecture Adcs
25/35
2008 EECS194-5 25
Inputs and Multiplexer
12 possible inputs 8 external pins (Port 6)
1 Vref+ (external)
1 Vref- (external)
1 Thermistor
1 Voltage supply
External pins may function as
Digital I/O orADC.
P6SEL register
Is th is a mult ip lexor as you saw
in CS150?
-
8/11/2019 Lecture Adcs
26/35
2008 EECS194-5 26
Conversion Memory
16 sample buffer
Each buffer configures sample
parameters
Voltage reference
Input channel
End-of-sequence
CSTARTADDx indicates where to
write next sample
-
8/11/2019 Lecture Adcs
27/35
2008 EECS194-5 27
Conversion Modes
Single-Channel Single-Conversion
Single channel sampled and convertedonce
Must set ENC (Enable Conversion) biteach time
Sequence-of-Channels Sequence of channels sampled and
converted once
Stops when reaching ADC12MCTLx
with EOS bit
Repeat-Single-Channel Single channel sampled and converted
continuously
New sample occurs with each trigger(ADC12SC, TimerA, TimerB)
Repeat-Sequence-of-Channels
Sequence of channels sampled andconverted repeatedly
Sequence re-starts when reachingADC12MCTLx with EOS bit
-
8/11/2019 Lecture Adcs
28/35
-
8/11/2019 Lecture Adcs
29/35
2008 EECS194-5 29
A Software Perspective
command void Read.read() {
ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON;
ADC12CTL1 = SHP;ADC12MCTL0 = EOS | SREF_1 | INCH_11;
call Timer.startOneShot( 17 );
}
event void Timer.fired() {
ADC12CTL0 |= ENC;
ADC12IE = 1;
ADC12CTL0 |= ADC12SC;
}
task void signalReadDone() {
signal Read.readDone( SUCCESS, m_reading );
}
async event void HplSignalAdc12.fired() {
ADC12CTL0 &= ~ENC;
ADC12CTL0 = 0;
ADC12IE = 0;
ADC12IFG = 0;
m_reading = ADC12MEM0;
post signalReadDone();
}
-
8/11/2019 Lecture Adcs
30/35
2008 EECS194-5 30
A Software Perspective
command void Read.read() {
ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON;
ADC12CTL1 = SHP;ADC12MCTL0 = EOS | SREF_1 | INCH_11;
call Timer.startOneShot( 17 );
}
event void Timer.fired() {
ADC12CTL0 |= ENC;
ADC12IE = 1;
ADC12CTL0 |= ADC12SC;
}
task void signalReadDone() {
signal Read.readDone( SUCCESS, m_reading );
}
async event void HplSignalAdc12.fired() {
ADC12CTL0 &= ~ENC;
ADC12CTL0 = 0;
ADC12IE = 0;
ADC12IFG = 0;
m_reading = ADC12MEM0;
post signalReadDone();
}
-
8/11/2019 Lecture Adcs
31/35
2008 EECS194-5 31
A Software Perspective
command void Read.read() {
ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON;
ADC12CTL1 = SHP;ADC12MCTL0 = EOS | SREF_1 | INCH_11;
call Timer.startOneShot( 17 );
}
event void Timer.fired() {
ADC12CTL0 |= ENC;
ADC12IE = 1;
ADC12CTL0 |= ADC12SC;
}
task void signalReadDone() {
signal Read.readDone( SUCCESS, m_reading );
}
async event void HplSignalAdc12.fired() {
ADC12CTL0 &= ~ENC;
ADC12CTL0 = 0;
ADC12IE = 0;
ADC12IFG = 0;
m_reading = ADC12MEM0;
post signalReadDone();
}
-
8/11/2019 Lecture Adcs
32/35
2008 EECS194-5 32
A Software Perspective
command void Read.read() {
ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON;
ADC12CTL1 = SHP;ADC12MCTL0 = EOS | SREF_1 | INCH_11;
call Timer.startOneShot( 17 );
}
event void Timer.fired() {
ADC12CTL0 |= ENC;
ADC12IE = 1;
ADC12CTL0 |= ADC12SC;
}
task void signalReadDone() {
signal Read.readDone( SUCCESS, m_reading );
}
async event void HplSignalAdc12.fired() {
ADC12CTL0 &= ~ENC;
ADC12CTL0 = 0;
ADC12IE = 0;
ADC12IFG = 0;
m_reading = ADC12MEM0;
post signalReadDone();
}
-
8/11/2019 Lecture Adcs
33/35
2008 EECS194-5 33
A Software Perspective
command void Read.read() {
ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON;
ADC12CTL1 = SHP;ADC12MCTL0 = EOS | SREF_1 | INCH_11;
call Timer.startOneShot( 17 );
}
event void Timer.fired() {
ADC12CTL0 |= ENC;
ADC12IE = 1;
ADC12CTL0 |= ADC12SC;
}
task void signalReadDone() {
signal Read.readDone( SUCCESS, m_reading );
}
async event void HplSignalAdc12.fired() {
ADC12CTL0 &= ~ENC;
ADC12CTL0 = 0;
ADC12IE = 0;
ADC12IFG = 0;
m_reading = ADC12MEM0;
post signalReadDone();
}
-
8/11/2019 Lecture Adcs
34/35
2008 EECS194-5 34
MCU
Kernel Driver
Interrupts and Tasks
ADC
Application
command void Read.read() {
ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON;
ADC12CTL1 = SHP;ADC12MCTL0 = EOS | SREF_1 | INCH_11;
call Timer.startOneShot( 17 );
}
event void Timer.fired() {
ADC12CTL0 |= ENC;
ADC12IE = 1;
ADC12CTL0 |= ADC12SC;
}
task void signalReadDone() {
signal Read.readDone( SUCCESS, m_reading );
}
async event void HplSignalAdc12.fired() {
ADC12CTL0 &= ~ENC;
ADC12CTL0 = 0;
ADC12IE = 0;
ADC12IFG = 0;
m_reading = ADC12MEM0;
post signalReadDone();
}
-
8/11/2019 Lecture Adcs
35/35