Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMA423 anymotion always firing

    BMA423 anymotion always firing

    mcas
    New Poster

    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);

    }

    3 REPLIES 3

    Vincent
    Community Moderator
    Community Moderator

    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. 

     

    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);

    Vincent
    Community Moderator
    Community Moderator

    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.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist