0
0
Embedded Cprogramming~20 mins

Single channel ADC reading in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ADC Mastery Badge
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 reading code?

Consider the following embedded C code snippet that reads from a single ADC channel and stores the result in a variable. What will be the value of adc_value after execution?

Embedded C
volatile uint16_t adc_value = 0;
void read_adc(void) {
    ADC->CHSELR = ADC_CHSELR_CHSEL0; // Select channel 0
    ADC->CR |= ADC_CR_ADSTART;       // Start conversion
    while (!(ADC->ISR & ADC_ISR_EOC)); // Wait for conversion complete
    adc_value = ADC->DR;             // Read data register
}
Aadc_value is always zero because ADC is not started
Badc_value contains the 12-bit ADC conversion result from channel 0
Cadc_value contains a random value due to missing conversion start
Dadc_value contains the previous conversion result, not updated
Attempts:
2 left
💡 Hint

Check if the ADC conversion is started and if the code waits for completion before reading.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes single channel ADC reading?

In embedded systems, what does single channel ADC reading mean?

AReading digital inputs instead of analog
BReading multiple ADC channels simultaneously
CUsing ADC in differential mode with two channels combined
DReading analog input from one specific ADC channel at a time
Attempts:
2 left
💡 Hint

Focus on the meaning of 'single channel' in ADC context.

🔧 Debug
advanced
2:30remaining
Why does this ADC reading code hang in the while loop?

Analyze the following code snippet. Why does the program get stuck in the while loop?

Embedded C
ADC->CHSELR = ADC_CHSELR_CHSEL1; // Select channel 1
ADC->CR |= ADC_CR_ADSTART;         // Start conversion
while (!(ADC->ISR & ADC_ISR_EOC)); // Wait for conversion complete
uint16_t val = ADC->DR;
AThe ADC is not enabled before starting conversion, so EOC flag never sets
BThe channel selection register is incorrect, causing conversion failure
CThe data register is read before conversion starts
DThe interrupt flag is cleared too early, causing infinite wait
Attempts:
2 left
💡 Hint

Check if ADC peripheral is enabled before starting conversion.

📝 Syntax
advanced
1:30remaining
Which option fixes the syntax error in this ADC reading code?

Identify the option that corrects the syntax error in the following code snippet:

uint16_t read_adc() {
    ADC->CHSELR = ADC_CHSELR_CHSEL2
    ADC->CR |= ADC_CR_ADSTART;
    while (!(ADC->ISR & ADC_ISR_EOC));
    return ADC->DR;
}
AAdd a semicolon after the channel selection line
BReplace ADC_CHSELR_CHSEL2 with ADC_CHSELR_CHSEL3
CChange return type to void
DRemove the while loop
Attempts:
2 left
💡 Hint

Look for missing punctuation that causes syntax errors.

🚀 Application
expert
3:00remaining
How many ADC readings are stored after this code runs?

Given this code that reads ADC channel 0 five times and stores results in an array, how many valid ADC readings does the array contain?

uint16_t adc_results[5];
for (int i = 0; i < 5; i++) {
    ADC->CHSELR = ADC_CHSELR_CHSEL0;
    ADC->CR |= ADC_CR_ADSTART;
    while (!(ADC->ISR & ADC_ISR_EOC));
    adc_results[i] = ADC->DR;
}
AOnly 1 valid reading, repeated 5 times
B0 readings because ADC is not enabled
C5 valid ADC readings, one per loop iteration
DUndefined number due to missing delay between readings
Attempts:
2 left
💡 Hint

Consider the loop and waiting for conversion complete each time.