0
0
Embedded Cprogramming~20 mins

ADC interrupt-driven reading in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ADC Interrupt Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this ADC interrupt handler?

Consider the following ADC interrupt handler code snippet. What value will adc_value hold after the interrupt?

Embedded C
volatile uint16_t adc_value = 0;

void ADC_IRQHandler(void) {
    if (ADC_GetITStatus(ADC1, ADC_IT_EOC)) {
        adc_value = ADC_GetConversionValue(ADC1);
        ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
    }
}

// Assume ADC_GetConversionValue(ADC1) returns 1234 when called.
Aadc_value will be uninitialized garbage
Badc_value will be 4095
Cadc_value will be 0
Dadc_value will be 1234
Attempts:
2 left
💡 Hint

Think about what happens inside the interrupt when the end of conversion flag is set.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes ADC interrupt-driven reading?

Choose the best description of how ADC interrupt-driven reading works in embedded systems.

AThe ADC triggers an interrupt when conversion completes, allowing the CPU to handle the result asynchronously.
BThe CPU continuously polls the ADC status register to check if conversion is done.
CThe ADC conversion result is stored automatically in a global variable without CPU intervention.
DThe ADC conversion starts only when the CPU writes the result to memory.
Attempts:
2 left
💡 Hint

Think about how interrupts help the CPU avoid waiting actively.

🔧 Debug
advanced
2:30remaining
Why does this ADC interrupt handler fail to update the value?

Examine the code below. The adc_value variable never updates after ADC conversions. What is the likely cause?

Embedded C
uint16_t adc_value;

void ADC_IRQHandler(void) {
    if (ADC_GetITStatus(ADC1, ADC_IT_EOC)) {
        uint16_t value = ADC_GetConversionValue(ADC1);
        ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
    }
}

// adc_value is expected to hold the latest ADC reading.
AThe ADC conversion value function returns zero always.
BThe interrupt flag is not cleared, so the handler never runs.
C<code>adc_value</code> is never assigned inside the interrupt handler.
DThe variable <code>adc_value</code> is declared as volatile, causing optimization issues.
Attempts:
2 left
💡 Hint

Check if the variable that stores the ADC result is updated.

📝 Syntax
advanced
2:00remaining
Which option correctly enables ADC interrupt in this code?

Given the following code snippet, which option correctly enables the ADC interrupt?

Embedded C
void ADC_Config(void) {
    ADC_InitTypeDef ADC_InitStructure;
    // ADC initialization code here

    // Enable ADC interrupt
    // ???
}
AADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
BADC_ITConfig(ADC1, ADC_IT_OVR, DISABLE);
CADC_ITConfig(ADC1, ADC_IT_EOC);
DADC_ITConfig(ADC1, ENABLE, ADC_IT_EOC);
Attempts:
2 left
💡 Hint

Check the correct order and parameters for enabling ADC interrupts.

🚀 Application
expert
3:00remaining
How many ADC readings are stored after this interrupt-driven sequence?

Consider this code that uses an interrupt to read ADC values into a buffer of size 4. How many valid readings will adc_buffer contain after 6 ADC conversions?

Embedded C
volatile uint16_t adc_buffer[4];
volatile uint8_t index = 0;

void ADC_IRQHandler(void) {
    if (ADC_GetITStatus(ADC1, ADC_IT_EOC)) {
        adc_buffer[index++] = ADC_GetConversionValue(ADC1);
        if (index >= 4) {
            index = 0;
        }
        ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
    }
}

// Assume 6 ADC conversions complete, each triggering the interrupt.
A6 readings, all stored without overwrite
B4 readings, the buffer overwrites oldest values after 4
C2 readings, because index resets after 4
D0 readings, buffer is never updated
Attempts:
2 left
💡 Hint

Think about how the index variable cycles through the buffer size.