ICM-4X60X 六轴传感器自由落体功能固件移植

                                                                                                                                                                               自由落体工程说明文档


前言:TDK ICM-4X6XX 系列六轴传感器没有自由落体功能,但是有一些客户需要实现自由落体的功能去实现一些产品的开发, 这里会详细给大家介绍自由落体固件的移植说明,方便客户快速导入开发

  1. 整体 main 函数 
int main(void)

{

int rc = 0;

struct inv_icm426xx_serif icm426xx_serif;



/* Initialize MCU hardware */

SetupMCUHardware(&icm426xx_serif);



/* Initialize Icm426xx */

rc = SetupInvDevice(&icm426xx_serif);

check_rc(rc, "error while setting up INV device");



/* Configure Icm426xx */

rc = ConfigureInvDevice(ICM_LOWG_FREQUENCY,

ICM_LOWG_PEAK_THRESHOLD,

ICM_LOWG_PEAK_HYSTERESIS,

ICM_LOWG_TIME_THRESHOLD);

check_rc(rc, "error while configuring INV device");



do {

/* Poll device for data */

if (irq_from_device & TO_MASK(INV_GPIO_INT1)) {



rc = GetLowGFromInvDevice();

check_rc(rc, "error while getting data from Icm426xx");



inv_disable_irq();

irq_from_device &= ~TO_MASK(INV_GPIO_INT1);

inv_enable_irq();

}



} while(1);

}
  1. 初始化函数中 SetupInvDevice(&icm426xx_serif); 里面有下载 FW :

   

 /* Loads DMP image to SRAM */

rc |= inv_icm426xx_load_dmp_sram_code(&icm_driver, dmp_image, 16, sizeof(dmp_image) /

sizeof(dmp_image[0]));

 

注意:

因为它只能通过外部加载的算法,所以首先上电前需要下载FW,而后只需要配置好就行了,然后它可以映射到中断PIN上,通过识别中断来判断。

所以如果下载 FW , 会占用到 WoM & Apex 的功能,所以会导致这两个功能失效。

 

  1. 接下来就是 LOWG 的配置函数,LOWG 就是我们的自由落体的功能。

 

   /* Configure Icm426xx */

rc = ConfigureInvDevice(ICM_LOWG_FREQUENCY,

ICM_LOWG_PEAK_THRESHOLD,

ICM_LOWG_PEAK_HYSTERESIS,

ICM_LOWG_TIME_THRESHOLD);

参数说明:

ICM_LOWG_FREQUENCY 这个是 sensor 要用LOWG 的时候需要配置的 ODR。

后面三个都是LOWG相关的配置参数。

ConfigureInvDevice这个函数最开始就是配置中断:

  

  /* Enable only lowg on INT1 */


config_int.INV_ICM426XX_LOWG_DET = INV_ICM426XX_ENABLE;

inv_icm426xx_set_config_int1(&icm_driver, &config_int);



/* Disable all interrupts on INT2 and IBI */

config_int.INV_ICM426XX_LOWG_DET = INV_ICM426XX_DISABLE;

inv_icm426xx_set_config_int2(&icm_driver, &config_int);

inv_icm426xx_set_config_ibi(&icm_driver, &config_int);

接下来配置 LOWG 参数:设置 ODR,滤波器,和打开 sensor 到 LPM

    /* Enable accelerometer to feed the APEX algorithms. (1KHz by default, could be set to 500Hz). */

rc |= inv_icm426xx_set_accel_frequency(&icm_driver,

ICM426XX_ACCEL_CONFIG0_ODR_1_KHZ);



/* Set 1x averaging, in order to minimize power consumption (16x by default) */

rc |= inv_icm426xx_set_accel_lp_avg(&icm_driver,

ICM426XX_GYRO_ACCEL_CONFIG0_ACCEL_FILT_AVG_1);



rc |= inv_icm426xx_enable_accel_low_power_mode(&icm_driver);

 

然后是对芯片内部的 APEX 功能做配置,

这个功能 APEX 下载 FW 就不能用了,那这个配置的话就是实际配置 LOWG 的参数。

APEX 就是 advanced Pedometer and Event Detector, 就是内部的一些功能的,这个 LOWG其实是把内部的功能频率,然后占用了他们的寄存器来用的。

 

   /* Initializes APEX features */

rc |= inv_icm426xx_init_apex_parameters_struct(&icm_driver, &apex_inputs);

apex_inputs.power_save = ICM426XX_APEX_CONFIG0_DMP_POWER_SAVE_DIS;

rc |= inv_icm426xx_configure_apex_parameters(&icm_driver, &apex_inputs);



/* Initializes APEX lowg features */

rc |= inv_icm426xx_init_apex_highg_lowg_parameters_struct(&icm_driver, &apex_full_inputs);

apex_full_inputs.apex_highg_lowg_inputs.lowg_peak_th = lowg_peak_th;

apex_full_inputs.apex_highg_lowg_inputs.lowg_peak_hyst = lowg_peak_hyst;

apex_full_inputs.apex_highg_lowg_inputs.lowg_time_th = lowg_time_th;

rc |= inv_icm426xx_configure_apex_highg_lowg_parameters(&icm_driver, &apex_full_inputs);

rc |= inv_icm426xx_set_apex_frequency(&icm_driver, lowg_freq);

 

最后使能 LOWG 功能:

    /* Enable the lowG sensors */

rc |= inv_icm426xx_enable_apex_lowg(&icm_driver);

 

  1. 以上配置完成,读下中断状态寄存器,看下是不是 LOWG
    /* Poll device for data */

GetLowGFromInvDevice();

  

  1. 优化,ConfigureInvDevice 函数的后面三个参数:参考如下


     6.  最后附件会提供相关代码,谢谢参考。

技术文档

类型标题档案
软件相关代码

★博文内容均由个人提供,与平台无关,如有违法或侵权,请与网站管理员联系。

★文明上网,请理性发言。内容一周内被举报5次,发文人进小黑屋喔~

评论