I have a MPL115A1 barometer which outputs data as two 8-bit words. To get the Temperature and pressure coefficients you combine the two 8-bit words in to one 16-bit word BUT then use only the Right 10 binary digits.
Here are examples from the data sheet:
Pressure MSB = 67h
Pressure LSB = C0h Pressure = 67C0h = 0110 0111 11 00 0000
= 415 ADC counts
First 10 digits are 0110 0111 11 which = 415
Temperature MSB = 80h
Temperature LSB = 40h Temperature = 8040h = 1000 0000 01 00 0000
= 513 ADC counts
First 10 digits are 1000 0000 01 which = 513.
When I use the GCB "VAL" command to convert the first example to decimal I get 41703 which is wrong. It should be 415.
Does anyone know how to convert a 10-bit binary to decimal?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you only wish to work on the 10 Most Significant Bits you need to Right Shift 6 times.
Considering that a Right Shift is the equivalent of Divide by 2, then 6 Right shifts are a divide by 64.
So concatenate the MSB and LSB into a Word Variable then divide the Word by 64
VAL will then return your expected value of 415.
Cheers
Chris
Edit Anobium hit send whilst I was running the Spell Check :)
Same Maths just a different explination...........
Last edit: Chris Roper 2018-10-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Both methods will give the same result. However as a general rule shifting bits is faster and more code efficient than division.
Consider the following code.
#chip 18F25K42, 16
Pressure = 0x67C0
Pressure = Pressure / 64 '// This takes ~ 92 us to complete
' '// Uses 78 Words of Program memory
' '// Uses 1 Byte of RAM
Pressure = FnLSR(Pressure, 6) '// This takes ~ 14 us to complete
' '// Uses 29 Words of Program memory
' '// Uses 6 bytes of RAM
Last edit: William Roth 2018-11-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using v0.98.02 with a 18F4550.
I have a MPL115A1 barometer which outputs data as two 8-bit words. To get the Temperature and pressure coefficients you combine the two 8-bit words in to one 16-bit word BUT then use only the Right 10 binary digits.
Here are examples from the data sheet:
Pressure MSB = 67h
Pressure LSB = C0h Pressure = 67C0h = 0110 0111 11 00 0000
= 415 ADC counts
First 10 digits are 0110 0111 11 which = 415
Temperature MSB = 80h
Temperature LSB = 40h Temperature = 8040h = 1000 0000 01 00 0000
= 513 ADC counts
First 10 digits are 1000 0000 01 which = 513.
When I use the GCB "VAL" command to convert the first example to decimal I get 41703 which is wrong. It should be 415.
Does anyone know how to convert a 10-bit binary to decimal?
:-)
BitsOut = FnLSR(BitsIn, NumBits)
So, 513 = FnLSR( 0x8040 , 6 ).... so use valout = FnLSR( valin, 6
If you only wish to work on the 10 Most Significant Bits you need to Right Shift 6 times.
Considering that a Right Shift is the equivalent of Divide by 2, then 6 Right shifts are a divide by 64.
So concatenate the MSB and LSB into a Word Variable then divide the Word by 64
VAL will then return your expected value of 415.
Cheers
Chris
Edit Anobium hit send whilst I was running the Spell Check :)
Same Maths just a different explination...........
Last edit: Chris Roper 2018-10-18
Thanks!
Both methods will give the same result. However as a general rule shifting bits is faster and more code efficient than division.
Consider the following code.
Last edit: William Roth 2018-11-15