This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2650STK: Increasing Gyroscope sensor Resolution

Other Parts Discussed in Thread: CC2650STK, BLE-STACK

Hi,

I am trying to find out how to change the resolution of the gyroscope sensor in CC2650STK firmware source code. The default resolution is 250 degree/sec. But according to the datasheet of MPU-9250 sensor gyroscope resolution is programmable and it can be set up to 2000 degree/sec. The firmware source code has only the function to change the resolution of accelerometer sensor. However, I did not find any indication related to full scale range setting of gyroscope sensor.

I appreciate any help or suggestion.

Thanks,

Fazlay

  • Hi Fazlay,

    Please feel free to add gyroscope configuration function to your application. FYI, the register number for gyroscope configuration is 27 according to the MPU-9250 specification available at store.invensense.com/.../RM-MPU-9250A-00.pdf.

    - Cetri
  • Hi,

    I have added the some functions in sensor_mpu9250.c and sensor_mpu9250.h to set the resolution by referring to the accelerometer and https://e2e.ti.com/support/wireless_connectivity/f/538/t/423483  thread. I am using BLE-STACK version 2.1. Here is what I have changed:

    In sensor_mput9250.h I have added the following declaration:

    #define GYRO_RANGE_250DPS      0
    #define GYRO_RANGE_500DPS      1
    #define GYRO_RANGE_1000DPS     2
    #define GYRO_RANGE_2000DPS     3
    #define GYRO_RANGE_INVALID 0xFF
    
    
    bool sensorMpu9250GyroSetRange(uint8_t newRange);
    uint8_t sensorMpu9250GyroReadRange(void);

    In sensor_mpu9250.c I have added the above two functions and modified some existing function (modification to existing functions starts with //my change comments).

    
    
    bool sensorMpu9250Reset(void)
    {
      bool ret;
    
      // Make sure pin interrupt is disabled
      PIN_setInterrupt(hMpuPin, PIN_ID(Board_MPU_INT)|PIN_IRQ_DIS);
    
      accRange = ACC_RANGE_INVALID;
    
      //My Change
    
      gyroRange = GYRO_RANGE_INVALID;
    
      mpuConfig = 0;   // All axes off
      magStatus = 0;
    
      if (!SENSOR_SELECT())
      {
        return false;
      }
    
      // Device reset
      val = 0x80;
      sensorWriteReg(PWR_MGMT_1, &val, 1);
      SENSOR_DESELECT();
    
      delay_ms(100);
    
      ret = sensorMpu9250Test();
      if (ret)
      {
        // Initial configuration
        sensorMpu9250AccSetRange(ACC_RANGE_8G);
    
        //My Change
    
        sensorMpu9250GyroSetRange(GYRO_RANGE_2000DPS);
    
        sensorMagInit();
    
        // Power save
        sensorMpuSleep();
      }
    
      return ret;
    }
    



    /**************************************************************************************************
    * @fn          sensorMpu9250GyroReadRange
    *
    * @brief       Set the range of the gyroscope (added)
    *
    * @param       none
    *
    * @return      ange: GYRO_RANGE_250DPS, GYRO_RANGE_500DPS, GYRO_RANGE_1000DPS, GYRO_RANGE_2000DPS
    */
    uint8_t sensorMpu9250GyroReadRange(void)
    {
      // Apply the range
      SENSOR_SELECT();
      sensorReadReg(GYRO_CONFIG, &gyroRangeReg, 1);
      SENSOR_DESELECT();
    
      gyroRange = (gyroRangeReg>>3) & 3;
    
      return gyroRange;
    }
    
    
    /**************************************************************************************************
    * @fn          sensorMpu9250GyroSetRange
    *
    * @brief       Set the range of the gyroscope (added)
    *
    * @param       newRange: GYRO_RANGE_250DPS, ACC_RANGE_500DPS, ACC_RANGE_1000DPS, ACC_RANGE_2500DPS
    *
    * @return      true if write succeeded
    */
    bool sensorMpu9250GyroSetRange(uint8_t newRange)
    {
      bool success;
    
      if (newRange == gyroRange)
        return true;
    
      success = false;
    
      gyroRangeReg = (newRange << 3);
    
      // Apply the range
      SENSOR_SELECT();
      success = sensorWriteReg(GYRO_CONFIG, &gyroRangeReg, 1);
      SENSOR_DESELECT();
    
      if (success)
        gyroRange = newRange;
    
      return success;
    }

     

    float sensorMpu9250GyroConvert(int16_t data)
    {
            //My Change
    
            float v;
    	switch (gyroRange)
    	{
    	  case GYRO_RANGE_250DPS:
    		  //-- calculate rotation, unit deg/s, range -250, +250
    	    v = return (data * 1.0) / (65536 / 500);
    	    break;
    
    	  case GYRO_RANGE_500DPS:
    		  //-- calculate rotation, unit deg/s, range -500, +500
    	    v = return (data * 1.0) / (65536 / 1000);
    	    break;
    
    	  case GYRO_RANGE_1000DPS:
    		  //-- calculate rotation, unit deg/s, range -1000, +1000
    	   	v = return (data * 1.0) / (65536 / 2000);
    	    break;
    
    	  case GYRO_RANGE_2000DPS:
    		  //-- calculate rotation, unit deg/s, range -2000, +2000
    	    v = return (data * 1.0) / (65536 / 4000);
    	    break;
    	}
    	return v;
    
    }

    I built and compiled the above change and analyzed the data got from CC2650STK sensortag using my bike (Sensortag placed in bike paddle). I configured the gyroscope resolution to 2000 degree/sec. But when I analyzed the data I found the data change range (min and max value of each axis) is very small along 3 axis. For x axis changes between  -16.7266 to 21.1016, y axis changes between -4.6563 to 31.2031 and z axis changes between -132.8516 to 11.5781. I checked the data range using motionnode sensor (www.motionnode.com) using 2000 degree/s resolution setting and found that x and y axis value change between -500 to 800 and z axis value changes between -800 to +800.

    I am wondering whether I am missing something while adding and modifying the source code. I appreciate any help , suggestion and comments on my change.

    Another point, I saw the variable static uint16_t mpuConfig in SensorTag_Mov.c file. I saw it's bit 8-9 is for accelerometer range (2,4,8,16). I am wondering whether this variable has dedicated bit for gyroscope range like accelerometer range and also whether I have to touch this variable as well to set the gyroscope resolution.

    I appreciate any help , suggestion and comments on my change.

    Thanks,

    Fazlay

  • There is no support for Gyro resolution in the firmware as delivered, but the changes you have done seem reasonable. If you want to set the range from your BLE client you would have to add a two-bit field in mpuConfig, bits 10-15 are spare. Please note that the conversion algorithm is for refrence only, it must be applied on the cleint side (Android/iOs or Windows). You may however experiment with it in SensorTag_Mov.c to "emulate" the default resolution.