Problem in calibrating mpu6050.

Hello,
I am suffering with a problem with my mpu6050.
I am using motion apps library and I calibrated it with IMU zero example.
But the problem is that when I used those offsets though the sensor was good in rest but when i moved it,the values go in opposite direction and then comes back to proper direction
Even when I place it on flat surface values takes time to get to zero.
However with previous offsets though the zero error was there it shows no problem.
I will be thankful if you help me out.

I use this code for calibration:
(See attached)

I also provided you with the base code I use for all my MPU6050 projects.

This array holds my offsets I get from my calibration routine

// supply your own gyro offsets here, scaled for min sensitivity use MPU6050_calibration.ino
//                       XA      YA      ZA      XG      YG      ZG
int MPUOffsets[6] = {    2471,   -563,   690,   66,     -29,     39};

this inserts the offsets into the proper memory locations on the MPu6050

  mpu.setXAccelOffset(MPUOffsets[0]);
  mpu.setYAccelOffset(MPUOffsets[1]);
  mpu.setZAccelOffset(MPUOffsets[2]);
  mpu.setXGyroOffset(MPUOffsets[3]);
  mpu.setYGyroOffset(MPUOffsets[4]);
  mpu.setZGyroOffset(MPUOffsets[5]);

Z

MPU6050_calibration.ino (7.64 KB)

MPU6050_Latest_code.ino (7.95 KB)