Method for reducing driving delay of DS18B20 digital temperature sensor, medium and terminal
By turning on the hardware timer interrupts in the MCU and dispersing timing operations, the problem of excessive delay in the drive of the DS18B20 digital temperature sensor is solved, which improves system practicality and resource utilization, reduces software delays and reduces costs.
Patent Information
- Application Number
- CN202410876613.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-11-01
AI Technical Summary
In the prior art, the driving delay time of the DS18B20 digital temperature sensor is too long, resulting in low system practicality and high processor computing resource share, especially in multiple sensor applications that affect the system real-time and waste resources.
By turning on the hardware timer interrupt in the MCU, all operations are performed in the timer interrupt service function, and the timing operation is completed using the timer overflow time T (set to 60μs~120μs). The timing set is distributed at the time of the timer interrupt, reducing the Software delay ensures that each timing operation accurately lands at the timer interrupt moment and exits the interrupt in time to release resources.
It effectively shortens the driving delay of the digital temperature sensor, improves the practicality of the system, saves processor computing resources, reduces the proportion of software delay, avoids the impact on the real-time nature of the system, and reduces costs.
Smart Images

Figure CN118885264A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of temperature sensors, and in particular relates to a method, a medium and a terminal for reducing the driving delay of a DS18B20 digital temperature sensor. Background Art
[0002] The DS18B20 digital temperature sensor is widely used in various devices that need to collect temperature due to its high precision, no need for calibration, small temperature drift, and simple use. The temperature sensor is a 3-pin package, namely VCC / GND / DATA, VCC is the positive power supply, GND is the negative power supply and also serves as a signal reference, DATA is the data pin, and each temperature sensor has its own address (8 bytes).
[0003] In the prior art, the timing set required to read the temperature data of a sensor requires at least 1 reset timing (960us) plus writing 10 bytes (10*8*60us=4.8ms) plus reading 9 bytes (9*8*60us=4.32ms). The total delay time required for the timing set is 0.96+4.8+4.32=10.08ms. Due to the strict requirements on the time of the operation timing, each timing operation in this timing set of about 10ms cannot exceed its specified time range. This can be achieved by using a software delay function, and interrupts need to be turned off in this timing set of about 10ms to ensure that the timing operation is not interrupted by other programs and cause errors. In general applications, a 10ms delay may not have much impact, but if there are multiple temperature sensors in the application, the delay time will increase by the same multiple, which will affect the real-time performance of the entire system and waste processor computing resources. The patent with announcement number CN112212992B provides a low-power, low-voltage digital temperature sensor, which obtains temperature information through the frequency ratio of the first oscillation signal output by the first ring oscillator and the second oscillation signal output by the second ring oscillator. The first ring oscillator additionally uses a MOS varactor as a load capacitor, and uses the voltage characteristics of the MOS varactor to reduce the sensitivity of power supply voltage fluctuations. It is suitable for low-power and low-voltage environments. At the same time, the low-power, low-voltage digital temperature sensor also has the advantages of small size, high digitization, and self-reference. The digital temperature sensor in this patent only reduces power consumption, and then does not provide relevant technical solutions for how to reduce driving delay.
[0004] Therefore, how to provide a method for reducing the driving delay of the DS18B20 digital temperature sensor to improve system practicality and reduce the processor computing resource occupancy rate is an urgent problem to be solved by personnel in this technical field. Summary of the invention
[0005] In view of the deficiencies in the prior art, the purpose of the present invention is to provide a method for reducing the driving delay of a DS18B20 digital temperature sensor, so as to solve the problem in the prior art that the digital temperature sensor has low system practicality and high resource occupancy rate due to excessive delay time; in addition, the present invention also provides a medium and a terminal for reducing the driving delay of a DS18B20 digital temperature sensor.
[0006] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0007] In a first aspect, the present invention provides a method for reducing a DS18B20 digital temperature sensor driving delay, comprising the following steps:
[0008] S10, MCU turns on the hardware timer interrupt, all operations are executed in the timer interrupt service function, and the timer overflow time is set to T;
[0009] S20, reset sequence: the host pulls down the bus and releases the bus after at least 480μs. The next interrupt confirms the slave pulse, and this sequence ends after at least (480-T)μs.
[0010] S30, write 1 timing: the host pulls down the bus, delays 2μs to release the bus, and this timing ends after the next interrupt;
[0011] S40, write 0 timing: the host pulls down the bus, and this timing ends after the next interruption, and the bus is released at the same time;
[0012] S50, read timing: the host pulls down the bus, delays 2μs to release the bus, and then delays 8μs to read the level status. This timing ends after the next interrupt;
[0013] S60, end sequence: the operation is completed, and the host sets the bus to a high level.
[0014] Furthermore, in the interrupt service function, the operation on the DATA pin is completed, and after the interrupt is exited, the MCU resources are released to process other services.
[0015] Furthermore, each timing operation ends at the T timer interruption moment. A basic timing includes one or several timer terminals. In the program, multiple terminals are combined into a single timing through state quantities.
[0016] Furthermore, the coherent timing set is broken up so as to be dispersed at the next timer interrupt moment starting from the instruction and ending at the next timer interrupt moment ending from the instruction.
[0017] Furthermore, the DATA pin level is operated at each timer interrupt moment, and the pin level state is maintained before the next timer interrupt moment comes. After the operation is performed at the timer interrupt moment, the interrupt is exited and the MCU runs other services.
[0018] Furthermore, the write 1 timing has a delay of 2 μs, and the read timing has a delay of 10 μs.
[0019] Furthermore, in step S10, the timer overflow time T ranges from 60 μs to 120 μs.
[0020] Furthermore, the timer overflow time T is 100 μs. In the reset sequence, the host pulls down the bus and releases the bus after 500 μs. The next interrupt confirms the slave pulse, and this sequence ends after 400 μs.
[0021] In a second aspect, the present invention further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program implements the above method when executed by a processor.
[0022] In a third aspect, the present invention further provides an electronic terminal, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the terminal executes the method as described above.
[0023] Compared with the prior art, the method, medium and terminal for reducing the driving delay of the DS18B20 digital temperature sensor provided by the present invention have at least the following beneficial effects:
[0024] There are multiple temperature sensors in the application of the prior art, and the delay time increases exponentially. There is a lack of effective methods to reduce the driving delay, which affects the real-time performance of the entire system and wastes processor computing resources. The present invention has a simple process and convenient operation. By removing the delay to the maximum extent, only the real timing operation and the necessary short delay are left. In the single instruction timing set, although the timing cycle span of the single instruction will be lengthened, the proportion of software delay is greatly reduced, which solves the delay in the single-bus digital temperature sensor instruction operation timing set, so that the instruction operation of the digital temperature sensor is integrated into other programs, and one or more sensors are not affected, and the real-time performance of the entire system is not affected. There is no need to add an additional processor or change the temperature acquisition scheme. The reduced software delay saves computing resources and reduces costs. The saved time can be used to perform other tasks, improving the work efficiency of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the scheme of the present invention, a brief introduction is given below to the figures required for use in the description of the embodiments. Obviously, the figures described below are some embodiments of the present invention. For ordinary technicians in this field, other figures can be obtained based on these figures without paying any creative work.
[0026] Figure 1 A flow chart of a method for reducing the driving delay of a DS18B20 digital temperature sensor provided by an embodiment of the present invention;
[0027] Figure 2 It is a schematic diagram of the delay of a single instruction timing set of a digital temperature sensor in the prior art;
[0028] Figure 3 A schematic diagram of a single instruction timing set delay for a method of reducing a DS18B20 digital temperature sensor drive delay provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to facilitate the understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings. The preferred embodiments of the present invention are given in the drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive.
[0030] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0031] The present invention provides a method for reducing the driving delay of a DS18B20 digital temperature sensor, comprising the following steps:
[0032] S10, MCU turns on the hardware timer interrupt, all operations are executed in the timer interrupt service function, and the timer overflow time is set to T;
[0033] S20, reset sequence: the host pulls down the bus and releases the bus after at least 480μs. The next interrupt confirms the slave pulse, and this sequence ends after at least (480-T)μs.
[0034] S30, write 1 timing: the host pulls down the bus, delays 2μs to release the bus, and this timing ends after the next interrupt;
[0035] S40, write 0 timing: the host pulls down the bus, and this timing ends after the next interruption, and the bus is released at the same time;
[0036] S50, read timing: the host pulls down the bus, delays 2μs to release the bus, and then delays 8μs to read the level status. This timing ends after the next interrupt;
[0037] S60, end sequence: the operation is completed, and the host sets the bus to a high level.
[0038] The present invention effectively shortens the driving delay of the digital temperature sensor, improves the practicability of the system, and saves processor computing resources.
[0039] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.
[0040] The present invention provides a method for reducing the driving delay of a DS18B20 digital temperature sensor. In the instruction operation of the digital temperature sensor, most of the time is consumed in the delay. The delay is removed as much as possible, leaving only the real timing operation and the necessary short delay. The MCU needs to start the hardware timer interrupt, and all operations are executed in the hardware timer interrupt service function. The timer overflow time is assumed to be T. Considering avoiding invalid operations and meeting the timing requirements, and shortening the total duration of the entire timing set of instructions as much as possible, T should meet the following conditions (every time entering the interrupt, DATA can be operated, and the software delay in the interrupt reduces the occupation of processing resources as much as possible): T>60μs and T<120μs.
[0041] The invalid operation mentioned above means: for example, if T=1μs, then all the timing times that meet the requirements can definitely be combined, but obviously most of the timer interrupt functions perform no operations (the corresponding operation time is not met, resulting in immediate exit after entering the interrupt function). In this case, write 0 timing, DATA is at a low level from the first interrupt operation until the end of the 60th interrupt timing, and the 58 times of entering the interrupt function in the middle are all no operations.
[0042] Combination Figures 1 to 3 In this embodiment, taking T=100 μs as an example, the method for reducing the driving delay of the DS18B20 digital temperature sensor includes the following steps:
[0043] S10, MCU turns on the 100μs hardware timer interrupt, and all operations are executed in the 100μs timer interrupt service function;
[0044] S20, reset sequence: the host pulls down the bus, releases the bus after 500μs, confirms the slave pulse (host reads) after 100μs, and this sequence ends after 400μs;
[0045] S30, write 1 timing: the host pulls down the bus, delays 2μs to release the bus, and this timing ends after the next 100μs;
[0046] S40, write 0 timing: the host pulls down the bus, and this timing ends after the next 100μs, and the bus is released at the same time;
[0047] S50, read timing: the host pulls down the bus, delays 2μs to release the bus, and then delays 8μs to read the level status. After the next 100μs, this timing ends;
[0048] S60, end sequence: the operation is completed, and the host sets the bus to a high level.
[0049] Specifically, in this embodiment, the timer 100μs overflow interrupt is enabled, and timing operations are performed in the interrupt service function. The significance of enabling the timer interrupt is to provide accurate timing to meet strict timing requirements, and the operation on the DATA pin is completed in the interrupt service function. After exiting the interrupt, the MCU resources are released to process other tasks.
[0050] Furthermore, in this embodiment, four basic operation timing logics for the digital temperature sensor are modified so that these timing operations are not started at any time during the program execution, and each timing operation is accurately implemented at the time of the timer interrupt of 100μs. A basic timing is composed of one or several timer interrupts, and multiple interrupts are combined into a single timing through state quantities in the program.
[0051] Furthermore, in this embodiment, for any instruction that interacts with the temperature sensor, it is composed of a reset timing + several write timings + an end timing, or a reset timing + several read timings + an end timing, and this series of coherent timing sets are broken up (the existing software delay scheme is a coherent operation timing, and interruptions are not allowed) so that they are distributed at the next timer interrupt moment starting from the instruction and ending at the next timer interrupt moment when the instruction ends.
[0052] Furthermore, in this embodiment, the DATA pin level is operated at each timer interrupt moment (the write 1 timing requires a 2us delay, and the read timing requires a 10us delay), and the pin level state is maintained before the next timer interrupt moment arrives. After performing the necessary operations at the timer interrupt moment, the interrupt is exited and the MCU can run other tasks.
[0053] Specifically, in this embodiment, the reset timing consists of 10 timer interrupts. When the first timer interrupts, the bus is pulled low. The second, third, fourth, and fifth timer interrupts remain unchanged. The sixth timer interrupt host switches the DATA pin to the reading direction. The seventh timer interrupt reads the DATA pin level. The eighth, ninth, and tenth timer interrupts remain unchanged. The eleventh timer interrupt sets the DATA pin to a high level. At this point, the reset timing operation ends. In the timing process, after the timer interrupt operation is completed, one operation is completed, releasing the MCU processing resources.
[0054] Further, as a comparison, the current software delay scheme operation sequence is as follows: the host pulls down the DATA pin, the software delays 480μs, the switch pin is in the read state, the software delays 20μs, the DATA pin level is read, the software delays 480μs, and the reset sequence operation ends. During the sequence process, exit and interruption are not allowed. The MCU needs to process the sequence operation all the time, even if the software delay generates resource waste and reduces the practicality of the system. Therefore, only a small amount of software delay assistance for write 1 sequence and read sequence is needed, relying on the precise timing of the timer, and the on-site preservation and recovery of interrupt calls and exits, the instruction sequence set operation of the digital temperature sensor that meets the high accuracy requirements can be realized, and the MCU core resources can be released for other tasks after the necessary DATA pin operation.
[0055] Furthermore, in this embodiment, by comparing Figure 2 and Figure 3 It can be clearly seen that in a single instruction timing set, although the timing cycle span of a single instruction will be lengthened, the proportion of software delay is greatly reduced, and the real-time performance of the entire system is not affected. There is no need to add additional processors (increase costs) or change the temperature acquisition solution. The reduced software delay also saves computing resources and can be used to perform other tasks.
[0056] Taking the instruction of reading temperature acquisition data once as an example, the driving mode of the traditional technology and the driving mode of the method for reducing the driving delay of the DS18B20 digital temperature sensor provided by the present invention are compared through direct delay time data: (For the convenience of calculation, it is assumed that writing 1 and writing 0 each account for half)
[0057] For the traditional driving method, the total time consumption of a single instruction is 960μs+10*8*60μs+9*8*60μs=10.08ms, and the software delay accounts for 100% of the single instruction timing cycle;
[0058] For the driving mode of the present invention, T=100μs is adopted, the total time span of the entire single instruction is 1000μs+10*8*100μs+9*8*100μs=16.2ms, and the software delay is 5*8*2μs+9*8*10μs=0.8ms.
[0059] Comparing the two methods, in the same operation instruction, the software delay in the timing set cycle is reduced by 10.08ms-0.8ms=9.28ms, reducing the software delay by 92%.
[0060] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, any one of the methods in the present embodiment is implemented.
[0061] An embodiment of the present invention further provides an electronic terminal, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the terminal executes any one of the methods in this embodiment.
[0062] The computer-readable storage medium in this embodiment can be understood by ordinary technicians in this field: all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the execution includes the steps of the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
[0063] The electronic terminal provided in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run computer programs so that the electronic terminal executes each step of the above method.
[0064] The method, medium and terminal for reducing the driving delay of the DS18B20 digital temperature sensor provided in the above embodiment are compared with the prior art. In the prior art, there are multiple temperature sensors in the application, the delay time increases exponentially, and there is a lack of effective methods to reduce the driving delay, which affects the real-time performance of the entire system and wastes processor computing resources. The present invention has a simple process and convenient operation. By taking out the delay to the maximum extent, only the real timing operation and the necessary short delay are left. In the single instruction timing set, although the timing cycle span of the single instruction will be lengthened, the proportion of software delay is greatly reduced, and the delay in the single-bus digital temperature sensor instruction operation timing set is solved, so that the instruction operation of the digital temperature sensor is integrated into other programs, and one or more sensors are not affected, and the real-time performance of the entire system is not affected. There is no need to add an additional processor or change the temperature acquisition scheme. The reduced software delay saves computing resources and reduces costs. The saved time can be used to perform other tasks, which improves the work efficiency of the system.
[0065] Obviously, the embodiments described above are only preferred embodiments of the present invention, rather than all embodiments. The preferred embodiments of the present invention are shown in the accompanying drawings, but they do not limit the patent scope of the present invention. The present invention can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive. Although the present invention has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific embodiments, or to perform equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of the present invention, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present invention.
Claims
1. A method for reducing the driving delay of a DS18B20 digital temperature sensor, characterized in that: The following steps are involved: S10, MCU turns on the hardware timer interrupt, all operations are executed in the timer interrupt service function, and the timer overflow time is set to T; S20, reset sequence: the host pulls down the bus and releases the bus after at least 480μs. The next interrupt confirms the slave pulse, and this sequence ends after at least (480-T)μs. S30, write 1 timing: the host pulls down the bus, delays 2μs to release the bus, and this timing ends after the next interrupt; S40, write 0 timing: the host pulls down the bus, and this timing ends after the next interruption, and the bus is released at the same time; S50, read timing: the host pulls down the bus, delays 2μs to release the bus, and then delays 8μs to read the level status. This timing ends after the next interrupt; S60, end sequence: the operation is completed, and the host sets the bus to a high level.
2. A method for reducing the driving delay of a DS18B20 digital temperature sensor according to claim 1, characterized in that: In the interrupt service function, the operation on the DATA pin is completed, and after exiting the interrupt, the MCU resources are released to process other services.
3. A method for reducing the driving delay of a DS18B20 digital temperature sensor according to claim 2, characterized in that: Each timing operation ends at the T timer interrupt moment. A basic timing includes one or several timer terminals. In the program, multiple terminals are combined into a single timing through state quantities.
4. A method for reducing the driving delay of a DS18B20 digital temperature sensor according to claim 1, characterized in that: Break up the coherent timing set so that it is scattered at the next timer interrupt moment starting from the instruction and ends at the next timer interrupt moment after the instruction ends.
5. A method for reducing the driving delay of a DS18B20 digital temperature sensor according to claim 1, characterized in that: The DATA pin level is operated at each timer interrupt moment, and the pin level state is maintained before the next timer interrupt moment. After the operation is performed at the timer interrupt moment, the interrupt is exited and the MCU runs other services.
6. A method for reducing the driving delay of a DS18B20 digital temperature sensor according to claim 5, characterized in that: The write 1 timing has a delay of 2μs and the read timing has a delay of 10μs.
7. A method for reducing the driving delay of a DS18B20 digital temperature sensor according to claim 1, characterized in that: In the step S10, the timer overflow time T ranges from 60 μs to 120 μs.
8. A method for reducing the driving delay of a DS18B20 digital temperature sensor according to claim 7, characterized in that: The timer overflow time T is 100μs. In the reset sequence, the host pulls down the bus and releases the bus after 500μs. The next interrupt confirms the slave pulse, and this sequence ends after 400μs.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
10. An electronic terminal, characterized in that: include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the terminal executes the method according to any one of claims 1 to 8.
