← Engineering Notes

Keeping a Vibration Logger Recording While Its SD Card Is Busy

Recording a few hundred measurements a second to an SD card sounds straightforward. The amount of data is small, and even a fairly ordinary card can write it comfortably. We wanted to build a vibration logger that could do this continuously, without quietly losing measurements whenever the card took longer than expected.

Our bench demonstrator eventually recorded 13.77 million three-axis samples over eight hours, with no detected gaps or corrupted data. Getting there involved paying attention to the pauses between writes as well as the average recording speed.

The sensor was an STMicroelectronics MEMS accelerometer. MEMS stands for micro-electromechanical systems: tiny mechanical structures fabricated into a chip. Inside the accelerometer, microscopic suspended structures move in response to acceleration, and electronics measure that movement. Similar sensors allow a phone to detect its orientation. Ours provided measurements along three perpendicular axes.

An STM32 microcontroller collected those readings and saved them to an SD card, with a separate real-time clock providing timing references.

Wiring overview of the vibration logger, showing the microcontroller, accelerometer, removable SD storage and real-time clock.

At approximately 480 samples per second, a new set of readings arrives roughly every two milliseconds. The resulting data rate is only a few kilobytes per second. However, during testing we observed an SD write taking 510 milliseconds. Around 240 more samples can arrive while that write finishes.

If the firmware waits for the card before collecting the next measurement, those readings are lost.

Giving the Data Somewhere to Wait

The accelerometer includes a FIFO, short for first in, first out. This is a small queue which stores measurements in the order they were taken, allowing the microcontroller to collect several at once rather than having to fetch each one immediately.

That queue has limited capacity. It buys time, but still needs emptying regularly.

The firmware transfers measurements from the sensor into buffers in the microcontroller’s RAM, then writes buffered data to the SD card in blocks. This lets acquisition and storage proceed at different rates for short periods, provided there is enough space for the accumulating measurements.

To check the behaviour, we recorded storage delays, intervals between servicing the sensor, and any acquisition overruns or communication errors. Each saved block also carried an integrity check, while sample indices let us look for missing sections after downloading the recording.

The eight-hour test captured 13,770,894 three-axis samples. Checking the complete file found no corrupted blocks or gaps in the recorded sample sequence, and the firmware reported no acquisition overruns or peripheral errors.

Despite the longest SD write taking just over half a second, the maximum interval between servicing the sensor FIFO was 84 milliseconds. The acquisition chain kept up through the delays encountered.

The next hardware revision needs measured power consumption across complete recording cycles. Running reliably from the development board’s USB supply lets us check the recording behaviour, but before choosing a battery we need to understand what the sensor, processor and SD card actually consume together.