adafruit / Adafruit_LIS3MDL

Adafruit library for LIS3MDL magnetometer
Other
11 stars 8 forks source link

custom SPI frequency and buffering of the range #7

Closed eringerli closed 2 years ago

eringerli commented 2 years ago

Allow for custom SPI clock frequency

Added an additional parameter to the SPI constructor, defaults to 1000000 as was before. The chip supports 10Mhz bus frequency. If you want to read out multiple chips with a high sample rate on a busy bus, rising the frequency to the maximum helps removing bottlenecks.

buffer the magnetic range instead of requesting it every time

Buffering the range instead of requesting it every time the data is read from the chips removes a lot of overhead for a couple of bytes of RAM.

ladyada commented 2 years ago

nice, looks like a good improvement. what hardware are you testing with?

eringerli commented 2 years ago

I test it with a combination of a ISM330 and a LIS3MDL, both connected on a SPI bus. On this bus, there is also an ADS131M04 4 channel-24bit-ADC. My main goal was to increase the sample rate for experiments with advanced filters for position calculations in agricultural guidance software. This is to filter the vibrations and roll/pitch out from the RTK-GNNS position with sufficient precision, as the antennas are typically mounted on the roof of the cab, which can be as high as 2.5...4m above ground. As all the distances are quite long on agricultural equipment, a precise orientation is important, so I'm really glad you supply precision IMUs with sufficient sample rate and resolution. A BNO085 (or even worse a BNO055) is way too unprecise and as the gyro is such a bad one, drifts a lot. In agricultural guidance, you run the software hours on end, so the effect of drift gets really bad and you have a lot of metal near the sensors, which doesn't improve the situation. So having less drift and noise is important. Because filtering generally works by removing unwanted information from a collection of data, having a lot of data allows for much heavier filtering. Also PID just works better with higher sample rates, as do all integrating/differential algorythms, which most in this field are (like EKFs or complement filters), also stuff like estimating the drift (which can get as bad as 15deg on slanted ground depending on the attached implement) requires a precise orientation to start with.

I can achieve 6.6kHz on the ISM330, 560Hz on the LIS3MDL and 4kHz on the ADC with an SPI rate of 10Mhz without overruns and with data-ready-interrupts. All this in done on a custom PCB with an ESP32 feather on it.

ladyada commented 2 years ago

ok sounds good, thanks!