Analog-to-Digital Converter-ADC - ARM
Analog-to-Digital Converter-ADC - ARM
Chapter 20
Analog-to-Digital Converter (ADC)
Spring 2015
1
Analog-to-Digital Converter (ADC)
} ADC is important to almost all application fields
} Converts a continuous-time voltage signal within a given range
to discrete-time digital values to quantify the voltage’s
amplitudes
x(t) x(n)
ADC
quantize
continuous-time analog signal discrete-time digital values
2
Analog-to-Digital Converter (ADC)
} Three performance parameters:
} sampling rate: number of conversions per second (thousands to milions)
} resolution: number of bits in ADC output (6 to 24)
} power dissipation: power efficiency of ADC
} Many ADC implementations:
} sigma-delta
} for apps requiring low sampling rate (<100 kHz) but high resolution (12-24 bit)
} e.g.: voice and audio apps in cell phones
} successive-approximation (SAR)
} for low-power data acquisitions w/ moderate sampling rates (<5MHz)
} e.g.: STM32 microcontrollers
} pipelined
} for high-speed apps (sampling rate > 5MHz) and relatively low resolution
} e.g.: radar communication
3
Resolution
} Resolution is determined by number of bits (in binary) to represent an analog input.
} Example of two quantization methods (N = 3)
½Δ
Δ
𝑉 𝑉
𝐷𝑖𝑔𝑖𝑡𝑎𝑙 𝑅𝑒𝑠𝑢𝑙𝑡 = 𝑓𝑙𝑜𝑜𝑟 2! × 𝐷𝑖𝑔𝑖𝑡𝑎𝑙 𝑅𝑒𝑠𝑢𝑙𝑡 = 𝑟𝑜𝑢𝑛𝑑 2! ×
𝑉"#$ 𝑉"#$
Max quantization error = Δ = VREF/23 Max quantization error = ±½ Δ = ±VREF/24
4 𝑟𝑜𝑢𝑛𝑑 𝑥 = 𝑓𝑙𝑜𝑜𝑟(𝑥 + 0.5)
Quantization Error
} For N-bit ADC, it is limited to ±½Δ
} Δ = is the step size of the converter.
} Example: for 12-bit ADC and input voltage range [0, 3V]
1 3𝑉
𝑀𝑎𝑥 𝑄𝑢𝑎𝑛𝑡𝑖𝑧𝑎𝑡𝑖𝑜𝑛 𝐸𝑟𝑟𝑜𝑟 = ∆= = 0.367𝑚𝑉
2 2×2!"
5
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
6
Successive-approximation (SAR) ADC
7
Determining Minimum Sampling Time
𝒕
&𝑻 Sampling time is software
𝑽𝑪 𝒕 = 𝑽𝒊𝒏 ×(𝟏 − 𝒆 𝒄)
programmable!
8
Programming ADC Sampling Time
4 cycles
9 cycles
HSI Clock ADC Clock
Prescaler 16 cycles
Selection
16 MHz /1, /2, /4
24 cycles
default prescaler = 1 48 cycles
96 cycles
192 cycles
384 cycles
9
Successive-approximation (SAR) ADC
𝑇+42567,142 = N×𝑇)*+_+049:
10
ADC Conversion Time
𝑇<=> = 𝑇?@ABCDEF + 𝑇>GEHIJ?DGE
11
Data Alignment
12
ADC: Regular vs injected
13
ADC Mode
14
ADC Mode
Regular channel:
1. Set SWSTART in ADC_CR2
2. The channel is selected by SQ1[4:0]
in SQR5
3. Result is stored in ADC_DR
4. EOC is set after conversion
5. Interrupt is generated if EOCIE is set
Injected channel:
1. Set JSWSTART in ADC_CR2
2. The channel is selected by JSQ1[4:0]
in JSQR
3. Result is stored in ADC_JDR1
4. JEOC is set after conversion
5. Interrupt is generated if JEOCIE is set
15
ADC Mode
16
VREF
} Some chips does not expose VREF to a pin
} STM32L LQFP64 does not have VREF pin
} STM32L LQFP100 does
} Infer internal VREF
Corresponds to VREF
} How?
17
Analog Watchdog
Analog voltage
Two programmable thresholds
} If V < VLTR or V > VHTR, the analog watchdog (AWD) flag (in ADC Status
Register) is set, generating an interrupt to the processor
} The monitor is automatically performed by hardware, not software
} Convenient and efficient feature
} Help processor detect exceptions and recover from specific situations
} For example, monitor sensor data and raise alarm on some level.
18
Example: ADC with Timer Interrupts
Main program
ADC
Set up timer timer
interrupt
interrupt
Timer ADC
Timer ISR
Peripheral Peripheral
Process Data
} ISR = Interrupt Service Routine
} TIMER ISR starts ADC
Repeat } ADC samples multiple channels
} ADC ISR copies ADC data register to memory
19
Example: ADC with Timer and DMA
Main program
Set up DMA
Set up timer timer
sampling
interrupt
channels DMA
Timer ADC Controller
Timer ISR
Peripheral Peripheral
Process Data
} Timer ISR starts ADC and DMA
} DMA automatically copies ADC results
Repeat of multiple channels to memory after
each conversion
20