Home        Store        Docs        Blog

MS5837 fast sampling


(Daniel) #1

Hi,

I’m having a strange problem with the pressure sensor and I’m wondering if anyone has seen anything similar. Basically, whenever I sample the MS5837 at a “high” rate (10Hz), the readings start going haywire.

After it starts returning bogus data, I can reset, power down, change sampling rate, or whatever, and it is still bogus. However, if I only sample slowly, I can watch as the values for both temperature and pressure slowly drift back to normal values. I’ve got a logic analyzer hooked up to the I2C bus and have confirmed its not a firmware glitch in the calibration code.

Anyone else see this behavior? I’m also curious to see if other folks are successfully using this at sampling rates > 10Hz.

Attached graph shows what I mean. Just left the sensor alone and it starts drifting towards bogus values. Eventually, I think a bug in my code caused a reduced sampling rate, and the values then trend back towards the expected 1000 mbar / 22C range.



(Jacob) #2

This is almost certainly a software issue, or an issue with the connections. ArduSub samples much higher than 10Hz. Can you please post your code? Make sure that you have very good connections, how do you have the sensor wired?

-Jacob


(Daniel) #3

Thanks for the feedback on the sampling rate, I’m tempted to just get another sensor to test with.

The sensor is wired with a clean 3.3V source and uses 3.3V logic on the SDA and SCL lines.

I’m using the BlueRobotics_MS5837 arduino library with some slight modifications. I’ve changed the OSR from 8192 to 2048 for both temperature and pressure, and reduced the delay between the conversion requests from 20ms to 5ms. I’ve also fixed the 0x00FF0 bug in the crc4 function.

To rule out bad math on the uC side, I’ve logged the raw D1 and D2 values and performed some hand calculations. I’ve also confirmed that the uC is reading in the correct values by hooking up a logic analyzer and watching the ADC read responses. Here’s some raw values while the sensor is trending back towards expected pressure/temperature (for reference, a ‘good’ reading should be about D1: 4162862 D2: 6824718, which is more in line with the example values from the spec sheet)…

D1: 88030 D2: 5961574
D1: 98238 D2: 5963270
D1: 109590 D2: 5964678
D1: 119918 D2: 5965918
D1: 130838 D2: 5967334
D1: 140734 D2: 5968718
D1: 151742 D2: 5970086
D1: 162102 D2: 5971542
D1: 172702 D2: 5972990
D1: 182798 D2: 5974182
D1: 193894 D2: 5975758
D1: 204190 D2: 5976966
D1: 214558 D2: 5978454
D1: 224662 D2: 5979686
D1: 234990 D2: 5981270
D1: 245710 D2: 5982854
D1: 255494 D2: 5984126
D1: 265406 D2: 5985406
D1: 276366 D2: 5986998
D1: 286118 D2: 5988374
D1: 296718 D2: 5989686
D1: 306102 D2: 5990910
D1: 316662 D2: 5992414
D1: 326246 D2: 5993654
D1: 336558 D2: 5995134
D1: 346422 D2: 5996638
D1: 356454 D2: 5997982
D1: 366174 D2: 5999326
D1: 376478 D2: 6000782
D1: 386014 D2: 6002126
D1: 396502 D2: 6003638
D1: 405742 D2: 6005142
D1: 415862 D2: 6006454
D1: 425486 D2: 6007622
D1: 435102 D2: 6009126
D1: 444934 D2: 6010718
D1: 454638 D2: 6011726
D1: 464358 D2: 6013062
D1: 473990 D2: 6014558
D1: 483646 D2: 6015766
D1: 493662 D2: 6017494
D1: 503062 D2: 6018854
D1: 512198 D2: 6020334
D1: 521630 D2: 6021790
D1: 531494 D2: 6022814
D1: 540694 D2: 6024406
D1: 550286 D2: 6025822
D1: 559190 D2: 6027126
D1: 568782 D2: 6028494
D1: 578206 D2: 6029958
D1: 587142 D2: 6031254
D1: 596790 D2: 6032806
D1: 605686 D2: 6034246
D1: 614686 D2: 6035526
D1: 624206 D2: 6036750
D1: 633350 D2: 6038326
D1: 642414 D2: 6039694
D1: 651798 D2: 6041246
D1: 660286 D2: 6042454
D1: 669902 D2: 6043902
D1: 678814 D2: 6045334
D1: 688606 D2: 6046902
D1: 697110 D2: 6048014
D1: 705974 D2: 6049534
D1: 714846 D2: 6050814
D1: 724014 D2: 6052310
D1: 733062 D2: 6053742
D1: 742086 D2: 6055046
D1: 750998 D2: 6056422
D1: 759646 D2: 6057902
D1: 768766 D2: 6059270
D1: 777254 D2: 6060662
D1: 786222 D2: 6062086
D1: 794982 D2: 6063414
D1: 803702 D2: 6065014
D1: 812182 D2: 6066262
D1: 821166 D2: 6067534
D1: 829382 D2: 6068846
D1: 838766 D2: 6070078
D1: 846422 D2: 6071222
D1: 855222 D2: 6072926
D1: 863854 D2: 6074206
D1: 872198 D2: 6075606
D1: 880558 D2: 6076870
D1: 889158 D2: 6078246
D1: 898014 D2: 6079518
D1: 906606 D2: 6081070
D1: 914990 D2: 6082502
D1: 923358 D2: 6083926
D1: 931982 D2: 6085030
D1: 940078 D2: 6086470
D1: 948358 D2: 6087702
D1: 956958 D2: 6089006
D1: 965094 D2: 6090510
D1: 973038 D2: 6091958
D1: 981806 D2: 6093038
D1: 989782 D2: 6094662
D1: 998638 D2: 6095790
D1: 1006342 D2: 6097302
D1: 1014526 D2: 6098678
D1: 1022710 D2: 6100214
D1: 1030918 D2: 6101254
D1: 1039278 D2: 6102998
D1: 1047374 D2: 6104390
D1: 1055638 D2: 6105470
D1: 1063694 D2: 6106766
D1: 1071598 D2: 6108230
D1: 1080094 D2: 6109510
D1: 1087766 D2: 6110710
D1: 1094990 D2: 6112134
D1: 1103006 D2: 6113414
D1: 1110806 D2: 6114750
D1: 1119262 D2: 6116374
D1: 1127014 D2: 6117710
D1: 1135654 D2: 6119158
D1: 1143126 D2: 6120262
D1: 1151150 D2: 6121774
D1: 1158534 D2: 6123166
D1: 1166838 D2: 6124462
D1: 1174750 D2: 6126014
D1: 1182230 D2: 6127318
D1: 1190526 D2: 6128606
D1: 1197966 D2: 6129766
D1: 1205870 D2: 6131422
D1: 1213662 D2: 6132478
D1: 1221294 D2: 6134014
D1: 1228926 D2: 6135382
D1: 1236358 D2: 6136686
D1: 1244294 D2: 6137974
D1: 1252118 D2: 6139214


(Jacob) #4

Take note of page 11 in the datasheet. It is a little bit vague, but it does state:
<div data-canvas-width=“787.7350000000002”>‘If the ADC read command is sent during conversion the result will be 0, the conversion will not stop and the final result will be wrong. Conversion sequence sent during the already started conversion process will yield incorrect result as well’</div>
<div data-canvas-width=“787.7350000000002”></div>
<div data-canvas-width=“787.7350000000002”>What rate are you sending the ADC read command at? Although sending the conversion command at 5ms seems to be within spec of the max conversion time (4.54 ms) with OSR at 2048, you are not leaving much overhead, less than 500 microseconds. With OSR 8192 and conversion command rate of 20ms, there is more that 2ms delay above the specified conversion time. It is quite possible that your delay() is rounding to the nearest millisecond and you actually end up waiting closer to 4ms. Try increasing your delay() command to 6 or 7 ms, or use delayMicroseconds(5000) for finer resolution timing.</div>
<div data-canvas-width=“787.7350000000002”></div>
<div data-canvas-width=“787.7350000000002”>-Jacob</div>


(Daniel) #5

Excellent point about the delay, and I think you are correct that the delay() implementation can allow for closer to 4ms of delay. I’ll have to experiment with that and will also try reducing OSR to 256.

And I did catch that in the spec- I interpreted that as returning a zero byte when doing the ADC read, which is not what I’m seeing. I’ll run some experiments to see if I can clear up how that behaves w.r.t. returning zeroes or just incorrect data.

 

The BlueRobotics library is set up like:

Start D1 Conversion

Wait 20ms (or in my case 5ms)

Read ADC

Start D2 Conversion

Wait 20ms (5ms for me)

Read ADC

Run through the calculation code w/ the calibration coefficients read in at startup

 

I took a peak at the ArduSub code and got some ideas for edits from it. I’ve altered my code to only read the temperature once every 5 reads of the pressure.

 

I think I’ll also grab a couple of raw sensors from digikey and see if they behave any differently than this one I’ve got, since I seem to be unique in having this issue.