Fault Detection Method for 18B20 Temperature Sensor

Through the delay and state reading method based on the 1-Wire protocol, the problem of short-circuit fault detection of the DQ pin of the 18B20 temperature sensor is solved, and accurate fault detection and memory optimization are achieved.

CN119666197BActive Publication Date: 2025-04-18SHENYANG ANFEI TECH
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510174120.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-02-18
Publication Date
2025-04-18
Estimated Expiration
2045-02-18

AI Technical Summary

Technical Problem

The prior art is difficult to effectively detect the short circuit failure of the DQ pin of the 18B20 temperature sensor to the power supply positive VCC or the power supply ground GND, resulting in data reading errors and occupying a lot of microcontroller memory.

Method used

The fault detection method based on the 1-Wire protocol is adopted, and by defining variables and performing delay and state reading, the time length specified by the 1-Wire protocol is used to determine the fault to reduce memory usage.

Benefits of technology

Accurate detection of short circuit faults of the 18B20 temperature sensor DQ pin is achieved, preventing data errors and reducing the use of microcontroller memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119666197B_ABST
    Figure CN119666197B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of temperature detection technology, and in particular to a fault detection method for an 18B20 temperature sensor. By using the time length of each step specified in the 1-Wire (single bus) protocol as the basis for fault judgment, the purpose of detecting two faults of the DQ pin of the 18B20 being short-circuited to the positive power supply VCC or the power supply ground GND is achieved, thereby preventing the reading of erroneous data. In addition, since only one variable is used to count and judge the subsequent multiple steps, the occupancy of the single-chip computer memory when executing the method can be minimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of temperature detection, and in particular to a fault detection method for an 18B20 temperature sensor. Background Art

[0002] 18B20 is a commonly used digital temperature sensor, which outputs digital signals and has the characteristics of small size, low hardware cost, strong anti-interference ability and high precision. 18B20 digital temperature sensor is easy to wire and can be used in many occasions after packaging.

[0003] 18B20 uses 1-wire (single bus) bus protocol for communication, and data input and output can be completed with only one DQ pin.

[0004] 1-Wire (single bus) protocol is a half-duplex, serial communication protocol, mainly used for data exchange with various low-cost sensors and storage devices. 1-Wire (single bus) adopts a master-slave architecture, and one master device can connect to multiple slave devices.

[0005] Since the 1-wire (single bus) bus also requires each device to be connected in open-drain mode, the DQ signal line also needs to use a pull-up resistor.

[0006] 18B20 must be connected to a microcontroller controller to implement 1-Wire (single bus) protocol for data exchange. There are two ways to connect 18B20 to a microcontroller controller: Figure 1 and Figure 2 As shown, Figure 1 The three-wire connection method is shown. Figure 2 The two-wire connection method is shown.

[0007] The core components of the single-chip controller are all made by mounting electronic components on printed circuit boards using surface welding assembly technology. During the manufacturing process, there may be problems such as component mounting errors, tin leakage, and wrong connections, which may cause the DQ pin of 18B20 to short-circuit the positive power supply VCC or the power supply ground GND, causing hardware connection failures.

[0008] In addition, since 18B20 is mostly used in temperature measurement applications far away from the microcontroller controller, it requires longer external leads. There is also a short circuit problem between the leads, causing the DQ pin of 18B20 to be short-circuited to the positive power supply VGG or the power ground GND, resulting in hardware connection failure.

[0009] The above two faults of the DQ pin of 18B20 shorting to the positive power supply VGG or shorting to the power supply ground GND will affect the normal use of 18B20. The above two faults must be detected during use, and then the fault information is processed accordingly through the single-chip controller. In addition, since the single-chip controller has less memory, the memory usage of the single-chip controller should be minimized when solving the above technical problems.

[0010] In the prior art:

[0011] CN 219678491 U records a networking device for 18B20 temperature probes, including a box body, on which an import terminal, an export terminal and a plurality of plug connection terminals are fixedly arranged, wherein the import terminal, the export terminal and the plurality of plug connection terminals are all three-port connection terminals, wherein the first interface of the import terminal is connected to the third interface of the export terminal through a first wire, and the second interface of the import terminal is connected to the second interface of the export terminal through a second wire. By arranging the import terminal, the export terminal and the plurality of plug connection terminals on the box body, and then arranging matching resistors between the positive power supply electrodes and the signal lines of the import terminal and the export terminal, and then connecting the interfaces of the various terminals, the galaxy connection of the various 18B20 temperature probes is realized, and the import terminal and the export terminal on each box body can be further connected to form a cascade, thereby greatly improving the connection effect of the 18B20 temperature probe and ensuring the efficiency of the connection data transmission. However, there is no record of a fault detection method for the 18B20 temperature sensor.

[0012] CN 207395210 U records an electric water heater control system with temperature sensor fault detection, including: an electric water heater control system and a temperature sensor detection circuit; the electric water heater control system includes a single chip microcomputer, a thermal circuit breaker, a relay and a temperature sensor connected to the single chip microcomputer; the temperature sensor detection circuit is connected between the power supply I / O port of the single chip microcomputer and the detection I / O port and the thermistor of the temperature sensor; after the single chip microcomputer is powered on, a high level is given to the power supply I / O port to energize the temperature sensor detection circuit, and the current passes through the thermistor to GND, the detection I / O port is used to read the voltage on the thermistor, and the single chip microcomputer converts the temperature value according to the detected voltage value to detect the temperature sensor fault. When the temperature sensor has a fault in which the temperature probe resistance value remains unchanged, the electric water heater control system disconnects the electric heater of the electric water heater to ensure the safety of the user. However, this technical solution can only be used for thermistor fault detection, and cannot be used for 18B20.

[0013] CN 118960999 A records a method, device, equipment and storage medium for monitoring faults of temperature sensors. The monitoring method includes: obtaining model information, acquisition cycle, working environment temperature range, initial temperature and current temperature in the nth monitoring; wherein n is a positive integer; determining a standard temperature threshold according to the model information, acquisition cycle and working environment temperature range; determining a temperature change value according to the initial temperature and the current temperature; and outputting a temperature sensor fault signal when the temperature change value is greater than or equal to the standard temperature threshold. The technical scheme of the present invention determines the standard temperature threshold according to the model information, acquisition cycle and working environment temperature range, determines the temperature sensor fault when the temperature change value is greater than or equal to the standard temperature threshold, and determines the temperature sensor fault in real time in combination with the model and working environment of the temperature sensor, thereby improving the reliability and accuracy of the temperature sensor fault monitoring. However, the technical scheme is a fault detection method based on the change in the value of the continuous output of the sensor, and its judgment result has obvious hysteresis, and is powerless for faults with insignificant jump changes in the output value. Summary of the invention

[0014] In view of the problems existing in the prior art, the purpose of the present invention is to provide a fault detection method for 18B20 temperature sensor, which is used to detect two faults of the DQ pin of 18B20 being short-circuited to the positive power supply VCC or the power supply ground GND, so as to prevent reading of erroneous data. In addition, the occupancy of the microcontroller memory when executing the method should be minimized.

[0015] The technical solution of this application is as follows:

[0016] A fault detection method for an 18B20 temperature sensor, comprising:

[0017] S1: define a variable and clear it to zero;

[0018] S2: pull down the DQ pin;

[0019] S3: first delay;

[0020] S4: pull up the DQ pin;

[0021] S5: second delay;

[0022] S6: Read the DQ pin status, if it is high, continue to execute S7, otherwise execute S61;

[0023] S61: Execute S62 after the variable is incremented by 1;

[0024] S62: If the variable is less than the first specified preset value, go to execute S5, otherwise execute S63;

[0025] S63: Return fault information: DQ pin is short-circuited to GND, and terminate this method;

[0026] S7: clear the variable to zero;

[0027] S8: third delay;

[0028] S9: Read the DQ pin status, if it is low, continue to execute S10, otherwise execute S91;

[0029] S91: Execute S92 after the variable is incremented by 1;

[0030] S92: If the variable is less than the second specified preset value, go to execute S8, otherwise execute S93;

[0031] S93: Return fault information: DQ pin is short-circuited to VCC, and terminate this method;

[0032] S10: clear the variable;

[0033] S11: fourth delay;

[0034] S12: Read the DQ pin status, if it is high, continue to execute S13, otherwise execute S121;

[0035] S121: Variable is incremented by 1 and then S122 is executed;

[0036] S122: If the variable is less than the third specified preset value, go to execute S11, otherwise execute S123;

[0037] S123: Return fault information: DQ pin is short-circuited to GND, and terminate this method;

[0038] S13: Return information: This judgment is normal, and end this method.

[0039] Among them, the delay ranges of the first delay, the second delay, the third delay, and the fourth delay are all greater than 1 and less than 1000 microseconds; the ranges of the first specified preset value, the second specified preset value, and the third specified preset value are all greater than 1 and less than 255.

[0040] In the above method:

[0041] A variable is defined in S1 for counting the subsequent steps of this method. By using the variable time-sharing multiplexing method, only this one variable is used to count and judge the subsequent multiple steps, which can minimize the occupancy of the microcontroller memory when executing this method.

[0042] Steps S2 to S4 send a reset pulse that complies with the 1-Wire (single bus) protocol to the 18B20. If there is no fault, the 18B20 can be reset.

[0043] Steps S5~S6 and S61~S63 are used to detect whether the DQ pin can be pulled up to a high level by the pull-up resistor within the time obtained by multiplying the second delay time and the first specified preset value; if so, continue with the subsequent steps, otherwise return a fault message and end the method.

[0044] Steps S7~S9 and S91~S93 are used to detect whether the DQ pin can be pulled to a low level by the response signal of 18B20 within the time obtained by the product of the third delay time and the second specified preset value; if so, continue with the subsequent steps, otherwise return a fault message and end the method.

[0045] Steps S10~S13 and S121~S123 are used to detect whether the DQ pin can be pulled up to a high level by the pull-up resistor within the time obtained by the product of the fourth delay time and the third specified preset value; if so, normal information is returned and the method is terminated; otherwise, fault information is returned and the method is terminated.

[0046] Preferably, in the above method, the first delay time is 750 microseconds. The reason for selecting this value is based on the requirement of the 1-Wire (single bus) protocol for the time length of the reset pulse sent by the master device.

[0047] Preferably, in the above method, the second delay time is 2 microseconds, and the first specified preset value is 50. The reason for selecting this value is based on the requirement for the waiting time length of the slave device in the 1-Wire (single bus) protocol.

[0048] Preferably, in the above method, the third delay time is 2 microseconds, and the second specified preset value is 250. The reason for selecting this value is based on the requirement for the pulse time length of the slave device response signal in the 1-Wire (single bus) protocol.

[0049] Preferably, in the above method, the fourth delay time is 2 microseconds, and the third specified preset value is 150. The reason for selecting this value is based on the requirement for the waiting time length of the master device in the 1-Wire (single bus) protocol.

[0050] By adopting the above technical scheme, a fault detection method for an 18B20 temperature sensor is provided. Since the time length of each step specified in the 1-Wire (single bus) protocol is used as the basis for fault judgment, the purpose of detecting two faults of the DQ pin of the 18B20 being short-circuited to the positive power supply VCC or the power supply ground GND is achieved, thereby preventing the reading of erroneous data.

[0051] In addition, since only one variable is used to count and judge the subsequent multiple steps, the occupancy of the microcontroller memory when executing the method can be minimized. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 is a circuit diagram of the connection between 18B20 and the microcontroller controller using a three-wire connection method.

[0053] Figure 2 is a circuit diagram of the connection between 18B20 and the microcontroller controller using a two-wire connection method.

[0054] FIG3 is a flow chart of the technical solution of the present invention, and the step numbers in the figure are consistent with those described in the content of the invention. DETAILED DESCRIPTION

[0055] The specific embodiments of the present invention are described in detail below. It should be understood that the specific embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention. Specific embodiment 1:

[0057] This embodiment shows: when 18B20 is connected to the single-chip microcomputer controller using a three-wire connection method, the specific implementation method of the present invention.

[0058] according to Figure 1 After the circuit is connected, the method described in the present invention can be implemented by programming the single chip controller.

[0059] The single-chip microcomputer model in the single-chip microcomputer controller used in this embodiment is STC8H1K28, and the control program is written in the C language environment.

[0060] in:

[0061] Step S1 is implemented by the following code, wherein variable i is the variable described in the method of the present invention:

[0062] unsigned char i=0;

[0063] Step S2 is implemented by the following code:

[0064] DQ=0;

[0065] Step S3 is implemented by the following code:

[0066] Delay750us();

[0067] Step S4 is implemented by the following code:

[0068] DQ=1;

[0069] Step S5 is implemented by the following code:

[0070] S5:Delay2us();

[0071] Steps S6 and S61-S63 are implemented by the following code snippet, with the specific step numbers marked in the form of comments after the code; the value 3 returned in step S63 is the information agreed by the program that the DQ pin is short-circuited to GND:

[0072] if(DQ==1) / / S6

[0073] {}

[0074] else

[0075] {

[0076] i++; / / S61

[0077] if(i<50)goto S5; / / S62

[0078] else return 3; / / S63

[0079] }

[0080] Step S7 is implemented by the following code:

[0081] i=0;

[0082] Step S8 is implemented by the following code:

[0083] S8:Delay2us();

[0084] Steps S9 and S91-S93 are implemented by the following code snippet, with the specific step numbers marked in the form of comments after the code; the value 4 returned in step S93 is the information agreed by the program that the DQ pin is short-circuited with VCC:

[0085] if(DQ==1) / / S9

[0086] {}

[0087] else

[0088] {

[0089] i++; / / S91

[0090] if(i<250)goto S8; / / S92

[0091] else return 4; / / S93

[0092] }

[0093] Step S10 is implemented by the following code:

[0094] i=0;

[0095] Step S11 is implemented by the following code:

[0096] S11:Delay2us();

[0097] Steps S12 and S121-S123 are implemented by the following code snippets, with specific step numbers annotated after the code; the value 3 returned in step S123 is information agreed upon by the program that the DQ pin is short-circuited to GND; the value 0 returned in step S13 is information agreed upon by the program that the current judgment is normal:

[0098] if(DQ==1) / / S12

[0099] {

[0100] return 0; / / S13

[0101] }

[0102] else

[0103] {

[0104] i++; / / S121

[0105] if(i<150)goto S11; / / S122

[0106] else return 3; / / S123

[0107] } Specific embodiment 2

[0109] This embodiment shows: when 18B20 is connected to the single-chip microcomputer controller using a two-wire connection method, the specific implementation method of the present invention.

[0110] according to Figure 2 After the circuit is connected, the method described in the present invention can be implemented by programming the single chip controller.

[0111] The running procedure is the same as that of the specific embodiment 1. It should be noted that: since there is no VCC connection in the two-wire connection method, it does not affect the operation and judgment of the method described in the present invention.

[0112] The embodiments of the present invention disclosed above are only used to help illustrate the present invention. The embodiments do not describe all the details in detail, nor do they limit the invention to specific implementation methods. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes this embodiment in order to better explain the principles and practical applications of the present invention, so that those skilled in the art can understand and use the present invention well.

Claims

1. A fault detection method for an 18B20 temperature sensor, characterized in that ,include: S1: define a variable and clear it to zero; S2: pull down the DQ pin; S3: first delay; S4: pull up the DQ pin; S5: second delay; S6: Read the DQ pin status, if it is high, continue to execute S7, otherwise execute S61; S61: Execute S62 after the variable is incremented by 1; S62: If the variable is less than the first specified preset value, go to execute S5, otherwise execute S63; S63: Return fault information: DQ pin is short-circuited to GND, and terminate this method; S7: clear the variable to zero; S8: third delay; S9: Read the DQ pin status, if it is low, continue to execute S10, otherwise execute S91; S91: Execute S92 after the variable is incremented by 1; S92: If the variable is less than the second specified preset value, go to execute S8, otherwise execute S93; S93: Return fault information: DQ pin is short-circuited to VCC, and terminate this method; S10: clear the variable; S11: fourth delay; S12: Read the DQ pin status, if it is high, continue to execute S13, otherwise execute S121; S121: Variable is incremented by 1 and then S122 is executed; S122: If the variable is less than the third specified preset value, go to execute S11, otherwise execute S123; S123: Return fault information: DQ pin is short-circuited to GND, and terminate this method; S13: Return information: This judgment is normal, and the method ends; Among them, the delay ranges of the first delay, the second delay, the third delay, and the fourth delay are all greater than 1 and less than 1000 microseconds; the ranges of the first specified preset value, the second specified preset value, and the third specified preset value are all greater than 1 and less than 255.

2. A fault detection method for an 18B20 temperature sensor according to claim 1, characterized in that: The first delay time is 750 microseconds.

3. A fault detection method for an 18B20 temperature sensor according to claim 1 or 2, characterized in that: The second delay time is 2 microseconds, and the first specified preset value is 50.

4. A fault detection method for an 18B20 temperature sensor according to claim 1 or 2, characterized in that: The third delay time is 2 microseconds, and the second specified preset value is 250.

5. A fault detection method for 18B20 temperature sensor according to claim 1 or 2, characterized in that: The fourth delay time is 2 microseconds, and the third specified preset value is 150.

Citation Information

Patent Citations

  • Temperature sensor fault monitoring method, device and equipment and storage medium

    CN118960999A

  • Take temperature sensor fault detection's electric water heater control system

    CN207395210U

  • Networking device of 18B20 temperature probe

    CN219678491U

  • Online controllable sensing node positioning method

    CN102209110A

  • Bus-based fault positioning and loop detection method, apparatus, system and device

    CN108234232A