Share this

Research on Sensor Timing and Temperature Readout in Distributed Temperature Measurement

2026-04-06 07:05:50 · · #1
Abstract: The novel DS18B20 sensor is widely used in distributed temperature measurement systems. The DS18B20 is a single-bus digital temperature sensor with simple hardware wiring, but its timing is very complex. Correctly using the single-bus digital temperature sensor, analyzing its timing relationships, and developing correct programs based on the timing are of paramount importance. This paper elaborates on the initialization timing, write timing, and read timing with timing diagrams, and provides software programs to implement each timing sequence. Temperature acquisition is achieved using the initialization and read/write timing sequences, and the comprehensive application of timing is illustrated through the design of a 64-bit serial number reading program for the sensor. The design concept of the temperature acquisition program is explained. Temperature display in a distributed temperature measurement system is also presented. The correct temperature reading and display based on timing described in this paper has been applied to a distributed temperature measurement system. Keywords: write timing; read timing; temperature sensor; temperature acquisition Abstract: A lot of new temperature sensors DS18B20 are used in distributed temperature measurement system. DS18B20 is a single bus digital temperature sensor. The hardware connection of temperature sensor is simple and time slots are very complex. Using the single bus temperature correctly, analyzing time slots and designing the program based on correct time slots have an important meaning. Initialization timing, writing time slots and reading slots are expounded in this paper in detail. Software program of realizing each time slots is provided. The temperature sampling is realized by use of initialization timing, writing time slots and reading slots. The design of 64-bit serial number reading program illustrates synthetic application of time slots. The design method of temperature sampling is illustrated. The temperature display is given out for distributed temperature measurement system. Sensor; Temperature Sampling 1. Introduction The DS18B20, a novel sensor, is widely used in distributed temperature measurement systems. While its hardware wiring is simple, its timing is highly complex. Correct temperature reading requires both ROM operation commands for the DS18B20 and various function commands. These commands have a specific order and meaning, all based on the digital temperature sensor's initialization, write, and read timing sequences. Strict timing coordination is essential for accurate temperature acquisition and reading. Therefore, to correctly use a single-bus digital temperature sensor, its timing relationships must be analyzed, and a correct program must be developed based on these sequences. The timing analysis and application research of single-bus digital temperature sensors is of paramount importance. 2. Digital Temperature Sensor Timing The DS18B20 connects to the microcontroller via only one data line, making data transmission serial. To correctly read temperature values, the program must be developed strictly according to the timing relationships. The DS18B20 has a strict communication protocol to ensure the correctness and integrity of data transmission. This protocol specifies the timing of various signals on the bus. For example, the timing of signals such as reset pulse, response pulse, write 0, write 1, read 0, and read 1. The DS18B20 operates normally under strict timing control. In other words, it uses relatively complex software to achieve a simple hardware interface. Therefore, to use the DS18B20 correctly, it is necessary to understand its initialization timing, write timing, and read timing. 2.1 Digital Temperature Sensor Initialization Timing The initialization timing, sometimes called the reset timing, is the beginning of all transmission processes on the data line. The entire initialization process consists of a reset pulse issued by the master device and a response pulse from the DS18B20. During the master device initialization process, the master device pulls the data line low for at least 480μS, which the DS18B20 interprets as receiving an initialization pulse. Then, the master device releases the data line, and under the action of the pull-up resistor on the data line, the data line level is pulled high, and the master device enters receive mode. After the DS18B20 detects the rising edge, it delays for 15-60μS, and then pulls the bus low for 60-240μS to generate an acknowledgment pulse. The initialization timing is shown in Figure 2. Figure 1 is a line diagram of Figures 2, 3, and 4. [align=center] Figure 1 Line diagram Figure 2 Initialization timing[/align] In the distributed temperature measurement system, the CPU uses AT89S52. The initialization program for temperature reading is as follows: DAT BIT P1.0 INI10: SETB DAT MOV R2, #185 INI11: CLR DAT DJNZ R2, INI11 ; Reset pulse time 600us SETB DAT ; Release data line MOV R2, #28 INI12: DJNZ R2, INI12 ; Wait 60us CLR C ORL C, DAT ; Low level for response JC INI10 ; If no response, initialization fails MOV R6, #40 INI13: ORL C, DAT JC INI14 ; Data line goes high. Initialization successful: DJNZ R6, INI13; Low level for a maximum of 240us: SJMP INI10; Low level for more than 240us, failure: INI14: MOV R2, #222; INI15: DJNZ R2, INI15; Acknowledgment signal must last at least 480us: RET 2.2 Digital Temperature Sensor Write Timing: The write timing includes a write "0" timing and a write "1" timing. The write "1" timing is used for the master device to write a 1 to the DS18B20, and the write "0" timing is used for the master device to write a 0 to the DS18B20. Both write timings require at least 60μs, and there must be at least 1μs of recovery time between two independent write timings. Both write timings begin when the master device pulls the data line low. For the write "1" timing, after the master device pulls the data line low, it must immediately release the data line within 15μs, and the pull-up resistor will pull the data line high. For the write "0" timing, after the master device pulls the data line low, it only needs to maintain a low level for at least 60μs throughout the entire timing sequence. During the 15-60μs period after the start of the write timing, the DS18B20 reads the data line level. If the data line is high during this period, a logic 1 is written to the device; otherwise, a logic 0 is written. The write timing is shown in Figure 3. [align=center] Figure 3 Digital Temperature Sensor Write Timing[/align] The program for writing one bit is shown below. In the program, DAT is I/O port P1.0. WIR11: SETB DAT ; Pull high MOV R4, #5 NOP CLR DAT ; Pull low after 2µs high level WIR12: DJNZ R4, WIR12 ; Wait 10µs MOV DAT, C ; Send 1 bit MOV R4, #23 WIR13: DJNZ R4, WIR13 ; Ensure write time is greater than 60µs SETB DAT RET 2.3 Temperature Sensor Read Timing The DS18B20 only transmits data to the master device after detecting that the master device has initiated a read timing sequence. Therefore, a read timing sequence must be generated immediately after the master device sends a read data command so that the DS18B20 can transmit data. All read timing sequences require at least 60µs, and there must be at least 1µs recovery time between two independent read timing sequences. Each read timing sequence is initiated by the master device, first setting the data line to high level, then pulling the data line low for at least 1µs, and then releasing the data line. After the master device issues the read timing sequence, the DS18B20 begins transmitting data 0 or 1 on the data line. If it transmits 1, it keeps the data line high. If it transmits 0, the DS18B20 pulls the data line low and releases the data line after the timing sequence ends. The data transmitted by the DS18B20 is reliably valid for 15μs after the start of the timing sequence. Therefore, the master device must release the data line during the read timing sequence and read the data line status within 15μs after the timing sequence begins. The write timing sequence is shown in Figure 4. [align=center]Figure 4 Digital Temperature Sensor Read Timing[/align] The program for reading one bit is as follows: RE11: SETB DAT ; Set the data line to high level NOP NOP CLR DAT ; After holding the high level for 2us, pull the data line low MOV R4, #4 NOP ; Hold the low level for 2us SETB DAT ; Release the data line RE12: DJNZ R4, RE12 ; Wait for 8us MOV C, DAT ; Read one bit MOV R5, #28 RE13: DJNZ R5, RE13 ; Ensure one read cycle lasts for 60us SETB DAT ; Set the data line to high level RET 3. Initialization and Read/Write Timing Application 3.1 The temperature acquisition program design for the single-bus digital temperature sensor DS18B20 requires the following steps to complete temperature acquisition in sequence: initialization, skip ROM matching, start conversion, wait for conversion completion, initialization, match ROM, read note-based memory, CRC check, temperature format conversion, save temperature value, and display, among other processing. Following this sequence, the program design first executes the initialization program INI10 described in section 2.1 according to the initialization timing sequence. Next, the skip ROM matching command (code CCH) needs to be written into the DS18B20. At this point, a write byte program WRITE needs to be written to the DS18B20 according to the digital temperature sensor write timing sequence described in section 2.2 to write the skip ROM matching command into the DS18B20. To complete the temperature start conversion, the start conversion command needs to be written into the DS18B20. A 750ms delay is used to wait for the conversion to complete. Then, the initialization program INI10 described in section 2.1 is executed again according to the initialization timing sequence, and a write byte program is used to write the match ROM command (code 55H) into the DS18B20. To complete the read operation of the notepad memory, the read notepad memory command (code BEH) needs to be written into the DS18B20 first, combined with the digital temperature sensor write timing. Then, the read one-byte program READ, written using the temperature sensor read timing, continuously reads 9 bytes of content from the DS18B20 notepad memory. Therefore, to achieve correct temperature acquisition, the initialization timing, temperature sensor write timing, and temperature sensor read timing described above need to be combined to write and read the required commands, thus completing the correct temperature reading. 3.2 Temperature Sensor Serial Number Reading Program Design Each single-bus digital temperature sensor DS18B20 has a unique 64-bit serial number at the factory. Before using the temperature sensor, each temperature sensor needs to be connected to an I/O port such as P1.0, and then the serial number of the temperature sensor needs to be read. When a temperature sensor DS18B20 is connected to an I/O port, the 64-bit serial number can be read using the read ROM command. The program design first loads the ROM read command (code 33H) into accumulator A, then calls the write-one-byte program WRITE, followed by the read-64-bit serial number program DXLH. In the WRITE program, the loop count is set to 8, and then a write-one-bit subroutine is called, strictly following the timing sequence to execute the sensor write timing, looping 8 times to write one byte. In the DXLH program, the internal RAM starting address is set to 30H, the loop count is set to 8, and the read-one-byte program READ is called to store the read data in internal RAM. This loop reads 8 bytes (64-bit serial number) in 8 iterations. The read 64-bit serial number is then stored in internal RAM locations 30H to 37H. The read-one-byte program READ is shown below. READ: MOV R6, #8 ; Loop count is 8 SETB DAT ; Read one bit of the program and execute the sensor read timing NOP NOP RD11: CLR DAT MOV R4, #4 NOP ; Continuous low level for 2us SETB DAT ; Release data line RD12: DJNZ R4, RD12 ; Wait for 8us MOV C, DAT ; Read one bit RRC A ; Shift the read data into accumulator A MOV R5, #28 RD13: DJNZ R5, RD13 ; Ensure one read cycle lasts 60us DJNZ R6, RD11 ; Loop 8 times to read one byte SETB DAT RET After the above program is executed, the 64-bit serial number of the temperature sensor can be stored in the microcontroller's internal RAM units 30H to 37H. 4. Temperature Display in Distributed Temperature Measurement System In a distributed temperature measurement system, an LCD display can show the room number, actual temperature, alarm upper limit, and the time of alarm occurrence. It can also cycle through the actual temperature and upper limit of multiple rooms, as shown in Figure 5. [align=center]Figure 5: Display of corresponding room temperature and alarm upper limit in a distributed temperature measurement system[/align] 5. Conclusion Correctly reading the temperatures of multiple single-bus digital temperature sensors (DS18B20) is crucial in a distributed temperature measurement system. Because the program design must adhere to strict timing relationships, the author's innovation lies in detailing the complex logical relationships such as initialization timing and read/write timing, designing a correct temperature sequence number reading program and temperature read/write program, and enabling LCD display. Since the various functions of the single-bus digital temperature sensor DS18B20 are implemented through various ROM commands and operation function commands, these commands are interconnected, and each link is a set of timing sequences. During program debugging, it is not possible to trace the process using single-step execution as in other programs, thus greatly complicating error finding and program optimization. When encountering a program error, one can only analyze, speculate, modify and run it again based on the error phenomenon to solve the problem, but cannot directly locate the error. The program design ideas and methods of the single-bus digital temperature sensor DS18B20 introduced in this article have been well applied to the distributed temperature measurement system and meet certain accuracy requirements. References [1] Sha Zhanyou, Principles and Applications of Intelligent Integrated Temperature Sensors [M], Machinery Industry Press, 2002 [2] Zhou Yuexia, Sun Chuanyou, Hardware Connection and Software Programming of DS18B20 [J], Sensor World, 2001.12 [3] Dallas Semiconductor. DS18B20 1-Wire Digital Thermometer [Z]. Dallas Semiconductor Co, 2002 [4] Xu Weitao, Hao Xiaohong, Research on Control Method of OCXO Constant Temperature Bath Temperature Control System [J], Microcomputer Information, No.3, 2006
Read next

CATDOLL 123CM Maria (TPE Body with Hard Silicone Head)

Height: 123cm Weight: 23kg Shoulder Width: 32cm Bust/Waist/Hip: 61/54/70cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22