Hello, I have some questions.
I'm using the H3LIS331DL accelerometer
to calculate the distance and velocity of a RC Car.
I'm using the TI's Tiva MCU(TM4C123BH6PM, ARM Cortex-M4F series)
with 16MHz crystal.
The connection between the sensor and the MCU is fine.
I'm using SPI interface with 1MHz SPI clock.
The sensor returns the 'Who am I value' which is 0x32.
In other words, the hardware connection is reliable.
The following pseudo code is the register setup I applied to the sensor.
Write Control Register1 0x3F
with Low-pass filter cutoff Frequency 780Hz
Write Control Register2 0x33
FDS = 1 (data from internal filter sent to output reg)
High-Pass filter mode = Reference signal for filtering
High pass filter enable for interrupt source bypass
HPc = 64 (High-pass filter cutoff frequency config)
Write Control Register4 0x80
FS bit = 00, Sensitivity = 49mg/digit
Write Reference Register 0x0f
The following pseudo code is about reading the X_High, X_Low, Y_High, Y_Low,
Z_High and Z_Low.
Read X_High, X_Low
signed short x = ((X_High<<8) | X_Low) >> 4
//Since the sensor follows the 12-bit representation
double ax = x * 49 * 9.8 /1000;
//Same to y axis and z axis
As a result, the acceleration is shown as the following picture below.
I printed some data when the sensor is not moving.
The data are six MOSI(MCU TX, read X_High, read Y_Low, read Y_High, read X_Low, read Z_High, read Z_Low, ),
six MISO(MCU RX, value of X_High, X_Low, Y_High, Y_Low,Z_High, Z_Low,),
three 12 bit representation value(X, Y, Z), and three 12 bit value times 49 times 9.8
(acceleration value X, Y, Z).
I don't know how to print floating values on the terminal, so I didn't divided 1000.
I think the values are not valid. Is there some changes to be needed to the sensor's control registers?
So my question is
1. What changes are needed to the control registers?
2. Is the filter cut-off frequencies are resonable?
I actually don't understand why the Low-pass or High-pass filter is needed.
Also how much should I set the reference register?
3. Is the pseudo code above is correct?
4. Does the acceleration of Z should show -9.8 when it is not moving at all?
5. Finally, my goal is to use this sensor to calculate the velocity and the distance of a
moving RC car. However, the data above shows doubtful.
After changings some setting and adding some filters(like Kalman filter), what method should be reasonable to calculate the velocity or distance?
At first, I thougth set the dt as the system control clock (1/16MHz).
Then calculate velocity = a*dt, distance = old distance + velocity * dt.
Would calcuating like above give a rough estimation value?
Appreciate your help!