05-14-2020 12:30 PM - edited 05-14-2020 12:50 PM
Hi,
I am trying to get the following features working:
- step counter
- double tap
- motion sensor (when accel. any axis exceeds limit trigger interrupt, eg "I am fallen down")
With my code below (tests for BMA_OK removed) I get the double tap interrupt and I can read the steps,
but I get an anymotion interrupt every time I move the device - even slightly - so it seems that setting the sensitivity fails and the trigger threshold seems to be set extremely low.
I would really be grateful if someone could point out what I am doing wrong!
Many thanks in advance!
========================== CODE ==========================
// accellerator setup
void accellerator_setup( int reset_level )
{
i2c = new I2CBus();
uint16_t rslt = BMA4_OK;
struct bma4_int_pin_config int_config;
bma423.dev_addr = BMA4_I2C_ADDR_PRIMARY;
bma423.interface = BMA4_I2C_INTERFACE;
bma423.bus_read = _i2c_read;
bma423.bus_write = _i2c_write;
bma423.delay = delay;
bma423.read_write_len = 8;
bma423.resolution = 12;
bma423.feature_len = BMA423_FEATURE_SIZE;
rslt = bma423_init(&bma423);
rslt |= bma4_set_advance_power_save(BMA4_ENABLE, &bma423);
// Wait for sensor time synchronization. Refer the data-sheet for more information
delay(5);
rslt = bma423_write_config_file(&bma423);
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma423);
struct bma4_accel_config accel_conf;
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_1600HZ;
accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
accel_conf.range = BMA4_ACCEL_RANGE_2G;
accel_conf.perf_mode = BMA4_CONTINUOUS_MODE;
rslt |= bma4_set_accel_config(&accel_conf, &bma423);
rslt |= bma423_feature_enable(BMA423_STEP_CNTR, BMA4_ENABLE, &bma423);
rslt |= bma423_reset_step_counter(&bma423); // must be called once feature is enabled otherwise will not work
struct bma423_anymotion_config anymotion_conf;
anymotion_conf.threshold = 0x200; // 0xAA 83mg; 0x400 500g;
anymotion_conf.duration = 5; // X*20ms
anymotion_conf.nomotion_sel = 0; // 0 Anymotion, 1 Nomotion
rslt |= bma423_set_any_motion_config(&anymotion_conf, &bma423);
rslt |= bma423_anymotion_enable_axis(BMA423_ALL_AXIS_EN, &bma423);
rslt |= bma423_feature_enable(BMA423_ANY_MOTION, BMA4_ENABLE, &bma423);
// double tap detection (should be on by default)
rslt |= bma423_feature_enable(BMA423_WAKEUP, BMA4_ENABLE, &bma423);
rslt |= bma423_tap_selection(0, &bma423); // 0 = double tap, 1 = single tap
rslt |= bma423_wakeup_set_sensitivity(7, &bma423); // 0 = most sensitive, 7 = least sensitive
rslt |= bma4_set_interrupt_mode(BMA4_LATCH_MODE, &bma423);
rslt |= bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ANY_NO_MOTION_INT | BMA423_WAKEUP_INT, BMA4_ENABLE, &bma423); // anymotion and double tap
// need verification for interrupt functionality
int_config.edge_ctrl = BMA4_LEVEL_TRIGGER;
int_config.lvl = BMA4_ACTIVE_HIGH; // this must be hogh as the main code triggers on HIGH on ext1 bits
int_config.od = BMA4_PUSH_PULL;
int_config.output_en = BMA4_OUTPUT_ENABLE;
int_config.input_en = BMA4_INPUT_DISABLE;
rslt |= bma4_set_int_pin_config(&int_config, BMA4_INTR1_MAP, &bma423);
}
05-15-2020 01:17 AM
Here you can also try to increase the duration of any motion which means you need to keep movement for certain time to trigger the interrupt.
05-18-2020 03:27 PM
Thanks Vincent!
I've managed to get to behave normally by using the newest libraries from github instead of the rather old ones given to me by the hw manufacturer of the device I'm programming.
two questions still:
- is it normal that the config write moved from 15secs to about 3mins?
- I cannot seem to be able to set the sensitivity right (see short code below) anymotion triggers way too easily. If I want to have an anymotion trigger on "I am fallen on the floor" which values do you recommend instead of the ones I am using below?
Thanks a lot again!
CODE SNIPPET
==============
struct bma4_accel_config accel_conf;
accel_conf.odr = BMA4_OUTPUT_DATA_RATE_1600HZ;
accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
accel_conf.range = BMA4_ACCEL_RANGE_16G;
accel_conf.perf_mode = BMA4_CONTINUOUS_MODE;
rslt |= bma4_set_accel_config(&accel_conf, &bma423);
struct bma423_any_no_mot_config anymotion_conf;
anymotion_conf.threshold = 0x666; // 0xAA(170) 83mg; 0x400(1024) 500g;
anymotion_conf.duration = 80; // X*20ms
anymotion_conf.axes_en = BMA423_EN_ALL_AXIS;
rslt |= bma423_set_any_mot_config(&anymotion_conf, &bma423);
06-06-2020 01:24 AM
1. the size of configure string is about 6KB. So even with 100KHz I2C bus speed, the write of ths string will not take 3 mins. it is bit too long.
2. The suitable setting can only be found during testing based on the device. But i can suggest you to further increase the duration and also the threshold then find a balance of them.