📜 ⬆️ ⬇️

Responsible approach to measuring relative humidity

In this article, we continue to talk about sensors from the Swiss company IST. Not so long ago, posts about sensors of electrical conductivity of water and sensors for the velocity of the flow of liquids and gases were published, today the turn has reached relative humidity.



The article is devoted to high-precision sensors of the HYT series. A description of the sensor device and the sensing element is given, the order of pairing the sensor with the microcontroller is described in detail, an example of development is given.

')

1. Overview



Standard HYT models are three sensors for measuring temperature and relative humidity, built on the basis of the same sensing element, but made in different packages.



We will talk about other variants of the package below, but for now we will give the main characteristics of the HYT sensors.
Relative humidityTemperature
Measuring rangefrom 0 to 100% RHfrom -40 to +125 ° C
Accuracy (maximum error)± 1.8% RH (in the range of 0 ... 80% RH)± 0.2 ° C (in the range of 0 ... 60 ° C)
Response timeHYT 271 <4 s
HYT 221 <12 sec
HYT 939 <10 sec
HYT 271 <5 s
HYT 221 <12 sec
HYT 939 <10 sec
Repeatability± 0.2% RH± 0.1 ° C
Hysteresis<± 1% RH
Long term drift characteristics<± 0.5% RH / year<± 0.05 ° C / year
Supply voltage2.7 - 5.5 V
Current consumption<22 ÎĽA at a sampling frequency of 1 Hz, <1 ÎĽA in sleep mode

It is clear that such high accuracy and stability will not be useful in a home weather station tm . HYT sensors are used in industry - in household appliances, in processes that are associated with drying, evaporation and distillation, in analyzers of residual moisture of various materials, in medical technology, in ventilation systems and in other "critical applications".

2. Sensitive element



Like most modern sensors of relative humidity, HYT sensors have a capacitive sensing element. The principles of operation of converters "humidity-capacity" and their advantages are described in a huge number of sources, let me remind you the main thing.





The capacitive sensor is a ceramic substrate on which the lower conductive electrode, the moisture absorbing polymer and the upper electrode are sequentially located. The output characteristic of the converter is determined by the type of polymer, as well as its thickness and area:

εo - Electric constant. I'm too lazy to even give its value, the point is that it is a constant
εr - The dielectric constant of the polymer, changing in proportion to the amount of absorbed moisture
A - Polymer area
d - polymer thickness

Depending on the purpose of the sensitive element, transducers with different characteristics are produced, made on the basis of polymers with different parameters.

For example, for weather probes and some other applications, high speed is an important requirement. Reducing the response time of the sensing element is achieved by reducing the thickness of the polymer, so the response time of the P14 Rapid sensor is less than 1.5 seconds. Another example is the MK33 sensors, designed to work with oils. Here, by increasing the area of ​​the sensitive element, the steepness of the output characteristic, and hence the sensor resolution, increases.

IST produces about a dozen different capacitive transducers. I invite those interested to follow the link to their review , and we return to the digital sensors HYT.

3. The structure of the sensors HYT



The use of a “bare” sensing element is justified in very few cases. As a rule, it is simpler and more profitable to use an integrated module in which, in addition to a capacitive converter, a temperature sensor, thermal compensation and signal processing circuits, as well as a digital or analog interface are already provided. Such digital sensors are factory calibrated and do not require additional configuration.

Digital temperature and relative humidity sensors are produced in different price segments. A sensor that fits the description from the previous paragraph can cost $ 2 or $ 150. Such a difference between expensive and cheap sensors is explained by the fact that digital sensors differ not only in accuracy, speed and repeatability of measurement results, but also in other characteristics that are not so simple to ensure. This is a long-term stability of work, the ability to use the sensor at very low or very high humidity and resistance to environmental influences. To understand why the listed characteristics have a great influence on the cost of a component, we turn to the features of production.

One of the main difficulties in producing digital sensors for relative humidity is the incompatibility of some processes for the production of a capacitive sensing element and semiconductor production (creating a CMOS structure containing a temperature sensor, a signal processing circuit, etc.). Technologies do not allow to fully preserve the characteristics of a capacitive converter, if it is not made separately, but on the same substrate as the semiconductor structure. Therefore, the manufacture of a sensor that combines a capacitive element and a digital circuit always implies a compromise between the cost of production and the characteristics of the final product.

In the manufacture of HYT sensors, the capacitive SMD converter and the integrated circuit are manufactured separately from each other, tested separately, and only after that they are installed on a common substrate and connected with wires.



By reducing the mutual influence of the IC and capacitive sensor, the use of almost moisture-absorbing materials, gold conductors, as well as the use of other quality improvement measures, the digital module achieves an accuracy close to the accuracy of a separate moisture-capacity converter.

4. Calibrate the HYT sensors



Standard factory calibration is carried out at nine points at three temperatures:

After calibration, control measurements are taken. Standard control points:

Here is the time to remind about one of the main IST chips: at the request of the customer, the manufacturer manufactures various modifications of its sensors. Sensors with modified characteristics, products in non-standard cases and, of course, sensors with non-standard calibration are supplied. Knowing the specifics of the application conditions of the final product, it is possible, for example, to order a HYT sensor with a calibration from 0 to 50% RH with a shift of + 2% RH over the entire range.

Such modifications have little effect on the price and delivery time and, which is especially nice, are available for short-run products.

5. HYT sensor housing



We give a description of the sensors series HYT.

The simplest module - HYT 271 - has a size of 5 to 10 mm and consists of a capacitive transducer filled with a “blot” integrated circuit and additional capacitors. In the absence of a protective filter, maximum speed and minimum price are achieved.

The digital sensor HYT 221 has the same filling as the HYT 271, but is covered with a protective filter that allows the sensor to be used, including in the presence of splashing water.


The HYT 939 sensor also differs only in the type of protective filter - the components are placed under a round metal case, on the upper side of which there is an opening closed by a membrane. Available to order is a HYT 939 module, resistant to pressure up to 16 bar.

In accordance with customer requirements, both the structure and the overall dimensions of the sensor can be changed. Instead of the standard I2C interface, the sensor can be equipped with 5-pin SPI, and in addition to the digital interface, additional quasi-analog lines can be added. The sensor leads can be extended, equipped with a connector. Sensors are manufactured in specialized cases, for example, as in the photo.

Ordering sensors with modified dimensions or non-standard configuration is possible, including for small-scale production.


4. Order of pairing sensor and control controller



The standard interface for connecting the HYT sensor to the control microcontroller is the I2C bus. The controller is a master, the sensor is a slave node.

There is nothing remarkable in the hardware characteristics of the sensor interface - speeds from 100 to 400 kHz and a standard 7-bit bus address are supported. The default sensor address is 0x28, the address can be changed to a value from 0x00 to 0x7F. Data is transmitted in MSB mode, i.e. high bits first.

I see no reason to describe the operation of the I2C bus itself. I also miss the description of the typical switching circuit, the HYT module requirements for timing on I2C, the description of the procedure for changing the address of the sensor. All this can be found in Wikipedia and documentation .

Let us dwell on the procedure for collecting data from the HYT sensor - a sequence of two commands to control the module.
In the absence of requests from the microcontroller, the sensor is in sleep mode. Upon the arrival of the 'Measuring Request ’(MR) command, it wakes up, starts a measurement cycle and generates a message with data for the controlling controller. Data preparation takes from 60 to 100 ms, after which the ‚Data Fetch '(DF) command should arrive at the sensor, according to which data from the output register of the sensor are transmitted to the microcontroller.

The “Measuring Request” command does not imply reading or writing data. The command contains only the header packet — the address of the slave node and the RW bit set to “0”, i.e. on the record.



The ‚Data Fetch '(DF) command is used to read data. The header file contains the address of the sensor and the RW bit set to "1", i.e. for reading.



The maximum number of bytes that must be taken on a microcontroller is four. The first two bytes contain data on relative humidity, the third and fourth - on temperature.

The microcontroller can request only the first two bytes (humidity data only) or the first three bytes (humidity data and high-order bits of the temperature value).

Both humidity and temperature account for 14 bits. The Data Fetch package also contains two status bits:


Processing the received parcel consists in calculating the values ​​of temperature and relative humidity from the input data. First, the status bits are masked, then the absolute values ​​of temperature and relative humidity are calculated from the obtained data:

RH [%] = (100 / (2 14 - 1)) * RH in
T [° C] = (165 / (2 14 - 1)) * T in - 40

5. An example of enabling the HYT sensor



From theory to practice. Consider the task of polling the HYT sensor from the debug board EFM32ZG-STK3200 from Silicon Labs, a detailed description of which was provided in a previous article .

This time, on the debug board, we will need a built-in LCD display, a mechanical button and a 20-pin connector with I2C signals, power and ground.



Connection

We connect the lines in accordance with the pinout of the sensor and the board connector.

For operation of the I2C bus on both its lines, pull-up resistors should be provided. The HYT sensor documentation lists 2.2 kΩ ratings, and the circuit was originally assembled using two separate resistors. However, during the debugging process, it turned out that to interrogate a sensor connected to short leads, it is enough to use the built-in pull-up resistors of the EFM32 microcontroller. Their nominal is 40 kΩ.



In this case, the sensor is powered from the power line MK (3.3 V), but five-volt levels are also permissible.

Microcontroller Programming

To work with the debug card EFM32ZG-STK3200, Simplicity Studio is used - a platform containing an IDE, examples of programs, documentation and various utilities for developing an application. Her description can also be found in previous articles , here I’ll just say that it is a free program that SiLabs distributes to work with SiLabs controllers.

When creating the program, the ready-made I2C driver from SiLabs and the glib library, designed to work with the LCD built into the plan, are used. The SPI interface and the real-time clock are used to communicate with the display, however, work with these modules is hidden in the depths of glib.

The program implements the simplest aglorhythm of the HYT sensor survey - by pressing the PB1 button, we receive data from the sensor on temperature and humidity, recalculate the values ​​obtained in degrees Celsius and percentages and display them on the screen. In case an error occurred while receiving data, a corresponding message is displayed.

imageimageimage

Full source code is available on github . Below we analyze only the part of the program that is related to polling the sensor, i.e. to I2C communication.
Basically, the standard library functions from Silicon Labs are used - the main em_i2c package and its i2cspm add- in .

For communication with the sensor, i. implementation commands Measuring Request and Data Fetch, serve the same function.

Each of them contains operations on the formation of a packet for I2C and the command to send a packet. To form a packet, the I2C_TransferSeq_TypeDef structure is used, which contains the sensor address, the value of the RW bit, and the register format for receiving (buf [0]) and transmitting (buf [1]) I2C data.

/**************************************************************************//** * Start a measuring cycle (Measurement Request command) * - [6-bit address] + [W flag] * - w/o data transfer *****************************************************************************/ void performMRCommand(void) { I2C_TransferSeq_TypeDef seq; seq.addr = HYT_ADDR; seq.flags = I2C_FLAG_WRITE; seq.buf[0].len = 0; seq.buf[1].len = 0; I2CSPM_Transfer(I2C0, &seq); } 


The function performDFCommand, in addition to indicating that a four-byte packet has been received with data written to the I2CdataToRead array, contains an algorithm for processing the received message. As a result of the conversion, the required values ​​are written to the temperature and humidity variables.

 /**************************************************************************//** * Fetch the last measured value of Humidity / Temperature (Data Fetch command) * - [6-bit address] + [R flag] * - w/ 4-byte data transfer: [CMode bit] + [State bit] + [14 bit humididty] + * + [14 bit temeprature] + [2 insignificant bits] *****************************************************************************/ int8_t performDFCommand(void) { I2C_TransferSeq_TypeDef seq; uint8_t I2CdataToRead[4]; unsigned int tempRawData, humididtyRawData; seq.addr = HYT_ADDR; seq.flags = I2C_FLAG_READ; seq.buf[0].data = I2CdataToRead; seq.buf[0].len = 4; seq.buf[1].len = 0; I2CSPM_Transfer(I2C0, &seq); uint8_t sensorCModeBit = (I2CdataToRead[0] & 0x80) >> 7; uint8_t sensorStateBit = (I2CdataToRead[0] & 0x40) >> 6; tempRawData = ((I2CdataToRead[2] << 8) | I2CdataToRead[3]) >> 2; humididtyRawData = ((I2CdataToRead[0] & 0x3F) << 8) | I2CdataToRead[1]; if (sensorCModeBit == 1) { return HYT_COMMAND_MODE; } if (tempRawData != 0 && humididtyRawData != 0 && tempRawData < 0x3FFF && humididtyRawData < 0x3FFF) { if (sensorStateBit != 1) { /* temperature as 14bit-value in the range from -40°C to +125°C */ temperature = ((float) (tempRawData) * 165.0F / 16383.0F) - 40.0F; /* humidity as 14bit-value in the range from 0%rH to 100%rH */ humidity = (float) humididtyRawData * 100.0F / 16383.0F; } else { /* No new value has been created since the last reading */ } return HYT_IS_OK; } else { return HYT_ERROR; } } 


When working with ready-made library functions for I2C from SiLabs, there are two main ways to spoil your life:

Method 1 : Calculate that 0x28 should be written to HYT_ADDR, i.e. the sensor address specified in the documentation .
Let me remind you that the address on the I2C bus is seven bits, i.e. 0x28 in the documentation means 010 1000. It would be logical to supplement this number with the high bit “0” and still have 0x28, however the library function for some reason considers that the address is not the low, but the high 7 bits. Thus, instead of
 #define HYT_ADDR 0x28 
should indicate
 #define HYT_ADDR 0x50 
or
 #define HYT_ADDR 0x51 

Method 2 : Calculate that I2C_FLAG_READ is “0” and I2C_FLAG_WRITE is “1”, which is provided by the bus protocol. That is, in fact, everything is as it is, in the header byte of the I2C package there is a single RW bit, which is set to “0” for data recording and to “1” for reading data. However, in the depths of the em_lib library, such insidious defaults are hidden here:
 #define I2C_FLAG_WRITE 0x0001 #define I2C_FLAG_READ 0x0002 
So, it is not necessary to set zeros and ones when forming the I2C_TransferSeq_TypeDef structure.

The rest of the claims to em_i2c and other packages em _ *** did not arise.

There must be a delay between calls to the performMRCommand () and performDFCommand () functions, for which the sensor generates a message with the measurement results.

 /**************************************************************************//** * Read temperature and humidity from HYT sensor, show result on the display * - Send MR (Measurement Requests) command * - Wait for 100 msec * - Send DF (Data Fetch) command * - Show result OR show error message *****************************************************************************/ void ReceiveDataAndShowIt(void) { performMRCommand(); delay100ms(); int8_t HYT_result = performDFCommand(); if (HYT_result == HYT_IS_OK) { Display_ShowValues(temperature, humidity); } else if (HYT_result == HYT_COMMAND_MODE) { Display_ShowCMode(); } else if (HYT_result == HYT_ERROR) { Display_ShowError(); } } 


We call the ReceiveDataAndShowIt () function, which polls the sensor and displays the measurement results, from the interrupt handler, which is shown below.

 /**************************************************************************//** * GPIO Interrupt handler (pushbutton # 1) * - Receive HYT data & show results on the display *****************************************************************************/ void GPIO_ODD_IRQHandler(void) { uint32_t interruptMask = GPIO_IntGet(); if (interruptMask & (1 << BUTTON_PIN)) { Display_WellcomeScreen(); ReceiveDataAndShowIt(); } GPIO_IntClear(interruptMask); } 


It is important to note here that this program performs a rather trivial task. To measure the temperature and humidity of the air, which almost do not change in time, any inexpensive sensor will work.

The outstanding characteristics of the HYT series are much better illustrated in dynamics. The video below shows how quickly the HYT-271 responds to changes in air humidity.



If you have had the honor of ever observing how quickly the conditional DHT22 reacts to changes in humidity, then, of course, you will feel the difference.

PS The process of creating a prototype, which is demonstrated in the video, is devoted to a series of articles " How to stop being afraid and fall in love with mbed "

6. Conclusion



In conclusion, I traditionally thank the reader for his attention and remind you that questions about the use of products, about which we write on Habré, can also be asked by email, specified in my profile.

Source: https://habr.com/ru/post/303350/


All Articles