Cse331 L19 Adc P2
Cse331 L19 Adc P2
1
Successive-approximation (SAR) ADC
2
Determining Minimum Sampling Time
is software configurable
4
SAR: Successive Approximation Register
5
ADC Conversion Time
6
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
7
Data Alignment
8
ADC: Regular vs injected
9
ADC Mode
10
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
11
ADC Mode
Channels are
selected by
ADC_SQRx
registers for
regular channels,
and by ADC_JSQR
register for
injected channel
All channels in a
regular group
share the same
result register
ADC_DR. Make
sure to read data
between
consecutive
sampling.
12
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.
13
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
14
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
15