EE 319K�Introduction to Embedded Systems
Lecture 11: Sampling, �Analog-to-Digital Conversion
http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C13_Interactives.htm
http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C14_Interactives.htm
Today and cover lab 8, lec11
Exam2 Friday 4/8: hard cutoff at 8:30pm
Please attempt Quiz 9 and Quiz 10
10-1
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Agenda
Push {R11}
SUB SP,SP,#32
MOV R11, SP
;*********
;*********(
ADD SP,SP#32
POP {R11}
X86
ENTER #32
LEAVE (moves BP into, POP BP
10-2
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Analog to Digital Converter (ADC)
Four limitations of digital sampling
Voltage resolution = 3.3V/4095 =0.8 mV
Frequency range = 0 to ½ fs
Frequency resolution = fs / N
10-3
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Nyquist Theorem
http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C13_Interactives.htm
http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C14_Interactives.htm
10-4
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sampling (option 1)
http://www.ece.utexas.edu/~valvano/Volume1/Nyquist.xls
Look at
200 Hz
2200 Hz
10-5
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sampling (option 1)
http://www.ece.utexas.edu/~valvano/Volume1/Nyquist.xls
10-6
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sampling (option 1)
This is aliasing
http://www.ece.utexas.edu/~valvano/Volume1/Nyquist.xls
10-7
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sampling (option 2)
http://www.ece.utexas.edu/~valvano/EE345L/Labs/Fall2011/FFT16.xls
10-8
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sampling (option 2)
http://www.ece.utexas.edu/~valvano/EE345L/Labs/Fall2011/FFT16.xls
10-9
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sampling (option 2)
This is aliasing
http://www.ece.utexas.edu/~valvano/EE345L/Labs/Fall2011/FFT16.xls
10-10
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Analog to Digital Converter (ADC)
end of conversion
http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C14_Interactives.htm
10-11
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Play the 6-bit SAR game
http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C14_Interactives.htm
10-12
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sample-And-Hold Circuit
S/H
10-13
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
= 3.3V/4095 alternatives < 1mV
or = 3.3V/4096 alternatives < 1mV
Use either
10-14
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
PD2=Ain5 used for Lab 8, 9, 10
10-15
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
Ain5PD2
Software initiated
Bit 3 is done flag
Use sequencer 3
PD2=Ain5 used for Lab 8, 9, 10
10-16
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
Twelve different pins can be used to sample analog inputs.
PD3=Ain4 used for TExaS oscilloscope
PD2=Ain5 used for Lab 8, 9, 10
PE4=Ain9 used in book and ADCSWTrigger_4C123
10-17
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
10-18
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
Speed bits in ADC0_PC_R
EM3, EM2, EM1, and EM0 bits in ADC_EMUX_R
ADC0_SSCTL3_R = 0x06;
10-19
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
10-20
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
Channel 9 is PE4
void ADC0_InitSWTriggerSeq3_Ch9(void){
SYSCTL_RCGCGPIO_R |= 0x10; // 1) activate clock for Port E
while((SYSCTL_PRGPIO_R&0x10) == 0){};
GPIO_PORTE_DIR_R &= ~0x10; // 2) make PE4 input
GPIO_PORTE_AFSEL_R |= 0x10; // 3) enable alternate fun on PE4
GPIO_PORTE_DEN_R &= ~0x10; // 4) disable digital I/O on PE4
GPIO_PORTE_AMSEL_R |= 0x10; // 5) enable analog fun on PE4
SYSCTL_RCGCADC_R |= 0x01; // 6) activate ADC0
delay = SYSCTL_RCGCADC_R; // extra time to stabilize
delay = SYSCTL_RCGCADC_R; // extra time to stabilize
delay = SYSCTL_RCGCADC_R; // extra time to stabilize
delay = SYSCTL_RCGCADC_R;
ADC0_PC_R = 0x01; // 7) configure for 125K
ADC0_SSPRI_R = 0x0123; // 8) Seq 3 is highest priority
ADC0_ACTSS_R &= ~0x0008; // 9) disable sample sequencer 3
ADC0_EMUX_R &= ~0xF000; // 10) seq3 is software trigger
ADC0_SSMUX3_R = (ADC0_SSMUX3_R&0xFFFFFFF0)+9; // 11) Ain9 (PE4)
ADC0_SSCTL3_R = 0x0006; // 12) no TS0 D0, yes IE0 END0
ADC0_IM_R &= ~0x0008; // 13) disable SS3 interrupts
ADC0_ACTSS_R |= 0x0008; // 14) enable sample sequencer 3
}
Book shows Ain9=PE4 Lab 8, 9, 10 use Ain5=PD2
10-21
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
10-22
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
ADC on TM4C123
//------------ADC_InSeq3------------
// Busy-wait analog to digital conversion
// Input: none
// Output: 12-bit result of ADC conversion
uint32_t ADC0_InSeq3(void){
uint32_t data;
ADC0_PSSI_R = 0x0008;
while((ADC0_RIS_R&0x08)==0){};
data = ADC0_SSFIFO3_R&0xFFF;
ADC0_ISC_R = 0x0008;
return data;
}
10-23
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Data Acquisition System (Lab 8)
10-24
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Analog Input Device
3.3V
GND
PD2
10-25
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Transducer Circuit
There are 6 ways to connect 3 pins to 3 connections; 4 of which will explode; 2 of which will operate
10-26
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Data Acquisition System
P
o
s
i
t
i
o
n
S
e
n
s
o
r
V
o
l
t
a
g
e
0
t
o
+
3.3V
A
D
C
h
a
r
d
w
a
r
e
A
D
C
d
r
i
v
e
r
S
a
m
p
l
e
0
t
o
4
0
9
5
S
y
s
T
i
c
k
I
S
R
S
a
m
p
l
e
0
t
o
4
0
9
5
S
y
s
T
i
c
k
h
a
r
d
w
a
r
e
L
C
D
d
i
s
p
l
a
y
L
C
D
d
r
i
v
e
r
F
i
x
e
d
-
p
o
i
n
t
0
t
o
2
.
0
0
0
P
o
s
i
t
i
o
n
0
t
o
2
c
m
m
a
i
n
M
a
i
l
b
o
x
0 to 2.00cm
10-27
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Data Acquisition System
10-28
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Thread Synchronization in Lab 8
consumer
Background thread
Foreground thread
10-29
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Sampling Jitter
10-30
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Measurement
Average accuracy (with units of x) =
10-31
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Fixed-Point Revisited
express non-integer values
no floating-point hardware support (want it to run fast)
range of values is known
range of values is small
1) variable integer, called I.
may be signed or unsigned
may be 8, 16 or 32 bits (precision)
2) fixed constant, called Δ (resolution)
value is fixed, and can not be changed
not stored in memory
specify this fixed constant using comments
value ≡ integer • Δ
10-32
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Fixed-Point Numbers
Fixed-point number ≡ I•Δ
Smallest value = Imin • Δ, where Imin is the smallest integer
Largest value = Imax • Δ, where Imax is the largest integer
Decimal fixed-point number = I • 10m
Nice for human input/output
Binary fixed-point number = I • 2m
Easier for computers to perform calculations
10-33
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Fixed-Point Math Example
Consider the following calculation.
C = 2*π*R
The variables C, and R are integers
2π ≈ 6.283
C = (6283*R)/1000
2π ≈ 6434/1024 = 6.283203125
C = (6434*R)>>10
10-34
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Fixed-Point Math Example
Calculate the volume of a cylinder
V = π*R2 * L
The variables are fixed-point
R = I*2-4 cm L = J*2-4 cm
V = K*2-8 cm3 π ≈ 3217*2-10 = 3.1416015625
K*2-8 cm3 = (3217*2-10)*(I*2-4 cm)2*(J*2-4 cm)
K = (3217*I*I*J)>>14
10-35
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Vin (V) Analog in | N Digital out | I (1 mV) Variable part | LCD |
0 | 0 | 0 | 0.000 |
0.825 | 1024 | 825 | 0.825 |
1.650 | 2048 | 1650 | 1.650 |
2.475 | 3072 | 2475 | 2.475 |
3.3 | 4095 | 3300 | 3.300 |
Δ=0.001 V
Vin = 3.3•N/4095 how ADC works
or Vin = 3.3•N/4096 how ADC works
Vin = I • 0.001 definition of fixed point
I = (3300*N)/4096 substitution
I = (m•N+b)/ 4096 calibrate to get m and b
Make a Voltmeter with ADC
10-36
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi
Lab 8 Calibration (0.001)
Show Lab8_Accuracy
10-37
Bard, Tiwari, Telang, Holt, Cuevas, Gerstlauer, Valvano, Yerraballi