0
0
Embedded Cprogramming~10 mins

Logic analyzer for signal debugging in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the logic analyzer input pin.

Embedded C
void init_logic_analyzer() {
    DDRD &= ~[1]; // Set PD2 as input
}
Drag options to blanks, or click blank then click option'
A(1 << PD4)
B(1 << PD2)
C(1 << PD3)
D(1 << PD5)
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the wrong bit for the input pin.
Using |= instead of &= ~ to clear the bit.
2fill in blank
medium

Complete the code to read the logic analyzer input pin state.

Embedded C
uint8_t read_signal() {
    return (PIND & [1]) ? 1 : 0;
}
Drag options to blanks, or click blank then click option'
A(1 << PD2)
B(1 << PD3)
C(1 << PD4)
D(1 << PD5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin mask.
Not using bitwise AND operator.
3fill in blank
hard

Fix the error in the code to store signal samples in the buffer.

Embedded C
void sample_signal(uint8_t *buffer, uint16_t length) {
    for (uint16_t i = 0; i < length; i++) {
        buffer[i] = [1];
    }
}
Drag options to blanks, or click blank then click option'
Aread_signal()
Bread_signal
C*read_signal()
D&read_signal()
Attempts:
3 left
💡 Hint
Common Mistakes
Using function name without parentheses.
Dereferencing the function pointer incorrectly.
4fill in blank
hard

Fill both blanks to configure the timer for sampling at 1 kHz frequency.

Embedded C
void setup_timer() {
    TCCR1B = (1 << [1]) | (1 << [2]); // Prescaler 64
    OCR1A = 249;
    TIMSK1 = (1 << OCIE1A);
}
Drag options to blanks, or click blank then click option'
ACS11
BCS10
CCS12
DWGM12
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong CS bits for prescaler.
Confusing WGM bits with CS bits.
5fill in blank
hard

Fill all three blanks to implement the interrupt service routine that stores samples.

Embedded C
ISR(TIMER1_COMPA_vect) {
    static uint16_t index = 0;
    if (index < [1]) {
        sample_buffer[[2]] = [3];
        index++;
    }
}
Drag options to blanks, or click blank then click option'
ABUFFER_SIZE
Bindex
Cread_signal()
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Not calling read_signal() function.