I have a device which can sample its accelerometer (a run-of-the-mill ADXL345) at up to 1600hz. I want it to transmit data (wirelessly, using bluetooth low energy, but that part is not too important) to a PC for analysis. It is important to sample at a consistent rate (ie, a predictable number of mili/microseconds between data points), and not so important for the PC to get the data as consistently.
Problem: the operation to send a “packet” of data takes a finite amount of time, ~15 milliseconds on the board I’m using (a punchthrough bean, an arduino compatible atmega328p board with a BLE module), during which I cannot sample the accelerometer because the send operation is blocking (is this normal??). Since it can sample at 1600hz, I could be sampling ~24 data points during this gap.
Partial solution: the ADXL has an internal, 32 item FIFO buffer which can keep collecting data while sending, so if I set the sampling rate to 1600hz, ~24 items are waiting for me after each send. Then, since each packet can only carry 3 data points, I take items 0, 8, and 16 from the FIFO, so hopefully every point is evenly spaced as possible.
Question: What is a more general solution where you need to interleave sampling and sending? Not all devices, esp. analog sensors, have internal buffers. Should I be using interrupts? Do I need a multi-core chip, which one core for collecting and another for sending? Any pointers to book/articles welcome, I’m a total amateur/hobbyist…