Abstract: This paper introduces the working principle, communication protocol and usage of the single bus temperature sensor DS18B20 in detail; gives the temperature measurement program flow, as well as the specific implementation method of DS18B20 hardware simulation in Proteus, and compares the simulation results with the experimental results.
Keywords: Proteus; DS18B20; single bus; temperature measurement
Introduction
At present, the serial buses for data transmission between microcomputers and peripherals mainly include I2C bus, SPI bus and SCI bus. Among them, I2C bus communicates in synchronous serial 2-wire mode (1 clock line and 1 data line), SPI bus communicates in synchronous serial 3-wire mode (1 clock line, 1 data input line and 1 data output line), and SCI bus communicates in asynchronous mode (1 data input line and 1 data output line). These buses require at least 2 signal lines and ground line. The single bus technology introduced by Dallas uses a single signal line and ground line to transmit both clock and data, and the data transmission is bidirectional, which has the advantages of simple lines, less hardware overhead, low cost, and easy bus expansion and maintenance.
DS18B20 is a typical single bus digital temperature sensor, with an operating voltage of 3~5V and a temperature measurement range of -55~+125℃. The resolution can be set to 9~12 bits according to actual needs through software settings. The alarm temperature set by the user is stored in the EEPROM inside the chip and can be retained when the power is off. Each chip has a globally unique code, and the user can query its temperature through its unique serial number. Therefore, in theory, countless temperature measuring elements can be connected to a bus. A single bus usually requires an external pull-up resistor of about 4.7 kΩ to ensure that the bus is in a high level when it is idle.
1 Design of DS18B20 simulation diagram in Proteus
1.1 Introduction to
Proteus Proteus is an EDA tool software developed by Labcenter Electronics in the UK. It is a platform that can design and simulate analog circuits, digital circuits, analog/digital mixed circuits, RS232 dynamic simulation, I2C debugger, SPI debugger, keyboard and LCD, LED system. Proteus has the functions of schematic design, circuit analysis and simulation, and PCB design, and can be compiled by calling in the program. hex or . cof file to debug the microcontroller program, and can also be directly embedded in Microchip's microcontroller debugging software MPLABIDE for program debugging and simulation.
The feature of Proteus is that it can realize the design and simulation of mixed circuit systems and software systems of microcontrollers and peripherals. During the simulation process, users can use the mouse to click switches, keyboards, potentiometers, adjustable resistors and other peripheral devices to make the microcontroller system respond accordingly to the input signal, and display the response processing results on LCD, LED and other display devices according to the compiled software. The whole process is similar to the debugging process of the hardware emulator. Therefore, in the absence of hardware, this is a very practical simulation software, and its simulated schematic diagram can be directly applied to reality after verification. Proteus also provides a variety of virtual terminals such as virtual oscilloscopes, logic analyzers, signal generators, and I2C, SPI debuggers to facilitate user simulation debugging.
1.2 Implementation of DSl8B20 simulation
At present, when using microcontrollers as microprocessors in control systems in China, most of them choose PIC, 51 series or Freescale series microcontrollers. PIC microcontroller has the advantages of simple peripheral circuit, low power consumption and rich peripheral resources. This system uses PIC series microcontroller PICl6F877A as the control chip.
The first step of Proteus simulation diagram design is to pick up the components required for simulation. Click the P button below the interface preview window shown in Figure 1, and the Pick Devices dialog box will pop up. Then, enter DSl8820, LM041L (4-line × 16-character LCD), PICl6F877A, RES (resistance) in the Keywords text box. In the searched results, select the desired component and double-click it, and the component will appear in the preview window on the left.
After picking up the components, close the Pick Devices window and return to the main design page. In the preview window on the left, select the components and place them in the appropriate position. Then, select the icon (terminals mode) on the far left, select POWER (power) and GROUND (ground), place them in the appropriate position, and connect them. To change the parameters of the components, double-click the component and then modify it directly in the property box that appears. The temperature measurement network composed of 12 DSl8B20 designed in this article is shown in Figure 2.
2 Use of the single bus device DS18B20
2.1 Working principle of DS18B20
In this temperature measurement system, the single-chip microcomputer PIC16F877A is the host and the DS18B20 temperature sensor is the slave. Since DS18B20 adopts a master-slave structure, the slave can only respond when the host calls the slave. Therefore, when accessing the device, the single bus command sequence, as well as the commands of initialization, ROM, and command functions must be strictly followed. If the sequence is chaotic, the device will not respond to the host. The communication between the slave host and the slave is completed in three steps: initializing the device; identifying the device; exchanging data.
The single bus device uses a strict communication protocol to ensure data integrity. The communication protocol includes: reset pulse, response pulse, write 0, write 1, read 0, and read 1. All these signals are sent in a low-bit first, high-bit later manner.
(1) Reset pulse and response pulse
The reset pulse and response pulse are the initialization process, and all communications start with initialization. First, the host should pull down the bus for at least 480μs, then release the bus for 15 to 60μs, and then enter the receiving state to detect the level of the bus DQ. If DQ is low, it means that the slave is ready and can send ROM commands. Since C language is concise, flexible, convenient and
portable, this article uses C language to complete the program. The corresponding initialization program is as follows:
Among them, the variable dq is used to determine whether DS18B20 has a return pulse. If it is 0, there is a return pulse, indicating that the reset is successful and the loop can be jumped out; DQ represents the level of the bus. When the bus is high, DQ is 1, otherwise it is 0; DQ_IO is used to represent the state of the I/O port of the microcontroller connected to DQ. If the I/O port is used as an input to the microcontroller, DQ_IO is 1, and if it is used as an output, DQ_IO is 0.
(2) Write operation timing
Whether it is a command or data, all write operations are in bytes, and all are transmitted in the form of low bits first and high bits later. The bit writing process is as follows: the host pulls the bus down for 15μs, and then determines the next bus level based on the level of the data to be sent. If the data to be sent bit is low, the host must set DQ to a low level and keep it for 15~45μs; if the data to be sent bit is high, the host must set DQ to a high level and keep it for 15~45μs. The time to send 1 bit of data (from the bus low to the end of sending) must be controlled within 60 to 20 μs.
There must be a high-level time gap of more than 1 μs between bits. After writing a byte of data, the bus needs to be released to ensure the correct operation.
(3) Read operation timing
All data is read in bytes, with low bits first and high bits later. The process of bit reading is as follows: First, the host needs to pull the bus low for 1 to 15 μs, then release the bus and judge the bus level. If the bus is low, it means that the data bit to be read is 0; if the bus is high, it means that the data bit to be read is 1. The time to read 1 bit of data (from the bus low to the bus high to prepare for the next bit of data) must be greater than 60 μs. Similarly, there must be a high-level time gap of more than 1 μs between bits. After reading a byte of data, the bus needs to be released to ensure the correct operation. Since the temperature of DSl8B20 uses a resolution of 9 to 12 bits, one temperature data needs to read 2 bytes of temperature data. After the 2-byte data is read, the bus is released to allow the subsequent data to be correctly transmitted.
2.2 Main commands for reading temperature
The main commands for reading temperature are listed in Table 1.
3 Implementation of temperature measurement and simulation in Proteus
3.1 Implementation of temperature measurement
The entire temperature reading process is as follows:
If you want to read the temperature of other chips, start the loop from ② to ⑤. Among them, reset() is a subroutine for calling the initialization subroutine; send_com() is a subroutine for the host to send 1 byte to the slave; send_num() is a subroutine for the host to send the 64-bit device serial number to the slave; delay() is a delay subroutine; check() is a subroutine for the host to determine whether the temperature of all slaves has been read.
3.2 Proteus simulation
When using multiple DSl8B20 in Proteus, you must change the properties of the device so that the serial number of each device in the simulation is different. The specific method is: right-click DSl8B20, select the Edit Properties option, and change the value of ROM Serial Numbet; you can also change the value of Granularity, that is, change the amount of temperature adjustment each time. In Proteus, you can manually change the 3-byte device serial number. To get all 8 bytes, a simple method is to connect only one device to the bus each time, and use the Ox33 command to read the device serial number to get the complete device serial number in the program. The specific program is as follows:
Among them, send_com() is a subroutine for the host to send a byte to the slave, and read_dat() is a subroutine for the host to read a byte from the slave. For example, if the device serial number is changed to B8C530, the complete device serial number of the device can be directly observed in the Watch window in MPLAB IDE, as shown in Figure 3.
This system uses 12 DS18B20s with serial numbers B8C530 to B8C53B. The serial numbers of all devices can be obtained through the above method, and then formed into an array, which can be directly used in the temperature reading program. The array is as follows:
In MPLAB IDE, use Proteus VSM simulation mode. According to the above process of reading temperature program, write a program to read temperature, compile and run it, and you can get the simulation result.
Conclusion
It has been verified that the simulation results in Proteus are completely consistent with the actual experimental results. This fully demonstrates that the simulation results of this software are very authentic. In the absence of hardware, this is a very practical simulation software. Its simulation schematics and results can be directly applied to actual projects after experimental verification.
The single-bus digital temperature sensor DSl8B20 has the characteristics of small size, wide dynamic range, high measurement accuracy, etc. The resolution can be set accordingly according to actual needs. The single-bus device is simple to connect and has strong scalability. It can form a multi-point temperature detection network and has good application prospects in the field of temperature measurement of various components of electronic products, especially semiconductor devices.
Previous article:10-bit analog-to-digital converter AD7416/AD7417/AD7418 with integrated temperature sensor and its application
Next article:Positioning technology of UWB-based wireless sensor networks
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Solve the problem that IAR cannot jump to function definition
- Free Download | TE White Paper "The Importance of Pressure Sensors in HVAC Refrigeration Systems"
- Things to note when routing high-frequency and high-speed signal lines along the edge of a PCB
- CAN protocol and CAN driver?
- lwip stability issue?
- [Gizwits Gokit3 Review] Gokit3 Hardware Circuit Learning
- Finally solved the XDS100 V2.0 driver problem of TMS320F28377S development board
- AD9 mid-level schematic design
- Download the white paper and answer questions to win prizes | TE "Smart Monitoring Application Connectivity Solution Guide"
- Use of TI DSP Integrated Development Environment CCS