0
0
Embedded Cprogramming~10 mins

ADC interrupt-driven reading in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - ADC interrupt-driven reading
Start ADC Conversion
ADC Conversion Complete?
NoWait
Yes
ADC Interrupt Triggered
Interrupt Service Routine (ISR)
Read ADC Result
Process or Store Result
Restart ADC Conversion
Back to Start
The ADC starts conversion, waits until done, triggers an interrupt, ISR reads and processes the result, then restarts conversion.
Execution Sample
Embedded C
void ADC_ISR(void) {
  int adc_value = ADC_Read();
  process(adc_value);
  ADC_StartConversion();
}
This ISR reads the ADC value when conversion completes, processes it, and starts a new conversion.
Execution Table
StepEventADC Conversion StatusISR CalledADC Value ReadAction Taken
1ADC conversion startedIn ProgressNoN/AWaiting for conversion
2ADC conversion completeCompleteYesValue read from ADCProcess value and restart conversion
3New ADC conversion startedIn ProgressNoN/AWaiting for next conversion
4ADC conversion completeCompleteYesNew value readProcess value and restart conversion
ExitStop or power downN/ANoN/AADC conversions stopped
💡 ADC conversions stop when device powers down or ADC is disabled
Variable Tracker
VariableStartAfter Step 2After Step 4Final
adc_valueundefinedValue from first conversionValue from second conversionLast read value
ADC Conversion StatusIdleCompleteCompleteStopped or Idle
Key Moments - 3 Insights
Why does the ADC conversion start again inside the ISR?
Because after reading the ADC value in the ISR (see Step 2 in execution_table), we need to start a new conversion to keep reading fresh data continuously.
What triggers the ADC ISR to run?
The ADC hardware triggers the ISR automatically when the conversion completes (Step 2 and 4 in execution_table), so the CPU can read the result immediately.
Why don't we read the ADC value outside the ISR?
Reading inside the ISR ensures we get the value right after conversion finishes, avoiding delays or missed data, as shown in the execution_table steps.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the ADC Conversion Status at Step 1?
AComplete
BIdle
CIn Progress
DStopped
💡 Hint
Check the 'ADC Conversion Status' column at Step 1 in the execution_table.
At which step does the ISR read the ADC value?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look for 'ISR Called' and 'ADC Value Read' columns in execution_table.
If the ADC conversion never completes, what happens to the ISR calls?
AISR is called repeatedly
BISR is never called
CISR is called once
DISR calls happen randomly
💡 Hint
Refer to the 'ADC Conversion Complete?' decision in concept_flow and ISR trigger in execution_table.
Concept Snapshot
ADC interrupt-driven reading:
- Start ADC conversion
- Wait for conversion complete interrupt
- ISR reads ADC value
- Process value inside ISR
- Restart conversion for continuous reading
Full Transcript
This visual execution trace shows how ADC interrupt-driven reading works. The ADC starts conversion and waits until it finishes. When done, it triggers an interrupt. The interrupt service routine (ISR) runs, reads the ADC value, processes it, and starts a new conversion. Variables like adc_value update after each ISR call. This cycle repeats until ADC is stopped or powered down. Key points include starting conversion inside ISR and ISR triggering only after conversion completes.