Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the wrong bit for the input pin.
Using |= instead of &= ~ to clear the bit.
✗ Incorrect
We clear the bit for PD2 in DDRD to set it as input.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin mask.
Not using bitwise AND operator.
✗ Incorrect
We mask PIND with (1 << PD2) to read the state of PD2 pin.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using function name without parentheses.
Dereferencing the function pointer incorrectly.
✗ Incorrect
We must call the function read_signal() to get the current signal value.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong CS bits for prescaler.
Confusing WGM bits with CS bits.
✗ Incorrect
Setting CS11 and CS10 bits in TCCR1B sets the prescaler to 64 for the timer.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Not calling read_signal() function.
✗ Incorrect
The ISR stores samples in sample_buffer at position index until BUFFER_SIZE is reached, reading the signal each time.