Complete the code to initialize the logic analyzer input pin.
void init_logic_analyzer() {
DDRD &= ~[1]; // Set PD2 as input
}We clear the bit for PD2 in DDRD to set it as input.
Complete the code to read the logic analyzer input pin state.
uint8_t read_signal() {
return (PIND & [1]) ? 1 : 0;
}We mask PIND with (1 << PD2) to read the state of PD2 pin.
Fix the error in the code to store signal samples in the buffer.
void sample_signal(uint8_t *buffer, uint16_t length) {
for (uint16_t i = 0; i < length; i++) {
buffer[i] = [1];
}
}We must call the function read_signal() to get the current signal value.
Fill both blanks to configure the timer for sampling at 1 kHz frequency.
void setup_timer() {
TCCR1B = (1 << [1]) | (1 << [2]); // Prescaler 64
OCR1A = 249;
TIMSK1 = (1 << OCIE1A);
}Setting CS11 and CS10 bits in TCCR1B sets the prescaler to 64 for the timer.
Fill all three blanks to implement the interrupt service routine that stores samples.
ISR(TIMER1_COMPA_vect) {
static uint16_t index = 0;
if (index < [1]) {
sample_buffer[[2]] = [3];
index++;
}
}The ISR stores samples in sample_buffer at position index until BUFFER_SIZE is reached, reading the signal each time.
