What is the output of the following embedded C code that simulates capturing 8 digital signal samples into a buffer?
#include <stdio.h> #include <stdint.h> int main() { uint8_t signal_samples[8] = {1, 0, 1, 1, 0, 0, 1, 0}; uint8_t buffer = 0; for (int i = 0; i < 8; i++) { buffer |= (signal_samples[i] << i); } printf("0x%02X\n", buffer); return 0; }
Remember that each bit is shifted by its index and ORed into the buffer.
The buffer accumulates bits from the signal_samples array, each shifted by its index. The bits are: 1 (bit0), 0 (bit1), 1 (bit2), 1 (bit3), 0 (bit4), 0 (bit5), 1 (bit6), 0 (bit7). This forms binary 01001101 which is 0x4D in hex.
Why is it important to sample a digital signal at a rate higher than twice its highest frequency component when using a logic analyzer?
Think about how sampling relates to signal frequency and reconstruction.
Sampling at more than twice the highest frequency (Nyquist rate) prevents aliasing, which causes distortion and incorrect signal representation.
Given the following ISR code snippet for capturing a signal edge, what is the main bug causing incorrect signal data capture?
volatile uint8_t signal_buffer = 0; volatile uint8_t bit_index = 0; void ISR_signal_edge() { uint8_t signal_value = READ_SIGNAL_PIN(); signal_buffer |= (signal_value << bit_index); bit_index++; if (bit_index >= 8) { bit_index = 0; PROCESS_SIGNAL(signal_buffer); signal_buffer = 0; } }
Consider what happens if main code reads signal_buffer while ISR modifies it.
Since signal_buffer and bit_index are shared between ISR and main code, they need atomic access or synchronization to avoid race conditions causing corrupted data.
Which option contains the correct syntax for capturing 8 bits from a digital input pin into a byte variable?
uint8_t capture_signal() {
uint8_t result = 0;
for (int i = 0; i < 8; i++) {
result |= (READ_PIN() << i)
}
return result;
}Check each line for missing punctuation.
The line 'result |= (READ_PIN() << i)' is missing a semicolon at the end, causing a syntax error.
A logic analyzer captures signal edges by storing each edge event in a 16-bit unsigned integer array of size 64. Each element stores the timestamp of an edge in microseconds. If the analyzer runs for 10 milliseconds and captures edges every 150 microseconds on average, how many edges will be stored in the array after the run?
Calculate how many 150 microsecond intervals fit into 10 milliseconds, then consider array size.
10 ms = 10,000 us. 10,000 / 150 ≈ 66.66 edges, but array size is 64, so only 64 edges can be stored.