0
0
Embedded Cprogramming~20 mins

ADC conversion process (sample and hold) in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ADC Sample and Hold 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 sample and hold simulation code?

Consider this embedded C code simulating an ADC sample and hold process. What will be printed?

Embedded C
#include <stdio.h>

int main() {
    int analog_signal = 512; // Simulated analog input (10-bit ADC max 1023)
    int sample_and_hold = 0;
    int digital_value = 0;

    // Sample phase
    sample_and_hold = analog_signal;

    // Hold phase (conversion simulated)
    digital_value = sample_and_hold;

    printf("Digital value: %d\n", digital_value);
    return 0;
}
ADigital value: 512
BCompilation error
CDigital value: 1023
DDigital value: 0
Attempts:
2 left
💡 Hint

Think about what the sample and hold phase does to the analog signal before conversion.

Predict Output
intermediate
2:00remaining
What error occurs in this ADC sample and hold code?

Analyze this code snippet simulating ADC sample and hold. What error will it produce?

Embedded C
#include <stdio.h>

int main() {
    int *sample_and_hold = NULL;
    int analog_signal = 256;

    // Sample phase
    *sample_and_hold = analog_signal; // Attempt to store value

    printf("Value: %d\n", *sample_and_hold);
    return 0;
}
AUndefined behavior but prints 0
BCompilation error: dereferencing NULL pointer not allowed
CPrints: Value: 256
DSegmentation fault (runtime error)
Attempts:
2 left
💡 Hint

What happens if you try to write to a NULL pointer?

🧠 Conceptual
advanced
1:30remaining
Which statement correctly describes the sample and hold phase in ADC?

Choose the correct description of the sample and hold phase in an ADC conversion process.

AIt captures the analog input voltage and holds it steady during conversion.
BIt converts the analog signal directly into a digital value instantly.
CIt amplifies the analog signal before conversion.
DIt filters out noise from the digital output after conversion.
Attempts:
2 left
💡 Hint

Think about why the ADC needs a stable input during conversion.

Predict Output
advanced
2:00remaining
What is the output of this ADC sample and hold timing simulation?

Given this code simulating ADC sample and hold timing, what will be the output?

Embedded C
#include <stdio.h>
#include <stdbool.h>

int main() {
    int analog_signal = 700;
    int sample_and_hold = 0;
    bool sample_phase = true;

    if (sample_phase) {
        sample_and_hold = analog_signal;
        sample_phase = false;
    }

    // Hold phase
    int digital_value = sample_and_hold;

    printf("Digital value: %d\n", digital_value);
    return 0;
}
ADigital value: 0
BDigital value: 700
CDigital value: 1
DCompilation error
Attempts:
2 left
💡 Hint

Check what happens during the sample phase before hold.

Predict Output
expert
2:30remaining
What is the value of 'digital_value' after this ADC sample and hold code runs?

Analyze this embedded C code simulating an ADC sample and hold with noise. What is the final value of digital_value?

Embedded C
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    srand(0);
    int analog_signal = 400;
    int sample_and_hold = 0;
    int noise = 0;

    // Sample phase with noise
    noise = rand() % 5 - 2; // Noise between -2 and +2
    sample_and_hold = analog_signal + noise;

    // Hold phase
    int digital_value = sample_and_hold;

    printf("Digital value: %d\n", digital_value);
    return 0;
}
ADigital value: 402
BDigital value: 400
CDigital value: 399
DDigital value: 403
Attempts:
2 left
💡 Hint

Check the random noise generated with srand(0) and rand() % 5 - 2.