I keep starting this last few days and then as I type think of code to edit - then not getting back with a good answer to post . . . The last diversion had me wonder how long the IMU processing is taking - and if the case of "if (newData == 1)" on the imu - is that when I see anomalies on my GPS Rx timing :: Answer looks to be YES! WIP ... more below . . .
Brian: Finally put a global for debug tracking on error for requested 'srd' of 49 or 199 in ...\libraries\MPU9250\MPU9250.cpp :: setSrd():
Code:
if(writeAK8963Register(AK8963_CNTL1,AK8963_PWR_DOWN) < 0){
return ErrSS=-2;
}
This is after this returns without error:
Code:
/* setting the sample rate divider */
if(writeRegister(SMPDIV,srd) < 0){ // setting the sample rate divider
At a glance I don't see an obvious problem/cause or solution to this? I added a delay(100) [ and 400 or 700 ] before that to no effect as was done on other calls. In the end the srd change is effective - but this intermediate error prevents recognition of that. Is there a limit on the requested SRD? Or reason these calls should fail? During calibration srd=19 completes with no problem but 49 and 199 fail based on the error detected - though the IMU changes. Note: These were found in that the early out on error breaks my effort to fix calibration value reset as stored in the class variables. I am running at 180 MHz so should not be a IMU issues with F_BUS - though I did just bump that to 90 MHz @ 180 and still error -2.
@mjs - yeah we should make a yourNAMEhere_HAL.H file or something for each of us outside the project to #ifdef exclude the local #ifdef's. Glad the #ifdef's got made at the top - I had to add some lines for my ALT pin i2c ... now Don has gone and rev'd the code - while I got distracted on the MPU9250 code and LIFE.
Don: I'll merge my changes into posted V10 filter code - I see changes to main sketch, globals.h, and the serialPort.ino and see if I can't finally get that worth posting. Wondering how UTC time helps - and if it could supersede value of regular local clocking? Since all samples are taken locally and time relative to each other. Other than setting the Teensy RTC now and then. The uBlox nano value only shows the samples were taken - before the calculations - relative to an arbitrary Earth second - before a lengthy 2.2 ms data transfer.
Finding some time offset anomalies from detection of the Rx isr() to the end of the message being 2.8ms instead of 2.2 ms. Not sure if this is stuttering on the uBlox - or isr() detect, some short runs show 1% discrepancy - other longer runs show it 0.4%. Perhaps this happens when IMU data is calculating and the GPD receive is delayed? It seems to happen in small groups of ~5 times in ~10 GPS messages.
mjs: Given the new info 'open to this post' I can see how TThreads could add value to this! And it should be simple to make multiple threads pull their own data - and submit a TIMED RECORD to a queue. Then other processing thread(s) can pull the data RECORDS and process them. In this case the GPS isr() could submit a PENDING RECORD that could HALT imu processing received after that until the GPS complete RECORD is received.
On the current run of 1750 seconds and 8750 GPS messages I have detected 37 GPS messages completing too long after the Start Bit was detected, and they can happen in groups of ~6.
It seems an IMU Calc can take 659 to 780+ micros on the default Filter_V9 code running at 180 MHz. My Rx timing aberrations happen when they are on the longer side (754+ micros). With GPS messages on 5 Hz but stretching 2.2 ms - if the faster Hz imu update cycle overlaps the start to end time gets out of wack and that is what I was detecting and being compulsive about - when a 2.2ms xfer takes 2.8ms. I correctly only ever trigger one isr() per GPS msg, but sometimes the finish was too far away to seem kosher so it seemed there was a Start bit detection error on the isr()!
TThreads would jump from arbitrarily long imu/filter updates harmlessly - ping the GPS Serial and then yield - perhaps with completed data record. For FIFO xfer and uBlox message read/convert uses probably net 1ms per second of CPU time - but not getting the messages in a timely fashion is uncalled for.