![Page 1: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/1.jpg)
1
EECS 373Design of Microprocessor-Based Systems
Prabal DuttaUniversity of Michigan
Lecture 11: Sampling, ADCs, and DACsOct 12, 2010
Slides adapted from Jonathan Huihttp://www.cs.berkeley.edu/~jwhui
![Page 2: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/2.jpg)
2
Announcements
• Homework, Labs, and Minute Quizzes
• Office Hours– Tuesday, Oct 12, 2:30 PM – 3:30 PM, in EECS 2334– Thursday, Oct 14, 1:30 PM – 3:00 PM, in CSE 4773– Last ones before the midterm
• Midterm– Thursday, Oct 21, 2010– 10:40 AM – 11:30 AM (50 minutes)– In-class
• Labs
![Page 3: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/3.jpg)
3
Outline
• Minute quiz
• Announcements
• Sampling
• ADC
• DAC
![Page 4: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/4.jpg)
4
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
![Page 5: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/5.jpg)
5
Transducers convert one form of energy into another
• Transducers– Allow us to convert physical phenomena to a
voltage potential in a well-defined way.
![Page 6: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/6.jpg)
6
Convert light to voltage with a CdS photocell
Vsignal = (+5V) RR/(R + RR)
• Choose R=RR at median of intended range
• Cadmium Sulfide (CdS)• Cheap, low current
• tRC = Cl*(R+RR)– Typically R~50-200k– C~20pF – So, tRC~20-80uS– fRC ~ 10-50kHz
Source: Forrest Brewer
![Page 7: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/7.jpg)
Many other common sensors (some digital)
• Force– strain gauges - foil,
conductive ink– conductive rubber– rheostatic fluids
• Piezorestive (needs bridge)
– piezoelectric films– capacitive force
• Charge source
• Sound– Microphones
• Both current and charge versions
– Sonar• Usually Piezoelectric
• Position– microswitches– shaft encoders– gyros
• Acceleration– MEMS– Pendulum
• Monitoring– Battery-level
• voltage– Motor current
• Stall/velocity– Temperature
• Voltage/Current Source
• Field– Antenna– Magnetic
• Hall effect• Flux Gate
• Location– Permittivity– Dielectric
Source: Forrest Brewer
![Page 8: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/8.jpg)
8
Going from analog to digital
• What we want
• How we have to get there
SoftwareSensor ADC
PhysicalPhenomena
Voltage orCurrent
ADC Counts Engineering Units
PhysicalPhenomena
Engineering Units
![Page 9: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/9.jpg)
9
Representing an analog signal digitally
• How do we represent an analog signal?– As a time series of discrete values
On MCU: read the ADC data register periodically
)(xf sampled
)(xf
t
ST
V Counts
![Page 10: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/10.jpg)
10
Choosing the horizontal range
• What do the sample values represent?– Some fraction within the range of values
What range to use?
rV
tRange Too Small
rV
tRange Too Big
rV
rV
tIdeal Range
rV
rV
![Page 11: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/11.jpg)
11
Choosing the horizontal 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 information
• Quantization Error– How far off discrete value is from
actual– ½ LSB Range / 8192
Larger range larger error
![Page 12: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/12.jpg)
12
Converting between voltages, ADC counts, and engineering units
• Converting: ADC counts Voltage
• Converting: Voltage Engineering Units
ADCN
4095
4095
RRADCin
RR
RinADC
VVNV
VV
VVN
t
rV
rV
inV
00355.0
986.0TEMP
986.0)TEMP(00355.0
TEMPC
CTEMP
V
V
![Page 13: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/13.jpg)
13
A note about sampling and arithmetic
• 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 TEMP
C
V
4095TEMP
RRADC
VVNV
![Page 14: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/14.jpg)
14
Choosing the sample rate
• What sample rate do we need?– Too little: we can’t reconstruct the signal we care
about– Too much: waste computation, energy, resources
• Example: 2-bytes per sample, 4 kHz 8 kB / second
• What about sampling jitter? Remember Lab 1?
)(xf sampled
)(xf
t
![Page 15: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/15.jpg)
15
Shannon-Nyquist sampling theorem
• If a continuous-time signal contains no frequencies higher than , it can be completely determined by discrete samples taken at a rate:
• Example:– Humans can process audio signals 20 Hz – 20 KHz– Audio CDs: sampled at 44.1 KHz
)(xf
maxf
maxsamples 2 ff
![Page 16: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/16.jpg)
16
Use anti-aliasing filters on ADC inputs toensure that Shannon-Nyquist is satisfied
• 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)
![Page 17: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/17.jpg)
17
Designing the anti-aliasing filter
• Note is in radians = 2f
• Exercise: Find an R+C pair so that the half-power point occurs at 30 Hz
![Page 18: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/18.jpg)
18
Can use dithering to deal with quantization
• Dithering– Quantization errors can
result in large-scale patterns that don’t accurately describe the analog signal
– Introduce random (white) noise to randomize the quantization error.
Direct Samples Dithered Samples
![Page 19: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/19.jpg)
19
Outline
• Minute quiz
• Announcements
• Sampling
• ADC
• DAC
![Page 20: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/20.jpg)
20
The basics of Analog-to-Digital Conversion
• So, how do you convert analog signals to a discrete 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 conversion3. When interrupt occurs, read sample from data
register4. Wait for a sample period5. Repeat step 1
![Page 21: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/21.jpg)
21
Architecture of the TI MSP430 ADC subsystem
![Page 22: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/22.jpg)
22
ADC Features
Texas Instruments MSP430
Atmel
ATmega 1281
Resolution 12 bits 10 bits
Sample Rate 200 ksps 76.9 ksps
Internally Generated Reference 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
![Page 23: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/23.jpg)
23
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
RVinV
![Page 24: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/24.jpg)
24
SAR ADC
• SAR = Successive-Approximation-Register– Binary search to find closest digital value– Conversion time log(bits)
![Page 25: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/25.jpg)
25
SAR ADC
• SAR = Successive-Approximation-Register– Binary search to find closest digital value
1 Sample Multiple cycles
![Page 26: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/26.jpg)
26
SAR ADC
1 Sample Multiple cycles
![Page 27: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/27.jpg)
27
Sample and Conversion Timing
• Timing driven by:– TimerA– TimerB– Manually using ADC12SC bit
• Signal selection using SHSx• Polarity selection using ISSH
![Page 28: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/28.jpg)
28
Voltage Reference
• Voltage Reference Generator– 1.5V or 2.5V– REFON bit in ADCCTL0– Consumes energy when on– 17ms settling time
• External references allow arbitrary reference voltage
• Exercise: If you want to sample Vcc, what Vref should you use?
Internal External
Vref+ 1.5V, 2.5V, Vcc VeRef+
Vref- AVss VeRef-
![Page 29: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/29.jpg)
29
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)kΩ2( Ssample Rt
![Page 30: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/30.jpg)
30
Software Configuration
• How it looks in code:
ADC12CTL0 = SHT0_2 | REF1_5V |
REFON | ADC12ON;
ADC12CTL1 = SHP;
![Page 31: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/31.jpg)
31
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 or ADC.
– P6SEL register
![Page 32: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/32.jpg)
32
Conversion Memory
• 16 sample buffer
• Each buffer configures sample parameters
– Voltage reference– Input channel– End-of-sequence
• CSTARTADDx indicates where to write next sample
![Page 33: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/33.jpg)
33
Conversion Modes
• Single-Channel Single-Conversion– Single channel sampled and
converted once– Must set ENC (Enable Conversion)
bit each 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
and converted repeatedly– Sequence re-starts when reaching
ADC12MCTLx with EOS bit
![Page 34: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/34.jpg)
34
Software Configuration
• How it looks in code:
• Configuration
ADC12CTL0 = SHT0_2 | REF1_5V |
REFON | ADC12ON;
ADC12CTL1 = SHP;
ADC12MCTL0 = EOS | SREF_1 |
INCH_11;
• Reading ADC data
m_reading = ADC12MEM0;
![Page 35: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/35.jpg)
35
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();
}
![Page 36: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/36.jpg)
36
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();
}
![Page 37: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/37.jpg)
37
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();
}
![Page 38: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/38.jpg)
38
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();
}
![Page 39: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/39.jpg)
39
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();
}
![Page 40: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/40.jpg)
40
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();
}
![Page 41: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/41.jpg)
41
Outline
• Minute quiz
• Announcements
• Sampling
• ADC
• DAC
![Page 42: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/42.jpg)
42
A decoder-based DAC architecture in linear and folded forms
![Page 43: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/43.jpg)
43
A binary-scaled DAC architecture in linear and folded forms
• Much more efficient• Monotonicity not guaranteed• May experiences glitches
![Page 44: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/44.jpg)
44
DAC output signal conditioning
• Often use a low-pass filter• May need a unity gain op amp for drive strength
![Page 45: EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan](https://reader036.vdocuments.site/reader036/viewer/2022062516/56812bb0550346895d8fea49/html5/thumbnails/45.jpg)
45
Questions?
Comments?
Discussion?