IIS3DWB
Arduino sketches for ST's vibration analyzer accelerometer
From the data sheet: "The IIS3DWB is a system-in-package featuring a 3-axis digital vibration sensor with low noise over an ultra-wide and flat frequency range. The wide bandwidth, low noise, very stable and repeatable sensitivity, together with the capability of operating over an extended temperature range (up to +105 °C), make the device particularly suitable for vibration monitoring in industrial applications."
The flat frequency range is 0 Hz to 6300 Hz (-3 dB bandwidth) with a 26667 Hz sample rate. The device has a large FIFO that can hold up to 3072 bytes of data, enough for 512 accelerometer data samples.
IIS3DWB breakout board sitting atop a Dragonfly STM32L476 development board via female pin headers.
The sketch is intended to be run on a Dragonfly development board at 80 MHz. The sensor uses the SPI interface for full functionality and fast data transfer. Maximum SPI clock is 10 MHz, which the Dragonfly can support at its 80 MHz CPU clock speed.
The basic sketch shows how to configure the sensor, including setting up a data ready interrupt on INT1 and an activity recognition (i.e., wakeup) interrupt on INT2, how to read the data, how to power down and power up the sensor, etc.
Second sketch shows how to set up the FIFO, collect accel data in the FIFO, set up the FIFO watermark and FIFO-full (watermark) interrupt, and then batch read the FIFO into a buffer for further processing on the host. Further processing includes FFT and power spectrum peak identification, etc.
We are reading the entire FIFO in one operation and subsequently constructing the data bytes rather than doing this all sequentially. Full (512 data samples) FIFO buffer read time is ~3.1 ms. Theoretical read time should be (512 samples x 7 bytes/sample x 8 bits/byte)/10 MHz = 2.87 ms so we are above 93% efficiency with > 15 ms of headroom.
Next steps are to test the IIS3DWB against a known vibrational source for accuracy and, after that, add a PDM mic for an overlapping frequency range sensitivity between 100 Hz and 40 kHz. The challenge will be to maintain full data and fft throughput on both data streams without collisions.
We tested the IIS3DWB against a hand-held Wahl Trimmer device. The IIS3DWB was mounted on top of the Dragonfly as shown above, and the Dragonfly was held by hand against the Wahl Trimmer. The 2048-bin FFT spectrum with the HPF filter set at 33 Hz (-3dB, ODR/800, maximum bandwidth setting) is shown below for both trimmer on and off:
The Wahl trimmer specs list the cutting frequency at 14400 cuts per minute, which we take to mean 7200 (two cuts per) motor revolutions per minute or 120 Hz vibration frequency. The dominant peak is at 3 Hz (first, DC bin) since we are using the rms accel data as input. The next-highest-intensity frequency is at 114 Hz (3% of the integrated intensity) with harmonics at 230, 341, and 686 Hz. There are somewhat weaker peaks at 58.5 Hz (60 Hz AC), 286 Hz and 796 Hz. The spectrum continues to tail off at higher frequencies (not shown). The zero vibration spectrum is essentially zero (orange line) on this scale. The total FFT time for 2048 bins is 4.0 ms, 5x (expected from Nlog2(N) dependence of FFT operations on bin size) the 800 us for 512 bins.
As a further check, we repeated the same procedure against a WMT-220 metronome set to 440 Hz. This time we fixed the FFT frequency range to half the 26667 Hz sample rate instead of twice the 6300 Hz bandwidth as above. The normalized PSD spectrum still shows a dominant peak in the first (DC) bin (as expected). The first non-DC peak has a weighted average of 443.6 Hz with two strong harmonics at 882.2 (2 x 441.1) Hz and 1324.9 (3 x 441.6) Hz. So the frequencies detected are still ~1% too high if we assume the 440 Hz output of the metronome is accurate. This is due to the fact that the IIS3DWB sample rate is not exactly 26667 Hz but can vary by typically +/-1% and as much as +/-2% per the data sheet. So best practice is to either measure the data rate via the interrupt, or simply adjust the FFT bin width to match an external source like the metronome.
Breakout board design is open source in the shared space at OSH Park.
FFT analysis code modifications from CMSIS library were done by Greg Tomasch.
L4 system layer and Arduino core designed (and SPI FIFO read strategy) by Thomas Roell.
Copyright 2020 Tlera Corporation. May be used by anyone with proper attribution.