MPL115A2 Coefficients

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MPL115A2 Coefficients

Jump to solution
4,409 Views
beng_
Contributor III

I've just started experimenting with the MPL115A2 Digital Barometer.

Maybe I’m having a bad day – but I can’t understand how to convert the Coefficient integers / binary values into numbers.

The data sheet doesn’t seem to make sense. For example a0 is defined as

a0 Signed, Integer Bits = 12, Fractional Bits = 3 : Coeff a0 = S I11 I10 I9 I8 I7 I6 I5 I4 I3 I2 I1 I0 . F2 F1 F0

Later the data sheet uses the example a0 = 0x3ECE = 2009.75

Maskign out - bits I11 to I0 gives 2009 - but the last 3 bits (the fractional bits) are 0x06 - I can't see how that taken to be 0.75?

Are there any examples of how to take these Coefficients in binary/hex form and convert them into actual numbers?

Labels (1)
Tags (2)
1 Solution
4,238 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Ben,

As for the fractional part, F2 = 0.5, F1 = 0.25 and F0 = 0.125.

Considering our example, the fractional part is 0b110 = 1 x 0.5 + 1 x 0.25 + 0 x 0.125 = 0.75

You may find useful David's example project, have a look at MPL115A1.c file.

I hope it helps.

Best regards,

Tomas

View solution in original post

4 Replies
4,239 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Ben,

As for the fractional part, F2 = 0.5, F1 = 0.25 and F0 = 0.125.

Considering our example, the fractional part is 0b110 = 1 x 0.5 + 1 x 0.25 + 0 x 0.125 = 0.75

You may find useful David's example project, have a look at MPL115A1.c file.

I hope it helps.

Best regards,

Tomas

4,238 Views
beng_
Contributor III

That works for the first Co-effeicent a0 - but not the next one b1. In the data-sheet:

0xB3F9 = -2.37585

0xB3F9 = 1011 0011 1111 1001

There's one sign bit - 1 - so the number is negative

Two Integer bits - 01 - so the integer portion is 1 (not 2 according to the datasheet)

13 Fraction bits - 1 0011 1111 1001 - (this is 0.5 + 0.0625 + 0.03125 + 0.015625 0.007815 etc...) so the integer portion is 0.62414551 (not 0.37585 according to the datasheet).

0 Kudos
4,238 Views
beng_
Contributor III

Never mind got it - there's a later note in the data sheets that says:

NOTE: Negative coefficients are coded in 2’s complement notation.

Taking the bit inverse of all bits gives me the correct answer

0 Kudos
4,238 Views
beng_
Contributor III

Ah ha - thanks - that makes sense!

0 Kudos
%3CLINGO-SUB%20id%3D%22lingo-sub-873472%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EMPL115A2%20Coefficients%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-873472%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI've%20just%20started%20experimenting%20with%20the%20MPL115A2%20Digital%20Barometer.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EMaybe%20I%E2%80%99m%20having%20a%20bad%20day%20%E2%80%93%20but%20I%20can%E2%80%99t%20understand%20how%20to%20convert%20the%20Coefficient%20integers%20%2F%20binary%20values%20into%20numbers.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EThe%20data%20sheet%20doesn%E2%80%99t%20seem%20to%20make%20sense.%20For%20example%20a0%20is%20defined%20as%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22color%3A%20%23000080%3B%22%3Ea0%20Signed%2C%20Integer%20Bits%20%3D%2012%2C%20Fractional%20Bits%20%3D%203%20%3A%20Coeff%20a0%20%3D%20S%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E11%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E10%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E9%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E8%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E7%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E6%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E5%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E4%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E3%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E2%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E1%3C%2FSPAN%3E%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E0%3C%2FSPAN%3E%20.%20F%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E2%3C%2FSPAN%3E%20F%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E1%3C%2FSPAN%3E%20F%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E0%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ELater%20the%20data%20sheet%20uses%20the%20example%20a0%20%3D%200x3ECE%20%3D%202009.75%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EMaskign%20out%20-%20bits%20I%3CSPAN%20style%3D%22font-size%3A%2011px%3B%22%3E11%3C%2FSPAN%3E%20to%20I%3CSPAN%20style%3D%22color%3A%20%23000000%3B%20font-size%3A%2011px%3B%22%3E0%3C%2FSPAN%3E%20gives%202009%20-%20but%20the%20last%203%20bits%20(the%20fractional%20bits)%20are%200x06%20-%20I%20can't%20see%20how%20that%20taken%20to%20be%200.75%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EAre%20there%20any%20examples%20of%20how%20to%20take%20these%20Coefficients%20in%20binary%2Fhex%20form%20and%20convert%20them%20into%20actual%20numbers%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-873472%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EPressure%20Sensors%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-873476%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MPL115A2%20Coefficients%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-873476%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ENever%20mind%20got%20it%20-%20there's%20a%20later%20note%20in%20the%20data%20sheets%20that%20says%3A%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3ENOTE%3C%2FSTRONG%3E%3A%20Negative%20coefficients%20are%20coded%20in%202%E2%80%99s%20complement%20notation.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ETaking%20the%20bit%20inverse%20of%20all%20bits%20gives%20me%20the%20correct%20answer%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-873475%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MPL115A2%20Coefficients%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-873475%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThat%20works%20for%20the%20first%20Co-effeicent%20a0%20-%20but%20not%20the%20next%20one%20b1.%20In%20the%20data-sheet%3A%3C%2FP%3E%3CP%3E0xB3F9%20%3D%20-2.37585%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E0xB3F9%20%3D%20%3CSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23ff00ff%3B%22%3E1%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23000080%3B%22%3E01%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23339966%3B%22%3E1%200011%201111%201001%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EThere's%20one%20sign%20bit%20-%26nbsp%3B%3CSTRONG%20style%3D%22color%3A%20%23ff00ff%3B%20%22%3E1%3C%2FSTRONG%3E%20-%20so%20the%20number%20is%20negative%3C%2FP%3E%3CP%3ETwo%20Integer%20bits%20-%26nbsp%3B%3CSTRONG%20style%3D%22color%3A%20%23000080%3B%20%22%3E01%3C%2FSTRONG%3E%20-%20so%20the%20integer%20portion%20is%201%20(not%202%20according%20to%20the%20datasheet)%3C%2FP%3E%3CP%3E13%20Fraction%20bits%20-%26nbsp%3B%3CSTRONG%20style%3D%22color%3A%20%23339966%3B%20%22%3E1%200011%201111%201001%3C%2FSTRONG%3E%20-%20(this%20is%200.5%20%2B%200.0625%20%2B%200.03125%20%2B%200.015625%200.007815%20etc...)%20so%20the%20integer%20portion%20is%200.62414551%20(not%200.37585%20according%20to%20the%20datasheet).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-873474%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MPL115A2%20Coefficients%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-873474%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAh%20ha%20-%20thanks%20-%20that%20makes%20sense!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-873473%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MPL115A2%20Coefficients%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-873473%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Ben%2C%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EAs%20for%20the%20fractional%20part%2C%20F2%20%3D%200.5%2C%20F1%20%3D%200.25%20and%20F0%20%3D%200.125.%3C%2FP%3E%3CP%3EConsidering%26nbsp%3Bour%20example%2C%20the%20fractional%20part%20is%200b110%20%3D%201%20x%200.5%20%2B%201%20x%200.25%20%2B%200%20x%200.125%20%3D%200.75%3C%2FP%3E%3CP%3EYou%20may%20find%20useful%20%3CA%20_jive_internal%3D%22true%22%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Fdocs%2FDOC-335542%22%20target%3D%22_blank%22%3EDavid's%20example%26nbsp%3Bproject%3C%2FA%3E%2C%20have%20a%20look%20at%20MPL115A1.c%20file.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EI%20hope%20it%20helps.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EBest%20regards%2C%3C%2FP%3E%3CP%3ETomas%3C%2FP%3E%3C%2FLINGO-BODY%3E