Skip to content

Commit

Permalink
Low-pass filtering the measurements of MPU6500
Browse files Browse the repository at this point in the history
  • Loading branch information
shengwen-tw committed Feb 16, 2024
1 parent 317118e commit bc2e4d8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion drivers/devices/mpu6500.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <kernel/delay.h>
#include <printk.h>

#include "lpf.h"
#include "mpu6500.h"
#include "spi.h"
#include "stm32f4xx_conf.h"
Expand All @@ -10,11 +11,14 @@

#define MPU6500_EXTI_ISR_PRIORITY 14

struct mpu6500_device mpu6500 = {
static struct mpu6500_device mpu6500 = {
.accel_fs = MPU6500_GYRO_FS_8G,
.gyro_fs = MPU6500_GYRO_FS_1000_DPS,
};

/* First order low-pass filter for acceleromter */
static float mpu6500_lpf_gain;

static int mpu6500_open(struct inode *inode, struct file *file)
{
return 0;
Expand Down Expand Up @@ -194,6 +198,9 @@ void mpu6500_init(void)
mpu6500_write_byte(MPU6500_INT_ENABLE, 0x01);
__msleep(100);

/* Sampling time = 0.001s (1KHz), Cutoff frequency = 25Hz */
lpf_first_order_init(&mpu6500_lpf_gain, 0.001, 25);

register_chrdev("imu0", &mpu6500_file_ops);
printk("imu0: mp6500");
}
Expand Down Expand Up @@ -230,7 +237,16 @@ void mpu6500_interrupt_handler(void)
mpu6500.gyro_unscaled[1] = +s8_to_s16(buffer[10], buffer[11]);
mpu6500.gyro_unscaled[2] = -s8_to_s16(buffer[12], buffer[13]);

/* Convert measurementis to metric unit */
mpu6500_convert_to_scale();

/* Low-pass filtering for accelerometer to cancel vibration noise */
lpf_first_order(mpu6500.accel_raw[0], &(mpu6500.accel_lpf[0]),
mpu6500_lpf_gain);
lpf_first_order(mpu6500.accel_raw[1], &(mpu6500.accel_lpf[1]),
mpu6500_lpf_gain);
lpf_first_order(mpu6500.accel_raw[2], &(mpu6500.accel_lpf[2]),
mpu6500_lpf_gain);
}

void EXTI15_10_IRQHandler(void)
Expand Down

0 comments on commit bc2e4d8

Please sign in to comment.