Barometer MS5611 accuracy improvement

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
NotungX
Posts: 3
Joined: Mon Oct 29, 2012 9:41 am

Barometer MS5611 accuracy improvement

Post by NotungX »

I was just playing around with my MS5611 sensor and in the specs I found room for improvement in the pressure and temperature calculations. The specs of my MS5611-01BA03 from measurement specialities says the following:

At OSR 4096 the ADC gives an accuracy of 0.012 mbar
At OSR 4096 the ADC gives an accuracy of 0.002 ºC

With the provided calculations the TEMP and P (pressure) variables are defined as int32 and you have to divide the final result by 100 to get the temperature and pressure. In this case the accuracy that we get is 0.01 mbar and 0.01 ºC, so we are not really using the whole potential of the sensor, especially after doing some calculations when the decimals were truncated.

I tried to change the variables TEMP and P to float and I observed a big improvement in accuracy.
The code in Sensors.ino for this variables are like this:

float temperature = 2000 + dT * (ms561101ba_ctx.c[6] / (float) (1 >>23));
float pressure = (float) (ms561101ba_ctx.up.val * sens - off * (1 << 21)) / ((int64_t) 1 << 36);

Of course we have to divde these values after by 100 to have the appropiate measurement.

Give it a try and let me know!!!

Cheers,

NotungX

Cheers

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Barometer MS5611 accuracy improvement

Post by copterrichie »

What version or Development R of the MWC are you using?

KaiK
Posts: 58
Joined: Thu Jul 28, 2011 8:32 pm
Contact:

AW: Barometer MS5611 accuracy improvement

Post by KaiK »

Did you check the noise of signal?

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Barometer MS5611 accuracy improvement

Post by Hamburger »

Could you please provide a unified diff? That would make testing your changes a lot easier and help avoid discrepancies
Thanks.

NotungX
Posts: 3
Joined: Mon Oct 29, 2012 9:41 am

Re: Barometer MS5611 accuracy improvement

Post by NotungX »

Actually I was testing the sensor for my own purposes. I don't have a multiwii device ready to test (yet). However as I noticed that the Multiwii code is using the calculations provided by the specs I decided to post here as you could benefit from the improvements.

I am attaching here a patch of Sensors.ino from the 2.1 release version that I downloaded from the website (MultiWii_2_1.zip). You can apply the patch to the sensors file with the command:

Code: Select all

patch < Sensors.patch


Please let me know if it works for you or if you have any other question.

NotungX
Attachments
Sensors_patch.zip
Increased accuracy patch for Sensors.ino (multiwii release 2.1)
(880 Bytes) Downloaded 222 times

scrat
Posts: 925
Joined: Mon Oct 15, 2012 9:47 am
Location: Slovenia

Re: Barometer MS5611 accuracy improvement

Post by scrat »

Can't wait for dev version

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Barometer MS5611 accuracy improvement

Post by Hamburger »

anyone tested this patch already?
I am en route to vacation so testing will have to wait another 2 weeks.

User avatar
Crashpilot1000
Posts: 631
Joined: Tue Apr 03, 2012 7:38 pm

Re: Barometer MS5611 accuracy improvement

Post by Crashpilot1000 »

I can not apply the patch because i don't have linux and don't want to install extra BS. Why not simply post the changed code here, so the DIFF LOVERS can Diff on their own??? Would be too simple. Anyway, i implemented the patch by hand and it doesn't work at all. Probably a a error on my side but diff doesn't make sense at all.

Imen
Posts: 20
Joined: Thu Sep 27, 2012 5:11 pm

Re: Barometer MS5611 accuracy improvement

Post by Imen »

Hi NotungX, could this improvement applied to BMP085 ? :)

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Barometer MS5611 accuracy improvement

Post by timecop »

Crashpilot1000 wrote:I can not apply the patch because i don't have linux and don't want to install extra BS. Why not simply post the changed code here, so the DIFF LOVERS can Diff on their own??? Would be too simple. Anyway, i implemented the patch by hand and it doesn't work at all. Probably a a error on my side but diff doesn't make sense at all.


haha, lunix lovers?! I despise lunix and patch files are 100000x more readable than just posting code!

in patch file, - lines are removed and + lines are added. Lines without a + or - are context, and are unchanged. Real simple! You can see exactly what changed, plus code around it to help orient.
basically all he did was make 'pressure' and 'delt' a float,
then replaced calculations with bitshifts with proper divides.

Code: Select all

-static int32_t  pressure;
+static float pressure;

find line "static int32_t pressure", replace int32_t with float.
etc.

This is really easy stuff.

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Barometer MS5611 accuracy improvement

Post by Hamburger »

Crashpilot1000 wrote:I can not apply the patch because i don't have linux and don't want to install extra BS.

no need for that. Try WinMerge (and/or TortoiseMerge). Some of the good unix stuff makes it into the win world :)
PS: all hearsay on my part; I do not use win* as dev platform. Also, kdiff3 for win* gets active development is what I hear.

NotungX
Posts: 3
Joined: Mon Oct 29, 2012 9:41 am

Re: Barometer MS5611 accuracy improvement

Post by NotungX »

Finally after some more tests I have to say that the improvement is basically for the temp measurements. Above 20ºC The noisy readings from the pressure sensor mask the accuracy improvements. So although there is a more precise reading, it does not seem to affect the final pressure value.

However under 20ºC the temperature readings is used for some calculations to re-adjust the pressure and it could be more useful. I have some charts that I generated showing you these conlusions. I will share them here tomorrow as it's getting a bit too late for me.

I will post as well the Sensors.ino for non-patching people ;-)

User avatar
Leo
Posts: 372
Joined: Wed Sep 17, 2014 7:01 am
Location: Germany
Contact:

Re: Barometer MS5611 accuracy improvement

Post by Leo »

Old thread, I know but I was curious because float is used in the present 2.3 dev version.

I did a comparison with integer and float using my own MS5611 code with these results:

Image

Alt hold should be a bit steadier with integer.

Post Reply