Designing Temperature Measurement with Pt100 Sensor
A high-precision temperature measurement chip (Si7051) is used to compensate the cold junction of the thermocouple. In order to convert temperature↔voltage, high-density bidirectional linear interpolation is performed in the thermocouple indexing table. Use three-wire Pt100 as the moving shoulder to form an unbalanced resistance bridge to detect the thermal resistance value. The temperature is obtained by solving the one-dimensional fourth-order thermal resistance equation of Pt100 analytically. Use a high-precision Σ-Δ analog-to-digital converter (ADC) with easy-to-drive functions. The high-performance 32-bit microprocessor STM32F103 with ARM Cortex-3 structure is selected. Combining these technologies, the temperature measurement resolution of the thermostat can reach 0.001°C. The error analysis of the above related content and the programming implementation on STM32F103 are the focus of this article. What is described in this article is not only for temperature measurement, but also for the measurement of other weak electrical and non-electrical signals (such as pressure, weight, etc.).
0 Preface
Many thermostats still use the traditional temperature measurement circuit structure: sensor → filter → preamplifier 1 → sensor type switching → preamplifier 2 → filter → ADC → MCU processing. Moreover, ADCs are usually integrated in MCUs, which not only have low resolution (mostly 12 bits or less), but the reference power supply is often immutable. This kind of structure has many components and high noise, and is not suitable for high-precision measurement and control. Taking thermocouples as an example, within the range of 0 ~ 661 °C, the resolution is difficult to exceed 0.1 °C. The accuracy is difficult to exceed 0.5%image.png (1631081939725930.png is the absolute value of the temperature, the unit is °C). In recent years, many IC companies have integrated the above-mentioned traditional temperature measurement structures and launched high resolutions (16-bit, 20-bit and 24-bit) for weak sensor signals at the microvolt level such as thermocouples. And there are multi-channel ADCs, such as LTC2486. This provides a good choice for the high-precision temperature measurement design of the thermostat.
1: High-precision temperature measurement circuit design
1.1 Circuit structure
Figure 1 shows a more conventional design, which is relatively simple. Without special signal amplification and channel switching circuits, the filter circuit is also the simplest first-order passive RC.
1.2 Temperature sensor
Usually, the thermostat requires two major types of sensors, thermocouples (TC) and resistors (RTD).
Figure 1 Thermostat high-precision temperature measurement circuit structure
1.2.1 Thermocouple
The latest international standard for thermocouples is the 2013 version of IEC60584-1:2013, and the equivalent (IDT) national standard is GB/T1639.1-2018[4]. The standard divides thermocouples into multiple types (E, K, J, etc.), among which type E has the highest sensitivity [3]. It is suitable for relatively high-precision temperature measurement. From a high-precision perspective, type E should be purchased with Class 1 error (0.004 for −40 to 800 °C temperature) [4], sheath and junction isolation [3] but connected to the shield for differential connection and Reduce noise.
1.2.2 RTD
In thermostats, this generally refers to Pt100, the current international standard is IEC 60751:2008, and the equivalent national standard is GB/T30121-2013. The formula of Pt100 thermal resistance is as follows [5]
Among them, the unit of t is °C; Rt is the resistance of Pt100; R0 is the resistance of Pt100 at 0 °C (100 Ω) [5] (the same below).
The error (or tolerance) level of Pt100 is divided into 4 levels [5]. Here we choose the highest level AA (±(0.1+ 0.001 7) (at −50 ~ 250 °C); or level A (the next highest level, ±( 0.15 + ) at −100 ~ 450 °C).
1.3 Detecting temperature signals
1.3.1 Thermocouple
1) Low pass filtering
Since it is a voltage signal, it can be directly connected to the differential input of the LTC2486 (CH2-CH3) after simple first-order RC low-pass filtering, as shown in Figure 2. filter cutoff frequency
Figure 2 Temperature detection and ADC circuit diagram
2) Cold end (also called reference end [4]) compensation thermocouple temperature measurement needs to solve a cold end compensation problem. The specific steps are:
① Use a high-precision temperature measurement chip to measure the cold end temperature tcj of TC [6].
② Due to the non-complete linear relationship of temperature ↔ voltage, tcj must be restored to voltage Vcj [3] using a linear interpolation algorithm on an E-type scale [4].
③ Add Vcj to the TC's output voltage Vtc as part of the TC's output voltage.
In addition to Si7051, the temperature measurement chip can also choose TMP275 (resolution up to 0.065 °C) and ADT7410 (0.007 8 °C).
3) Output voltage range. For type E thermocouple, in the temperature measurement range of −68 ~ 661 °C, check the graduation table [4], the corresponding voltage (Vi) range is −3.711 ~ 49.997 mV. In order to improve the resolution, the range can be reduced and the GAIN can be increased. See 1.4 for the definitions of FS and GAIN.
In Figure 2, the "M" in the thermocouple symbol represents the shielding end.
1.3.2 Pt100
It is necessary to convert the non-electrical resistance into a voltage signal. The lead error of the second-line Pt100 cannot be eliminated, and the temperature measurement deviation is large (when r = 0.225 Ω, it is about 1 ~ 1.5 °C). A three-wire Pt100 unbalanced resistor bridge is shown in Figure 3 (or Figure 2). is the lead resistance. is a fixed resistance; ΔR represents the temperature change relative to R0, which is positive or negative; Vcb is the bridge power supply; Vb is the bridge voltage when unbalanced. The three-wire Pt100 bridge has controllable lead error.
In this thermostat design, the temperature measurement range is divided into two levels according to the accuracy:
①(−68 ~ 68) °C, resolution 0.001 °C;
②(−68 ~ 466) °C, resolution 0.007 °C.
However, in the following design discussion, only ① is taken as an example.
Figure 3 Three-wire Pt100 resistance bridge analysis model
1.3.2.1 Bridge design
1) Resistor selection
① Actual measurement shows that the resistance of the 2 m long Pt100 lead is r = 0.225Ω. According to the requirement of within 20 m, it is about 2.25 Ω. According to formula (4) again, R1 and R2 are required to be more than one thousand times of r to reduce the lead error. So take image.png= ≥2.25 kΩ;
②The current (I p ) flowing through Pt100 should not be greater than 1 mA [5] to control self-heating. But it cannot be too small, otherwise it will affect the sensitivity of the bridge resistance measurement. The actual value is I p = (1 ~ 2) mA;
③The greater the resistance, the greater the noise [8]. From this perspective, the smaller the resistance, the better;
④The bridge should remain balanced (Vb = 0) at 0 °C. Requirements:
⑤ Consider that Vcb is generated by TL431, so select Vcb ≥ 2.5 V (see below). Based on the above four points, R1=R2= 2 400 Ω. Combining formula (3), we have
R1 ~ R3 use chip resistors with an accuracy of 0.01% and a temperature coefficient of 5×10−6/°C (about 0.45 yuan/piece in batches). This requirement is very important.
2) Vcb selection and bridge voltage output range selection
It can be seen from equation (9) that the selection of Vcb is related to the temperature measurement range (ΔR), bridge voltage Vb range, and bridge resistance selection. In the measurement range ①, when ΔR = 26.31Ω, if (4 is GAIN) is selected, at this time, according to equation (9) Vcb = 5 000 mV, and then from equation (9) we can get: at −68 °C, Vb = −52.2 mV, so the range of Vb is (−52.2 ~ 50) mV. The bridge voltage Vb is also low-pass filtered (R89, R90, C26 and C33) before entering the differential channel (CH0-CH1) of the ADC.
1.3.2.2 Three-wire bridge error analysis[10]
Assume first, and according to equation (6), then the bridge pressure is:
When the lead resistance image.png also considers equation (3), then the bridge voltage:
in,
It can be assumed that:
Then r in the addition term of Vbr and VG can be ignored, so we have
Consider another 2 factors for VG:
Available:
In order to ensure that the temperature measurement resolution is higher than 0.001, it is required that in formula (4b)
This can be done in practice. In this way, the following formula (4a) can be obtained:
At this time the relative error
Equation (6) shows that ① ε can be positive or negative, because ΔR and ΔR can be positive or negative; ② The smaller ΔR is, that is, the closer the temperature is to 0 °C, the larger the relative error ε is; ③ According to equation (3a), ε = 0 .
The above two points ① and ② are consistent with general perceptual understanding.
The current example is as follows: As mentioned above, when 2m long, the lead resistance r = 0.225Ω, if ΔR = 0.195 (corresponding to Ω temperature 0.5 °C), and let R1 = 2402 Ω, R2 = 2400 Ω, then the formula ( 3),
This relative error is very small, and after the temperature is higher than 0.5 °C, the error will gradually decrease again. Based on the above, as long as formula (3a) is satisfied, the influence of lead resistance r can be reduced to within 100%, or even smaller (designed according to actual needs).
The analysis conditions pointed out in reference [10] are different from this. Is it better to change to equation (3a)?
It is important to note that if the resistances of the three wires are unequal (which exists in practice), errors will be introduced. At this time, the three-wire circuit here cannot completely solve the problem. Therefore, when purchasing, you must make a request to the supplier that the three lines are equal.
1.4 Selection and use of ADC
The choice of LTC2486 (referred to as 2486) is mainly due to the following four reasons [1].
①High comprehensive resolution and small error. It is nominally 16 bits, but actually has a resolution of 17 bits (including the sign bit). Ideally, 1 μV voltage can be resolved.
② There are 2 differential channels, which just meet the input requirements of thermocouples and Pt100 of general thermostats, without the need for additional switching circuits (which will introduce noise errors).
③There is a built-in programmable gain amplifier (PGA, 1 ~ 256, divided into 8 levels).
④ Low noise and small error.
1.4.1 ADC application circuit design
The interface circuit between LTC2486, sensor and STM32F103 is shown in Figure 2.
1) Vcc and REF +, REF − voltage design
① Considering the low power consumption (0.8 mW) and accuracy of 2486, Vcc is selected
Choose to be powered by the reference voltage, TL431 generates output via 5 V;
② Define ADC_Data as conversion data; GAIN as internal gain value; Vref as reference voltage; Fs as full-scale voltage, Fs = 0.5Vref[1].
Generally, conversion errors (offset, nonlinearity, etc.) are ignored, and the conversion data is inversely proportional to Vref, that is, ADC_Data. In this way, the smaller the Vref, the smaller the voltage that the LSB can resolve. But Vref cannot be too small, not less than 400 mV [8]. Here take REF+ = 400 mV.
③ The reference positive power supply (REF+) of 2486 is generated by the higher precision chip (0.5%) LT6650. When the input of this chip is 5 V, the output can be adjusted (0.4~4) V.
④ REF- Ground. Vref = REF + −REF− = 400 mV, Fs =200 (mV).
2) Selection of GAIN
In order to achieve full-scale conversion (positive conversion data reaches 0×10000), for thermocouples, follow Section 1.3.1, GAIN ≈ 4, take 4 pairs of Pt100, follow Section 1.3.2, GAIN = 4. Note that the larger the value of GAIN, the greater the noise [1], and the greater the fluctuation of the ADC_Data value. The selection of GAIN can be achieved through the buttons of the controller.
3) Interface with STM32F103 (F103 for short)
Interface with F103 through four-wire SPI.
① Bidirectional mode, F103 is the master and 2486 is the slave;
② F103 uses 3.3V working voltage, while 2486 uses 5V, and there must be level conversion in the middle. For this reason, the output signal (MOSI, SCK, NSS) of F103 should be set to open circuit (OD), and the pull-up resistor is (3.3 ~ 5.1) kΩ; while the output signal SDO of 2486 should be divided to 3.3 V by a resistor and then connected MISO to F103. as shown in picture 2.
2 Programming
Conducted under IAR version 7.20.5.624. Use the latest version 3.5.0 [9] library function released in 2011.
2.1 F103 and LTC2486 interface programming
2.1.1 SPI initialization function
1) Procedure
void SPI2_Init(void)
{
Refer to library function programming. Just pay attention to setting PB13 and PB15 lines as multiplexed open-drain outputs. This method is for level conversion between F103 and 2486.
GPIO_InitStructure.GPIO_Pin_13|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_
OD;}
2.1.2 Write a byte data function to 2486
1) Procedure
void SPI2_reg_write(u8 data)
{
① SPI2->DR = data; // Put the data into the data register of the SPI2 port and send it out;
② while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_
FLAG_RXNE) == RESET);
}
2) Program notes
Statement ② determines whether writing one byte of data is successful. There are many similar statements in SPI and I 2C library functions, which must be understood. Due to space limitations, no further introduction is given here. For details, please refer to references [9] and [13].
2.1.3 Read 1 byte of data from 2486
Just read it directly from the data register of SPI2 port. No functions are used. That is: b = SPI 2→ DR; b is an unsigned byte variable.
2.1.4 Read the conversion data function of 2486
1) Algorithm
Before reading data, the working mode of 2486 must be set (written) first. Different requirements require different settings. This is just one example. Note the use of default values.
①The data conversion rate of 2486 is usually selected to be 6 times/s. 12 times/s can also be selected, but this will reduce the accuracy [1] and is generally not selected.
②Select the conversion channel. Choose between 4 single-ended or 2 differential channels.
③Select GAIN value. Make different selections as described in 1.4.1.
After this, the data can be read.
④ 2486 will output 1 bit low level on the SDO pin when the conversion is completed, which can be used as the conversion end flag (ie EOC signal) to judge, generally using the query method.
⑤ 2486 will output 3 8-bit bytes of data after each conversion. Each output byte is synchronized with 1 write byte of data. Therefore, the correct timing is: write 1 byte first, then read 1 byte; write 1 byte again, then read 1 byte, and repeat. If the number of bytes to be read is more than the valid write bytes, write 0 data instead (null write).
0 Preface
Many thermostats still use the traditional temperature measurement circuit structure: sensor → filter → preamplifier 1 → sensor type switching → preamplifier 2 → filter → ADC → MCU processing. Moreover, ADCs are usually integrated in MCUs, which not only have low resolution (mostly 12 bits or less), but the reference power supply is often immutable. This kind of structure has many components and high noise, and is not suitable for high-precision measurement and control. Taking thermocouples as an example, within the range of 0 ~ 661 °C, the resolution is difficult to exceed 0.1 °C. The accuracy is difficult to exceed 0.5%image.png (1631081939725930.png is the absolute value of the temperature, the unit is °C). In recent years, many IC companies have integrated the above-mentioned traditional temperature measurement structures and launched high resolutions (16-bit, 20-bit and 24-bit) for weak sensor signals at the microvolt level such as thermocouples. And there are multi-channel ADCs, such as LTC2486. This provides a good choice for the high-precision temperature measurement design of the thermostat.
1: High-precision temperature measurement circuit design
1.1 Circuit structure
Figure 1 shows a more conventional design, which is relatively simple. Without special signal amplification and channel switching circuits, the filter circuit is also the simplest first-order passive RC.
1.2 Temperature sensor
Usually, the thermostat requires two major types of sensors, thermocouples (TC) and resistors (RTD).
Figure 1 Thermostat high-precision temperature measurement circuit structure
1.2.1 Thermocouple
The latest international standard for thermocouples is the 2013 version of IEC60584-1:2013, and the equivalent (IDT) national standard is GB/T1639.1-2018[4]. The standard divides thermocouples into multiple types (E, K, J, etc.), among which type E has the highest sensitivity [3]. It is suitable for relatively high-precision temperature measurement. From a high-precision perspective, type E should be purchased with Class 1 error (0.004 for −40 to 800 °C temperature) [4], sheath and junction isolation [3] but connected to the shield for differential connection and Reduce noise.
1.2.2 RTD
In thermostats, this generally refers to Pt100, the current international standard is IEC 60751:2008, and the equivalent national standard is GB/T30121-2013. The formula of Pt100 thermal resistance is as follows [5]
Among them, the unit of t is °C; Rt is the resistance of Pt100; R0 is the resistance of Pt100 at 0 °C (100 Ω) [5] (the same below).
The error (or tolerance) level of Pt100 is divided into 4 levels [5]. Here we choose the highest level AA (±(0.1+ 0.001 7) (at −50 ~ 250 °C); or level A (the next highest level, ±( 0.15 + ) at −100 ~ 450 °C).
1.3 Detecting temperature signals
1.3.1 Thermocouple
1) Low pass filtering
Since it is a voltage signal, it can be directly connected to the differential input of the LTC2486 (CH2-CH3) after simple first-order RC low-pass filtering, as shown in Figure 2. filter cutoff frequency
Figure 2 Temperature detection and ADC circuit diagram
2) Cold end (also called reference end [4]) compensation thermocouple temperature measurement needs to solve a cold end compensation problem. The specific steps are:
① Use a high-precision temperature measurement chip to measure the cold end temperature tcj of TC [6].
② Due to the non-complete linear relationship of temperature ↔ voltage, tcj must be restored to voltage Vcj [3] using a linear interpolation algorithm on an E-type scale [4].
③ Add Vcj to the TC's output voltage Vtc as part of the TC's output voltage.
In addition to Si7051, the temperature measurement chip can also choose TMP275 (resolution up to 0.065 °C) and ADT7410 (0.007 8 °C).
3) Output voltage range. For type E thermocouple, in the temperature measurement range of −68 ~ 661 °C, check the graduation table [4], the corresponding voltage (Vi) range is −3.711 ~ 49.997 mV. In order to improve the resolution, the range can be reduced and the GAIN can be increased. See 1.4 for the definitions of FS and GAIN.
In Figure 2, the "M" in the thermocouple symbol represents the shielding end.
1.3.2 Pt100
It is necessary to convert the non-electrical resistance into a voltage signal. The lead error of the second-line Pt100 cannot be eliminated, and the temperature measurement deviation is large (when r = 0.225 Ω, it is about 1 ~ 1.5 °C). A three-wire Pt100 unbalanced resistor bridge is shown in Figure 3 (or Figure 2). is the lead resistance. is a fixed resistance; ΔR represents the temperature change relative to R0, which is positive or negative; Vcb is the bridge power supply; Vb is the bridge voltage when unbalanced. The three-wire Pt100 bridge has controllable lead error.
In this thermostat design, the temperature measurement range is divided into two levels according to the accuracy:
①(−68 ~ 68) °C, resolution 0.001 °C;
②(−68 ~ 466) °C, resolution 0.007 °C.
However, in the following design discussion, only ① is taken as an example.
Figure 3 Three-wire Pt100 resistance bridge analysis model
1.3.2.1 Bridge design
1) Resistor selection
① Actual measurement shows that the resistance of the 2 m long Pt100 lead is r = 0.225Ω. According to the requirement of within 20 m, it is about 2.25 Ω. According to formula (4) again, R1 and R2 are required to be more than one thousand times of r to reduce the lead error. So take image.png= ≥2.25 kΩ;
②The current (I p ) flowing through Pt100 should not be greater than 1 mA [5] to control self-heating. But it cannot be too small, otherwise it will affect the sensitivity of the bridge resistance measurement. The actual value is I p = (1 ~ 2) mA;
③The greater the resistance, the greater the noise [8]. From this perspective, the smaller the resistance, the better;
④The bridge should remain balanced (Vb = 0) at 0 °C. Requirements:
⑤ Consider that Vcb is generated by TL431, so select Vcb ≥ 2.5 V (see below). Based on the above four points, R1=R2= 2 400 Ω. Combining formula (3), we have
R1 ~ R3 use chip resistors with an accuracy of 0.01% and a temperature coefficient of 5×10−6/°C (about 0.45 yuan/piece in batches). This requirement is very important.
2) Vcb selection and bridge voltage output range selection
It can be seen from equation (9) that the selection of Vcb is related to the temperature measurement range (ΔR), bridge voltage Vb range, and bridge resistance selection. In the measurement range ①, when ΔR = 26.31Ω, if (4 is GAIN) is selected, at this time, according to equation (9) Vcb = 5 000 mV, and then from equation (9) we can get: at −68 °C, Vb = −52.2 mV, so the range of Vb is (−52.2 ~ 50) mV. The bridge voltage Vb is also low-pass filtered (R89, R90, C26 and C33) before entering the differential channel (CH0-CH1) of the ADC.
1.3.2.2 Three-wire bridge error analysis[10]
Assume first, and according to equation (6), then the bridge pressure is:
When the lead resistance image.png also considers equation (3), then the bridge voltage:
in,
It can be assumed that:
Then r in the addition term of Vbr and VG can be ignored, so we have
Consider another 2 factors for VG:
Available:
In order to ensure that the temperature measurement resolution is higher than 0.001, it is required that in formula (4b)
This can be done in practice. In this way, the following formula (4a) can be obtained:
At this time the relative error
Equation (6) shows that ① ε can be positive or negative, because ΔR and ΔR can be positive or negative; ② The smaller ΔR is, that is, the closer the temperature is to 0 °C, the larger the relative error ε is; ③ According to equation (3a), ε = 0 .
The above two points ① and ② are consistent with general perceptual understanding.
The current example is as follows: As mentioned above, when 2m long, the lead resistance r = 0.225Ω, if ΔR = 0.195 (corresponding to Ω temperature 0.5 °C), and let R1 = 2402 Ω, R2 = 2400 Ω, then the formula ( 3),
This relative error is very small, and after the temperature is higher than 0.5 °C, the error will gradually decrease again. Based on the above, as long as formula (3a) is satisfied, the influence of lead resistance r can be reduced to within 100%, or even smaller (designed according to actual needs).
The analysis conditions pointed out in reference [10] are different from this. Is it better to change to equation (3a)?
It is important to note that if the resistances of the three wires are unequal (which exists in practice), errors will be introduced. At this time, the three-wire circuit here cannot completely solve the problem. Therefore, when purchasing, you must make a request to the supplier that the three lines are equal.
1.4 Selection and use of ADC
The choice of LTC2486 (referred to as 2486) is mainly due to the following four reasons [1].
①High comprehensive resolution and small error. It is nominally 16 bits, but actually has a resolution of 17 bits (including the sign bit). Ideally, 1 μV voltage can be resolved.
② There are 2 differential channels, which just meet the input requirements of thermocouples and Pt100 of general thermostats, without the need for additional switching circuits (which will introduce noise errors).
③There is a built-in programmable gain amplifier (PGA, 1 ~ 256, divided into 8 levels).
④ Low noise and small error.
1.4.1 ADC application circuit design
The interface circuit between LTC2486, sensor and STM32F103 is shown in Figure 2.
1) Vcc and REF +, REF − voltage design
① Considering the low power consumption (0.8 mW) and accuracy of 2486, Vcc is selected
Choose to be powered by the reference voltage, TL431 generates output via 5 V;
② Define ADC_Data as conversion data; GAIN as internal gain value; Vref as reference voltage; Fs as full-scale voltage, Fs = 0.5Vref[1].
Generally, conversion errors (offset, nonlinearity, etc.) are ignored, and the conversion data is inversely proportional to Vref, that is, ADC_Data. In this way, the smaller the Vref, the smaller the voltage that the LSB can resolve. But Vref cannot be too small, not less than 400 mV [8]. Here take REF+ = 400 mV.
③ The reference positive power supply (REF+) of 2486 is generated by the higher precision chip (0.5%) LT6650. When the input of this chip is 5 V, the output can be adjusted (0.4~4) V.
④ REF- Ground. Vref = REF + −REF− = 400 mV, Fs =200 (mV).
2) Selection of GAIN
In order to achieve full-scale conversion (positive conversion data reaches 0×10000), for thermocouples, follow Section 1.3.1, GAIN ≈ 4, take 4 pairs of Pt100, follow Section 1.3.2, GAIN = 4. Note that the larger the value of GAIN, the greater the noise [1], and the greater the fluctuation of the ADC_Data value. The selection of GAIN can be achieved through the buttons of the controller.
3) Interface with STM32F103 (F103 for short)
Interface with F103 through four-wire SPI.
① Bidirectional mode, F103 is the master and 2486 is the slave;
② F103 uses 3.3V working voltage, while 2486 uses 5V, and there must be level conversion in the middle. For this reason, the output signal (MOSI, SCK, NSS) of F103 should be set to open circuit (OD), and the pull-up resistor is (3.3 ~ 5.1) kΩ; while the output signal SDO of 2486 should be divided to 3.3 V by a resistor and then connected MISO to F103. as shown in picture 2.
2 Programming
Conducted under IAR version 7.20.5.624. Use the latest version 3.5.0 [9] library function released in 2011.
2.1 F103 and LTC2486 interface programming
2.1.1 SPI initialization function
1) Procedure
void SPI2_Init(void)
{
Refer to library function programming. Just pay attention to setting PB13 and PB15 lines as multiplexed open-drain outputs. This method is for level conversion between F103 and 2486.
GPIO_InitStructure.GPIO_Pin_13|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_
OD;}
2.1.2 Write a byte data function to 2486
1) Procedure
void SPI2_reg_write(u8 data)
{
① SPI2->DR = data; // Put the data into the data register of the SPI2 port and send it out;
② while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_
FLAG_RXNE) == RESET);
}
2) Program notes
Statement ② determines whether writing one byte of data is successful. There are many similar statements in SPI and I 2C library functions, which must be understood. Due to space limitations, no further introduction is given here. For details, please refer to references [9] and [13].
2.1.3 Read 1 byte of data from 2486
Just read it directly from the data register of SPI2 port. No functions are used. That is: b = SPI 2→ DR; b is an unsigned byte variable.
2.1.4 Read the conversion data function of 2486
1) Algorithm
Before reading data, the working mode of 2486 must be set (written) first. Different requirements require different settings. This is just one example. Note the use of default values.
①The data conversion rate of 2486 is usually selected to be 6 times/s. 12 times/s can also be selected, but this will reduce the accuracy [1] and is generally not selected.
②Select the conversion channel. Choose between 4 single-ended or 2 differential channels.
③Select GAIN value. Make different selections as described in 1.4.1.
After this, the data can be read.
④ 2486 will output 1 bit low level on the SDO pin when the conversion is completed, which can be used as the conversion end flag (ie EOC signal) to judge, generally using the query method.
⑤ 2486 will output 3 8-bit bytes of data after each conversion. Each output byte is synchronized with 1 write byte of data. Therefore, the correct timing is: write 1 byte first, then read 1 byte; write 1 byte again, then read 1 byte, and repeat. If the number of bytes to be read is more than the valid write bytes, write 0 data instead (null write).