Analog
Analog
V_sensor ADC_Code
000..001
Ground 000..000
v(nT) t T 2T 3T 4T 5T 6T 7T t*
Sampled & quantized
(3/4)Vref
(2/4)Vref
Sampled data sequence:
d=10, 10, 10, 10, 11, 11, 11
(1/4)Vref
Binary values of n, where
(0/4)Vref
1 2 3 4 5 6 7 n v(nT) = (d/4)Vref
Minimum Sampling Rate:
Nyquist–Shannon Sampling Theorem
In order to be able to reconstruct the analog input signal, the sampling rate should be
at least twice the maximum frequency component contained in the input signal
Example of two sine waves have the same sampling values. This is called aliasing.
from wiki.com
5
Digital to Analog Converter
Digital-to-analog converter (DAC)
Converts digital data into a voltage signal by a N-bit DAC
𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷 𝑉𝑉𝑉𝑉𝑉𝑉𝑉𝑉𝑉𝑉
𝐷𝐷𝐷𝐷𝐷𝐷𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 = 𝑉𝑉𝑟𝑟𝑟𝑟𝑟𝑟 ×
2𝑁𝑁 − 1
For 12-bit DAC
𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷 𝑉𝑉𝑉𝑉𝑉𝑉𝑉𝑉𝑉𝑉
𝐷𝐷𝐷𝐷𝐷𝐷𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 = 𝑉𝑉𝑟𝑟𝑟𝑟𝑟𝑟 ×
4095
Many applications:
digital audio
waveform generation
Performance parameters
speed
resolution
power dissipation
7
Binary-weighted Resistor DAC
Reference
Voltage Digital value = 𝐷𝐷3 𝐷𝐷2 𝐷𝐷1 𝐷𝐷0
Analog
output
𝑅𝑅𝑟𝑟𝑟𝑟𝑟𝑟
𝑉𝑉𝑜𝑜𝑜𝑜𝑜𝑜 = 𝑉𝑉𝑟𝑟𝑟𝑟𝑟𝑟 × × (𝐷𝐷3 × 23 + 𝐷𝐷2 × 22 + 𝐷𝐷1 × 2 + 𝐷𝐷0 )
𝑅𝑅
8
Y. Zhu, Chapter 21
R-2R Resistor Ladder DAC
(Reference)
Current to
voltage
conversion
Equivalent
resistance = R Equivalent
resistance = R I/2n+1
x(t) x(n)
ADC
quantize
continuous-time analog signal discrete-time digital values
18
A/D – Flash Conversion
A multi-level voltage divider is used to set 1V
R Comparators
voltage levels over the complete range of 7/8 V +
conversion. R 1
A comparator is used at each level to -
Components used +
2Nresistors R Encoder 3
-
0
2 -1 comparators
N
3/8 V
Note +
Vin
Successive-approximation (SAR) ADC
𝑇𝑇𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶 = N × 𝑇𝑇𝐴𝐴𝐴𝐴𝐴𝐴_𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶
20
ADC - Successive Approximation Conversion
111111
Successively approximate input voltage
by using a binary search and a DAC Test voltage
(DAC output)
SA Register holds current
approximation of result Analog
Set all DAC input bits to 0 Input
100110
Voltage
Start with DAC’s most significant bit 100100
100000
Repeat
Bard, Gerstlauer,
Valvano, Yerraballi
ADC Performance Metrics
Linearity measures how well the transition voltages lie on a
straight line.
Multiplexing
Typically share a single ADC among multiple inputs
Need to select an input, allow time to settle before sampling
Signal Conditioning
Amplify and filter input signal
Protect against out-of-range inputs with clamping diodes
Sample and Hold Devices
May require analog input signal to be held constant during conversion.
Peak capture or sampling at a specific point in time may necessitate a sampling device.
“Sample and Hold”: Analog Input (Vin) is sampled when the Capture switch is closed
and its value is held on capacitor Cadc, where it becomes the analog output Vsample
S&H devices are incorporated into some A/D converters
26
STM32F4xx ADC Overview
Successive approximation conversion
High sampling speeds
Conversion range 0 to 3.6 volts
Supports multiple resolutions:
12, 10, 8 and 6 bits
16 regular and 4 injected channels
Supports single and continuous
conversions
Scan mode for sequence of inputs
Interrupt generation on
End of conversion
Analog watchdog
Overrun
Supports DMA transfers
Analog watchdog
Temperature sensor
ADC System Fundamentals
Output Registers
ADC
Analog Input
Clock
ADC Modes
29
Using the ADC
ADC initialization
Configure GPIO pin (analog mode)
Enable ADC clock
Enable ADC
Select voltage reference
Select trigger source
Select input channel
Select other parameters
Trigger conversion
Read results
Calibrate? Average?
On-off Control
For power efficiency, the ADC module is usually turned off (even if it is
clocked).
If ADON bit in ADC control register 2 is set, the module is powered on;
otherwise it is powered off.
Good practical to shut down ADC whenever you are not using it.
Clock Configuration
Analog Clock
ADCCLK, common to all ADCs
From APB2 (72Mhz) (Can be prescale by 1,2,4,8 or 16)
Can be prescaled by 2, 4, 6 or 8, which means at most 36MHz
ADC common control register(ADC_CCR) bit 17:16
ADC
Set up timer timer
interrupt
interrupt
Timer ADC
Peripheral Timer Peripheral
ISR
Process Data
ISR = Interrupt Service Routine
TIMER ISR starts ADC
Repeat ADC samples multiple channels
ADC ISR copies ADC data register to memory
43
Example: ADC with Timer and DMA
Main program
Set up DMA
Set up timer timer
samplin
interrupt
g DMA
Timer ADC channel Controller
Peripheral Timer Peripheral s
ISR
Process Data
Timer ISR starts ADC and DMA
DMA automatically copies ADC results of
Repeat multiple channels to memory after each
conversion
44
Using ADC Values
The ADC gives an integer representing the input voltage relative to the reference
voltages
Several conversions may be needed
For many applications you will need to compute the approximate input voltage
Vin = …
For some sensor-based applications you will need to compute the physical parameter value
based on that voltage (e.g. pressure) – this depends on the sensor’s transfer function
You will likely need to do additional computations based on this physical parameter (e.g.
compute depth based on pressure)
Data type
It’s likely that doing these conversions with integer math will lead to excessive loss of
precision, so use floating point math
AFTER you have the application working, you can think about accelerating the program
using fixed-point math (scaled integers).
Sometimes you will want to output ASCII characters (to the LCD, for example).
You will need to convert the floating point number to ASCII using sprintf, ftoa, or
another method.
Example: Temperature Sensor
ADC1 Channel 16
The minimum ADC sampling time for the temperature channel is 10
microseconds
Sampling cycles at least 110
T(°C) = {(Vsense-V25)/Avg_Slope}+25
V25=Vsense value for 25°C(typical value:0.78V)
Avg_Slope=average slope of the temperature vs. Vsense curve(typical
value:1.3mv/°C)
Vsense=DR×3/4096 (If Vref+=3v, Vref-=0v, 12-bit format)
Statics really vary from board to board!
Use your finger to press the chip in the center of the board, the
temperature will go high.