{"action":"created","issue":{"url":"https://api.github.com/repos/kriswiner/MPU-9250/issues/96","repository_url":"https://api.github.com/repos/kriswiner/MPU-9250","labels_url":"https://api.github.com/repos/kriswiner/MPU-9250/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/kriswiner/MPU-9250/issues/96/comments","events_url":"https://api.github.com/repos/kriswiner/MPU-9250/issues/96/events","html_url":"https://github.com/kriswiner/MPU-9250/issues/96","id":193502823,"number":96,"title":"Port for PIC24 and problems","user":{"login":"TopperBG","id":23097319,"avatar_url":"https://avatars.githubusercontent.com/u/23097319?v=3","gravatar_id":"","url":"https://api.github.com/users/TopperBG","html_url":"https://github.com/TopperBG","followers_url":"https://api.github.com/users/TopperBG/followers","following_url":"https://api.github.com/users/TopperBG/following{/other_user}","gists_url":"https://api.github.com/users/TopperBG/gists{/gist_id}","starred_url":"https://api.github.com/users/TopperBG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TopperBG/subscriptions","organizations_url":"https://api.github.com/users/TopperBG/orgs","repos_url":"https://api.github.com/users/TopperBG/repos","events_url":"https://api.github.com/users/TopperBG/events{/privacy}","received_events_url":"https://api.github.com/users/TopperBG/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2016-12-05T13:56:43Z","updated_at":"2016-12-16T16:51:04Z","closed_at":null,"body":"First thanks for hard work.\r\n\r\nI've try to port whole library to PIC24 and face some problems.\r\nBased on https://github.com/kriswiner/MPU-9250/blob/dea8453be4abd6c94612a13a2ddb5db184fed7cb/MPU9250BasicAHRS_t3.ino\r\nBoard is that https://www.seeedstudio.com/Grove-IMU-9DOF-v2.0-p-2400.html\r\nSensors response to Who_I_Am propperly.\r\nMPU init pass fine.\r\nStartup procedure is:\r\n```\r\nvoid Setup_MPU9250(){\r\n   fprintf(PC,\"\\n   *** Setup MPU 9250 unit ***\\n\\r\");       \r\n    if (MPU9250WIA()) {                      \r\n         fprintf(PC,\"\\n Reset MPU9250\");         \r\n         resetMPU9250();\r\n         fprintf(PC,\"\\n Calibration MPU start\");\r\n         calibrateMPU9250(gyroBias, accelBias);  // Calibrate gyro and accelerometers, load biases in bias registers\r\n         fprintf(PC,\"\\n accel biases (mg) %f %f %f\",1000.*accelBias[0],1000.*accelBias[1],1000.*accelBias[2]);\r\n         fprintf(PC,\"\\n gyro biases (mg) %f %f %f\",gyroBias[0],gyroBias[1],gyroBias[2]);  \r\n\r\n         fprintf(PC,\"\\n Init MPU9250\");\r\n        init_MPU9250(); \r\n   }                                         \r\n   if (CompassWIA()) {                               \r\n         fprintf(PC,\"\\n Init AK8963\");      \r\n         InitAK8963(magCalibration);        \r\n         fprintf(PC,\"\\n Calibrate AK8963\");      \r\n         MagCalMPU9250(magBias,magScale);\r\n         fprintf(PC,\"\\n AK8963 mag biases (mG) %f %f %f\",magBias[0],magBias[1],magBias[2]);\r\n         fprintf(PC,\"\\n AK8963 mag scale (mG) %f %f %f\",magScale[0],magScale[1],magScale[2]);  \r\n   }                                                             \r\n   fprintf(PC,\"\\n   *** End MPU 9250 setup ***\\n\\r\");\r\n} \r\n\r\n```\r\n1.First problem is calibration function according the code. After enable and quick disable FIFO (even within 1ms) the FIFO Counter FIFO_COUNTH is 65535 and samples to average are 5461. Doesn't change with manipulate time interval between: \r\n\r\n> i2c_WriteByte_MPU9250(MPU9250_ADDRESS, USER_CTRL, 0x40);   // Enable FIFO  \r\n> i2c_WriteByte_MPU9250(MPU9250_ADDRESS, FIFO_EN, 0x78);     // Enable gyro and accelerometer sensors for FIFO  (max size 512 bytes in MPU-9150)\r\n\r\nand\r\n\r\n> // At end of sample accumulation, turn off FIFO sensor read\r\n> i2c_WriteByte_MPU9250(MPU9250_ADDRESS, FIFO_EN, 0x00);        // Disable gyro and accelerometer sensors for FIFO\r\n> i2c_ReadByteS_MPU9250(MPU9250_ADDRESS, FIFO_COUNTH, 2, &data[0]); // read FIFO sample count \r\n\r\n \r\nSo I've put hardcoded packet_counter =40;\r\nSee results below\r\n\r\n 2.Second problems is ReadMagData. \r\nWhen started CalibrateMag and must be read 128 samples from Mag, first was read after that ST1 stays 0. Mode for Mag is single mode (0001)\r\n\r\n\r\nHere is output with heavy debug:\r\n\r\n>  *** Setup MPU 9250 unit ***\r\n> I AM 0x71\r\n>  MPU9250 is online...\r\n> \r\n>  Reset MPU9250\r\n>  Init MPU9250\r\n>Calibration MPU start\r\n> Calibration MPU ...\r\n> Calibration MPU 5461 samples for avrg. FIFO counter is 65535d \r\n> #0  #1  #2  #3  #4  #5  #6  #7  #8  #9  #10  #11  #12  #13  #14  #15  #16  #17  #18  #19  #20  #21  #22  >#23  #24  #25  #26  #27  #28  #29  #30  #31  #32  #33  #34  #35  #36  #37  #38  #39 \r\n> accel biases (mg) 0.00 0.00 1000.00\r\n> gyro biases (mg) 0.00 0.00 0.00\r\n>\r\n> I AM 0x48\r\n>  Compass is online...\r\n> \r\n>  Init AK8963\r\n> ASAX raw data read \r\n> X-Axis sensitivity adjustment value 1.16 \r\n> Y-Axis sensitivity adjustment value 1.16 \r\n> Z-Axis sensitivity adjustment value 1.12 \r\n> magCalibration 1066696704 1066729472 1066369024 \r\n> \r\n>    *** End MPU 9250 setup ***\r\n>    >>> MainLoop <<< \r\n> \r\n>  >>> ReadMagData AK8963_ST1 ST1=1...\r\n>  >>> Get 6 raw mag data \r\n> MagRaw data: mx 0 my 0 mz 0\r\n>  X-acceleration: 9.27 mg  Y-acceleration: 14.40 mg  Z-acceleration: 1030.27 mg \r\n>  X-gyro rate: 71.64 degrees/sec  Y-gyro rate: 82.92 degrees/sec  Z-gyro rate: 91.39 degrees/sec\r\n>  X-mag field: -463 mG  Y-mag field: -120 mG  Z-mag field: -118 mG \r\n> Temperature is 27.70 degrees C\r\n>  q0 = 1.00 qx = 0.00 qy = 0.00 qz = 0.00 \r\n> \r\n>    Yaw -13.80, Pitch 0.00, Roll 0.00: \r\n> \r\n> \r\n>  >>> ReadMagData AK8963_ST1 ST1=0...\r\n> \r\n>  >>> ReadMagData AK8963_ST1 ST1=0...\r\n> \r\n>  >>> ReadMagData AK8963_ST1 ST1=0...\r\n> \r\n>  >>> ReadMagData AK8963_ST1 ST1=0...\r\n\r\n\r\nAny ideas ?\r\n"},"comment":{"url":"https://api.github.com/repos/kriswiner/MPU-9250/issues/comments/267638884","html_url":"https://github.com/kriswiner/MPU-9250/issues/96#issuecomment-267638884","issue_url":"https://api.github.com/repos/kriswiner/MPU-9250/issues/96","id":267638884,"user":{"login":"kriswiner","id":6698410,"avatar_url":"https://avatars.githubusercontent.com/u/6698410?v=3","gravatar_id":"","url":"https://api.github.com/users/kriswiner","html_url":"https://github.com/kriswiner","followers_url":"https://api.github.com/users/kriswiner/followers","following_url":"https://api.github.com/users/kriswiner/following{/other_user}","gists_url":"https://api.github.com/users/kriswiner/gists{/gist_id}","starred_url":"https://api.github.com/users/kriswiner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kriswiner/subscriptions","organizations_url":"https://api.github.com/users/kriswiner/orgs","repos_url":"https://api.github.com/users/kriswiner/repos","events_url":"https://api.github.com/users/kriswiner/events{/privacy}","received_events_url":"https://api.github.com/users/kriswiner/received_events","type":"User","site_admin":false},"created_at":"2016-12-16T16:51:03Z","updated_at":"2016-12-16T16:51:03Z","body":"The data from this sensor (like most) comes in the form of bytes. The bytes are in two's complement form, that is how negative integers are carried in byte form. Uusally tou can convert the bytes to the proper integer number by type casting like this:\r\n\r\n(int16_t) MSBbyte << 8 | LSBbyte\r\n\r\nBut not all MCUs support this. So check the raw bytes coming from the data registers and verfiy that when the integers are supposed to be negative, that they are. Also, not all MCUs define int the same way, so if you are using ing or long instead of int16_t, for example, you could be truncating the integers, etc.\r\n\r\nIn any case, until you can get sensible results from the self test, everything else is a waste of time."}}
{"actor":{"display_login":"kriswiner"}}