0
0
Embedded Cprogramming~20 mins

Multi-channel ADC scanning in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ADC Scan Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of multi-channel ADC scan loop

Consider the following embedded C code snippet that simulates scanning 3 ADC channels and storing their values in an array. What will be the output printed?

Embedded C
#include <stdio.h>

int main() {
    int adc_values[3];
    for (int ch = 0; ch < 3; ch++) {
        adc_values[ch] = ch * 100 + 50; // Simulated ADC reading
    }
    for (int ch = 0; ch < 3; ch++) {
        printf("Channel %d: %d\n", ch, adc_values[ch]);
    }
    return 0;
}
A
Channel 0: 50
Channel 1: 100
Channel 2: 150
B
Channel 0: 0
Channel 1: 100
Channel 2: 200
C
Channel 0: 50
Channel 1: 150
Channel 2: 250
D
Channel 0: 100
Channel 1: 200
Channel 2: 300
Attempts:
2 left
💡 Hint

Look at how the ADC value is calculated inside the loop: ch * 100 + 50.

🧠 Conceptual
intermediate
1:30remaining
Understanding ADC scan sequence configuration

In multi-channel ADC scanning, what is the main purpose of configuring the scan sequence?

ATo define the order in which ADC channels are converted during a scan
BTo set the voltage reference for the ADC conversion
CTo adjust the ADC clock speed for faster conversions
DTo enable interrupts after each individual channel conversion
Attempts:
2 left
💡 Hint

Think about how multiple channels are read one after another.

🔧 Debug
advanced
2:30remaining
Identify the cause of incorrect ADC values in multi-channel scan

Given the following code snippet for scanning 4 ADC channels, the output values are all zero. What is the most likely cause?

#define NUM_CHANNELS 4
int adc_results[NUM_CHANNELS];

void start_adc_scan() {
    for (int i = 0; i < NUM_CHANNELS; i++) {
        adc_results[i] = 0;
    }
    // Start ADC hardware scan here
}

void adc_scan_complete_callback() {
    for (int i = 0; i < NUM_CHANNELS; i++) {
        adc_results[i] = read_adc_channel(i);
    }
}

int main() {
    start_adc_scan();
    // Wait for scan to complete
    for (int i = 0; i < NUM_CHANNELS; i++) {
        printf("Channel %d: %d\n", i, adc_results[i]);
    }
    return 0;
}
AThe main function prints adc_results before the scan completes and callback updates values
BThe read_adc_channel function is not implemented correctly
CThe adc_results array is not initialized before scanning
DThe start_adc_scan function does not clear previous results
Attempts:
2 left
💡 Hint

Consider when the ADC scan completes and when the results are printed.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in ADC scan configuration

Which option contains a syntax error in this ADC scan channel configuration snippet?

int channels[] = {0, 1, 2, 3};
int num_channels = 4;

for (int i = 0; i < num_channels; i++) {
    configure_adc_channel(channels[i]);
}
Afor (int i = 0; i < num_channels; i++) { configure_adc_channel(channels[i]); }
B} ;)]i[slennahc(lennahc_cda_erugifnoc { )++i ;slennahc_mun < i ;0 = i tni( rof
Cfor (int i = 0; i < num_channels; i++) configure_adc_channel(channels[i]);
Dfor int i = 0; i < num_channels; i++ { configure_adc_channel(channels[i]); }
Attempts:
2 left
💡 Hint

Check the syntax of the for loop header.

🚀 Application
expert
3:00remaining
Calculate total ADC scan time for multiple channels

An ADC has a sample time of 12 clock cycles per channel and a conversion time of 15 clock cycles per channel. The ADC clock runs at 1 MHz. If you scan 5 channels in sequence, what is the total time in microseconds to complete the full scan?

A60 microseconds
B135 microseconds
C75 microseconds
D1350 microseconds
Attempts:
2 left
💡 Hint

Total time per channel = sample time + conversion time. Multiply by number of channels. Clock frequency is 1 MHz (1 clock cycle = 1 microsecond).