dm00242307

TN1228
Technical note
How to interpret pressure and temperature readings in the
LPS25HB pressure sensor
Introduction
The purpose of this technical note is to provide a review of two's complement notation for ease of
design in the LPS25HB pressure sensor and to guide the user in the interpretation of pressure and
temperature values in the device registers. MEMS pressure sensors measure absolute pressure (P) and
2
temperature (t) and store the values in two's complement registers which can be read via the I C or SPI
host interface.
The pressure sensor stores pressure as a 24-bit word. Both values are stored as two's complement
integers as illustrated below.
Figure 1: Pressure sensor analog-to-digital data flow
Digital Domain
Analog Domain
P
t
Low Noise
Analog Front
End
Sensors
and Bias
(AFE)
Analog to
Digital
Conversion
(ADC)
Addr(h)
November 2015
Digital Control
Signal Processing
(DSP)
&
Register Bank
I2C
SPI
Byte Description
24-bit Pressure count
Two’s complement value
28h
29h
2Ah
PressureOut_XL (LSB)
PressureOut_L (MIDDLE)
PressureOut_H (MSB)
16-bit Temperature count
Two’s complement value
2Bh
2Ch
TemperatureOut_L (LSB)
TemperatureOut_H (MSB)
DocID028580 Rev 1
1/8
www.st.com
Contents
TN1228
Contents
1
Why we use two's complement ...................................................... 3
2
How to obtain pressure values in mbar ......................................... 4
3
How to obtain temperature values in °C ........................................ 5
4
5
Support material .............................................................................. 6
Revision history .............................................................................. 7
2/8
DocID028580 Rev 1
TN1228
1
Why we use two's complement
Why we use two's complement
Measuring analog values and storing the data in a digital domain creates an interesting
dilemma. How do we represent negative analog values in a digital system? How do we
handle the number zero?
A computing system uses two's complement to simplify the processing logic required to
handle negative numbers and subtractions. A circuit designed for addition can handle
negative operands by using two’s complement. This minimizes the need for additional
circuitry capable of subtraction or additional switching circuitry based on the sign. Most
modern computers, MCU’s, and DSP’s use two’s complement notation.
If a register is defined as two’s complement, typically the most significant bit (msb) of the
most significant byte (MSB) indicates the sign as shown in the figure below. If the msb of
the register is 1, the number is negative and we use two’s complement. If the bit is 0, the
integer is positive and no translation is necessary.
Figure 2: Sign bit indicates whether a value is positive or negative
PressOut_H (0x2A)
Bit
23
Bit
22
Bit
21
Bit
20
Bit
19
Bit Bit
18 17
Bit
16
PressOut_L (0x29)
Bit
15
Bit
14
Bit
13
Bit
12
Bit
11
Bit Bit
10 9
PressOut_XL (0x28)
Bit
8
Bit
7
Bit
6
Bit
5
Bit
4
bit
3
bit
2
bit
1
bit
0
S
I
G
N
0 = POS
1 = NEG
pressure magnitude
DocID028580 Rev 1
3/8
How to obtain pressure values in mbar
2
TN1228
How to obtain pressure values in mbar
The pressure sensor stores the pressure value in raw counts in 3 registers: PressOut_H,
PressOut_L, and PressOut_XL. The most significant bit of the PressOut_H register
indicates the polarity. If the sign bit is zero, then the value is positive and the pressure in
mbar is determined by dividing the decimal value by the scaling factor of 4096. A sign bit of
1 indicates a negative value, so we first take the two’s complement of the complete word
and then divide by 4096.
Keep in mind that the sign bit determines whether we should perform the two’s complement
operation or not. The 3 bytes are concatenated to form a 24-bit word and the complete
word is represented in two’s complement (not the single bytes).
When reading the pressure value, it is important to note the byte ordering. This is
especially important in auto-increment mode when the address is incremented
automatically. The designer should assemble the proper 24-bit endian format (pressure
count = 2Ah & 29h & 28h).
The device may be configured to report a delta pressure by using the auto-zero feature.
The actual pressure output value is copied in the REF_P_H, REF_P_L, and REF_P_XL
registers and the PressOut() registers contain the difference between the current pressure
and the reference pressure. So the PressOut() registers could contain a negative value.
Negative values can also occur when a device is defective. Hence it can be used for selftest during a boot-up operation and when the auto-zero feature is not used. An example of
a pressure calculation when the sign bit is 0 is shown in the following figure.
Figure 3: Pressure example: sign bit is 0, this is a positive value
PressOut_H (0x2A)
Bit
23
Bit
22
Bit
21
Bit
20
Bit
19
0
0
1
1
1
3
Bit Bit
18 17
1
1
F
PressOut_L (0x29)
PressOut_XL (0x28)
Bit
16
Bit
15
Bit
14
Bit
13
Bit
12
Bit
11
Bit Bit
10 9
Bit
8
Bit
7
Bit
6
Bit
5
Bit
4
bit
3
bit
2
bit
1
bit
0
1
1
1
1
1
0
1
1
1
0
0
0
1
1
0
1
F
0
5
8
D
Pressure Counts = 2Ah & 29h & 28h = 3FF58Dh = 4191629(dec)
Pressure millibar =
# counts
Scaling factor
=
4191629 counts
4096 counts/mbar
= 1023.3 mbar
The auto-zero feature can be enabled by setting bit 1 in CTRL_REG2 (0x21h).
4/8
DocID028580 Rev 1
TN1228
3
How to obtain temperature values in C
How to obtain temperature values in °C
The LPS25HB also contains a temperature sensor which is used for compensation of the
pressure sensor. The temperature data is also available for outside applications. The
temperature raw count is stored in registers Temp_Out_H (2Ch) and Temp_Out_L (2Bh).
The temperature in °C can be determined by calculating the two’s complement, if
necessary, and perform the scaling.
The temperature in °C is calculated as follows:
𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝑖𝑖𝑖𝑖 °𝐶𝐶 = �𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂𝑂 +
#𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐
#𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐
� = �42.5 °𝐶𝐶 +
�
480 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐/°𝐶𝐶
𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠
An example of a temperature calculation when the sign bit is 0 is shown below.
Figure 4: Temperature example: sign bit is 0, this is a positive value
Temp_Out_L (0x2B)
Temp_Out_H (0x2C)
Bit
15
Bit
14
Bit
13
0
1
1
Bit
12
Bit
11
Bit
10
Bit
9
Bit
8
Bit
7
Bit
6
Bit
5
0
1
0
1
1
1
1
0
B
6
Bit
4
1
Bit
3
0
D
Bit
2
0
Bit
1
Bit
0
0
0
0
Temperature Counts = 2Ch & 2Bh = 6BD0h = 27600(dec)
Temperature in °C = Offset +
# counts
scale
= 42.5 +
27600 counts
480 counts / °C
= 100 °C
Likewise, a negative value is indicated when the MSB in the temperature word is equal to
1. To obtain the temperature, we first take the two’s complement of the complete word and
then perform the scaling and offset operation.
When reading the temperature values it is also important to note the byte ordering. This is
especially true in auto-increment mode in which case address 2Bh is read first, followed by
address 2Ch. The designer should assemble the proper 16-bit endian format (temperature
count = 2Ch & 2Bh).
The following registers in the device are two’s complement. All other registers in the device
are either unsigned or bitwise representations (not negative).
Table 1: Pressure sensor two's complement registers
Function
PRESS_OUT()
TEMP_OUT()
Byte
2Ah & 29h & 28h
2Bh & 2Ch
REF_P()
0Ah & 09h & 08h
RPDS()
39h & 3Ah
Description
24-bit absolute pressure data or this contains the
difference in pressure between Ref_P() and
Press_Out() when auto-zero mode is used.
16-bit temperature data
24-bit pressure data subtracted from the sensor output
measurement in auto-zero mode
The pressure offset value is a 16-bit data that can be
used to implement One-Point Calibration (OPC) after
soldering.
DocID028580 Rev 1
5/8
Support material
4
TN1228
Support material
Table 2: Related design support material
Document
type
Part number
Datasheet/
data brief
LPS25HB
MEMS pressure sensor: 260-1260 mbar absolute digital output
barometer
STEVALMKI109V2
eMotion: ST MEMS adapter motherboard based on STM32.
Compatible with all ST MEMS adapters based on STM32F103.
STEVALMKI165V1
LPS25HB adapter board for standard DIL24 socket
Evaluation
board
User manual
Application
note
6/8
Title
UM0412
Getting started with DfuSe USB device firmware upgrade
STMicroelectronics extension
UM0979
STEVAL-MKI109V1 and STEVAL-MKI109V2 - eMotion
motherboards for MEMS adapter boards
UM1049
Unico graphical user interface (GUI)
UM1064
Software guide for Unico lite
AN4672
LPS25HB digital pressure sensor: HW guidelines for system
integration
AN4503
Environmental sensors: Hardware abstraction layer for Android
DocID028580 Rev 1
TN1228
5
Revision history
Revision history
Table 3: Document revision history
Date
Revision
09-Nov-2015
1
Changes
Initial release.
DocID028580 Rev 1
7/8
TN1228
IMPORTANT NOTICE – PLEASE READ CAREFULLY
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST
products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the
design of Purchasers’ products.
No license, express or implied, to any intellectual property right is granted by ST herein.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.
© 2015 STMicroelectronics – All rights reserved
8/8
DocID028580 Rev 1