Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit b09262f

Browse files
v3.6.0
Added Fast offset compensation
1 parent d28f5e2 commit b09262f

5 files changed

Lines changed: 687 additions & 19 deletions

File tree

README.md

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ This package contains the Bosch Sensortec's BMI160 sensor driver (sensor API)
55
The sensor driver package includes bmi160.h, bmi160.c and bmi160_defs.h files
66

77
## Version
8-
File | Version | Date
9-
-----|---------|-----
10-
bmi160.c | 3.5.0 | 13 Apr 2017
11-
bmi160.h | 3.5.0 | 13 Apr 2017
12-
bmi160_defs.h | 3.5.0 | 13 Apr 2017
8+
File | Version | Date
9+
--------------|---------|---------------
10+
bmi160.c | 3.6.0 | 04 Aug 2017
11+
bmi160.h | 3.6.0 | 04 Aug 2017
12+
bmi160_defs.h | 3.6.0 | 04 Aug 2017
1313

1414
## Integration details
1515
* Integrate bmi160.h, bmi160_defs.h and bmi160.c file in to your project.
@@ -518,4 +518,130 @@ int8_t fifo_gyro_header_time_data(struct bmi160_dev *dev)
518518
}
519519
```
520520

521+
## FOC and offset compensation
522+
> FOC shouldnot be used in Low-power mode
523+
#### Example for configuring FOC for accel and gyro
524+
```
525+
/* An example for configuring FOC for accel and gyro data */
526+
int8_t start_foc(struct bmi160_dev *dev)
527+
{
528+
int8_t rslt = 0;
529+
/* FOC configuration structure */
530+
struct bmi160_foc_conf foc_conf;
531+
/* Structure to store the offsets */
532+
struct bmi160_offsets offsets;
533+
534+
/* Enable FOC for accel with target values of z = 1g ; x,y as 0g */
535+
foc_conf.acc_off_en = BMI160_ENABLE;
536+
foc_conf.foc_acc_x = BMI160_FOC_ACCEL_0G;
537+
foc_conf.foc_acc_y = BMI160_FOC_ACCEL_0G;
538+
foc_conf.foc_acc_z = BMI160_FOC_ACCEL_POSITIVE_G;
539+
540+
/* Enable FOC for gyro */
541+
foc_conf.foc_gyr_en = BMI160_ENABLE;
542+
foc_conf.gyro_off_en = BMI160_ENABLE;
543+
544+
rslt = bmi160_start_foc(&foc_conf, &offsets, sen);
545+
546+
if (rslt == BMI160_OK) {
547+
printf("\n FOC DONE SUCCESSFULLY ");
548+
printf("\n OFFSET VALUES AFTER FOC : ");
549+
printf("\n OFFSET VALUES ACCEL X : %d ",offsets.off_acc_x);
550+
printf("\n OFFSET VALUES ACCEL Y : %d ",offsets.off_acc_y);
551+
printf("\n OFFSET VALUES ACCEL Z : %d ",offsets.off_acc_z);
552+
printf("\n OFFSET VALUES GYRO X : %d ",offsets.off_gyro_x);
553+
printf("\n OFFSET VALUES GYRO Y : %d ",offsets.off_gyro_y);
554+
printf("\n OFFSET VALUES GYRO Z : %d ",offsets.off_gyro_z);
555+
}
556+
557+
/* After start of FOC offsets will be updated automatically and
558+
* the data will be very much close to the target values of measurement */
559+
560+
return rslt;
561+
}
562+
```
563+
564+
#### Example for updating the offsets manually
565+
> The offsets set by this method will be reset on soft-reset/POR
566+
```
567+
/* An example for updating manual offsets to sensor */
568+
int8_t write_offsets(struct bmi160_dev *dev)
569+
{
570+
int8_t rslt = 0;
571+
/* FOC configuration structure */
572+
struct bmi160_foc_conf foc_conf;
573+
/* Structure to store the offsets */
574+
struct bmi160_offsets offsets;
575+
576+
/* Enable offset update for accel */
577+
foc_conf.acc_off_en = BMI160_ENABLE;
578+
579+
/* Enable offset update for gyro */
580+
foc_conf.gyro_off_en = BMI160_ENABLE;
581+
582+
/* offset values set by user */
583+
offsets.off_acc_x = 0x10;
584+
offsets.off_acc_y = 0x10;
585+
offsets.off_acc_z = 0x10;
586+
offsets.off_gyro_x = 0x10;
587+
offsets.off_gyro_y = 0x10;
588+
offsets.off_gyro_z = 0x10;
589+
590+
rslt = bmi160_set_offsets(&foc_conf, &offsets, sen);
591+
592+
/* After offset setting the data read from the
593+
* sensor will have the corresponding offset */
594+
595+
return rslt;
596+
}
597+
```
598+
599+
#### Example for updating the offsets into NVM
600+
> The offsets set by this method will be present in NVM and will be
601+
> restored on POR/soft-reset
602+
```
603+
/* An example for updating manual offsets to sensor */
604+
int8_t write_offsets_nvm(struct bmi160_dev *dev)
605+
{
606+
int8_t rslt = 0;
607+
/* FOC configuration structure */
608+
struct bmi160_foc_conf foc_conf;
609+
/* Structure to store the offsets */
610+
struct bmi160_offsets offsets;
611+
612+
/* Enable offset update for accel */
613+
foc_conf.acc_off_en = BMI160_ENABLE;
614+
615+
/* Enable offset update for gyro */
616+
foc_conf.gyro_off_en = BMI160_ENABLE;
617+
618+
/* offset values set by user as per their reference
619+
* Resolution of accel = 3.9mg/LSB
620+
* Resolution of gyro = (0.061degrees/second)/LSB */
621+
offsets.off_acc_x = 10;
622+
offsets.off_acc_y = -15;
623+
offsets.off_acc_z = 20;
624+
offsets.off_gyro_x = 30;
625+
offsets.off_gyro_y = -35;
626+
offsets.off_gyro_z = -40;
627+
628+
rslt = bmi160_set_offsets(&foc_conf, &offsets, sen);
629+
630+
if (rslt == BMI160_OK) {
631+
/* Update the NVM */
632+
rslt = bmi160_update_nvm(dev);
633+
}
634+
635+
/* After this procedure the offsets are written to
636+
* NVM and restored on POR/soft-reset
637+
* The set values can be removed to ideal case by
638+
* invoking the following APIs
639+
* - bmi160_start_foc()
640+
* - bmi160_update_nvm()
641+
*/
642+
643+
return rslt;
644+
}
645+
```
646+
521647
## Copyright (C) 2016 - 2017 Bosch Sensortec GmbH

0 commit comments

Comments
 (0)