2113 views|0 replies

119

Posts

0

Resources
The OP
 

DS18B20 Digital Temperature Sensor [Copy link]

1. Overview of DS18B20.

DS18B20 is the first temperature sensor that supports the "one-wire bus" interface launched by DALLAS Semiconductor Corporation in the United States. It has the advantages of miniaturization, low power consumption, high performance, strong anti-interference ability, and easy matching with microprocessors. It can directly convert temperature into digital signal processor processing. The measured temperature range is -55~125℃, and the temperature measurement error is 0.5℃. The programmable resolution is 9~12 bits, and the corresponding resolvable temperatures are 0.5℃, 0.25℃, 0.125℃ and 0.0625℃ respectively. Compared with thermocouple sensors, it can achieve high-precision temperature measurement.

For the thermocouple temperature sensor, the process of implementing this project is: using a photoresistor to detect the size of the light, the change of light eventually changes the size of the resistor, adding a voltage to the resistor changes the size of the voltage, and then using the PCF8951AD converter to detect the change of voltage and convert it into a digital signal, which is then transmitted to the microcontroller for certain processing to control the corresponding digital tube to display the temperature at that time. For DS18B20, the process is much simpler. The part from the thermocouple resistor sensor to the microcontroller can be replaced by a DS18B20, which truly realizes digitalization. The part after the microcontroller is the same for both!

Compared with the thermal resistance temperature sensor, the price of DS18B20 is much more expensive! Therefore, if the temperature measurement accuracy requirement is not very high, you can choose the thermal resistance temperature sensor. The experimenter should decide according to the situation.

2. DS18B20 hardware introduction.

1. The hardware physical diagram and hardware schematic diagram are as follows.

Three-pin TO-92 physical picture:

Hardware schematic diagram:

Eight-pin SOIC SMD DS18B20:

  1. Two pin arrangement diagrams:

  1. Model Specifications

4 Memory

The memory of DS18B20 includes high-speed temporary register RAM and electrically erasable RAM. The electrically erasable RAM includes temperature triggers TH and TL, as well as a configuration register. The memory can completely determine the communication of the one-line port. The numbers are first written into the register with the write register command, and then the read register command can be used to confirm these numbers. After confirmation, the copy register command can be used to transfer these numbers to the electrically erasable RAM. When the numbers in the register are modified, this process can ensure the integrity of the numbers.

The high-speed temporary register RAM is composed of 8 bytes of memory. The ninth byte can be read out by the read register command. This byte verifies the previous eight bytes.

5. 64-bit photolithography ROM

The first 8 bits of the 64-bit lithography ROM are the DS18B20's own code, the next 48 bits are continuous digital codes, and the last 8 bits are CRC checksums for the first 56 bits. The 64-bit lithography ROM includes 5 ROM function commands: read ROM, match ROM, jump ROM, search ROM, and alarm search.

6. Connection method of DS18B20 external power supply

DS18B20 can use external power supply VDD or internal parasitic power supply. When the VDD port is connected to a voltage of 3.0V-5.5V, the external power supply is used; when the VDD port is grounded, the internal parasitic power supply is used. Regardless of internal parasitic power supply or external power supply, the I/O port line should be connected to a pull-up resistor of about 5KΩ.

7. DS18B20 pin definition:

(1) DQ is the digital signal input/output terminal;

(2) GND is the power ground;

(3) VDD is the external power supply input terminal (grounded in parasitic power supply wiring mode).

8. Internal structure diagram:

3. Working process .

DS18B20 control method (DS18B20 has six control commands):

Temperature conversion 44H Start DS18B20 for temperature conversion

Read register BEH Read register 9-bit binary number

Write register 4EH Write data to the TH and TL bytes of the register

Copy register 48H and write the TH and TL bytes of the register to E2RAM

Re-adjust E2RAM B8H Write the TH and TL bytes in E2RAM to the TH and TL bytes in the temporary register

Read the power supply mode B4H to start DS18B20 to send the power supply mode signal to the main CPU

Void delay_18B20(us)

{

While(us--);

}

1. Initialization

( 1) First set the data line to high level "1".

( 2) Delay (this time requirement is not very strict, but it should be as short as possible)
( 3) The data line is pulled to a low level "0".
( 4) Delay 750 microseconds (this time can range from 480 to 960 microseconds).
( 5) The data line is pulled to a high level "1".

( 6) Delayed waiting (if initialization is successful, a low level "0" will be returned by DS18B20 within 15 to 60 microseconds. Its existence can be determined based on this state, but it should be noted that it cannot wait indefinitely, otherwise the program will enter an infinite loop, so timeout control is required).

( 7) If the CPU reads a low level "0" on the data line, it will need to delay. The delay time is at least 480 microseconds, starting from the time of the high level signal (starting from the time of step (5)).

( 8) Pull the data line high again to the high level "1" and then end.
void ds1820rset() //ds1820 reset
{
DQ = 1; //DQ reset
delay_18B20(4); //Delay
DQ = 0; //DQ pull low
delay_18B20(100); //Accurate delay greater than 480us
DQ = 1; //Pull high
delay_18B20(40);
}

2. Write data operation

( 1) The data line is first set to low level “0”.

( 2) The delay time is 15 microseconds.
( 3) Send the bytes in order from high to low (only one bit is sent at a time). The order from D7 to D0
( 4) The delay time is 45 microseconds.
( 5) Pull the data line to a high level.
( 6) Repeat the operations (1) to (6) until all bytes have been sent.
( 7) Finally, pull the data line high.
void ds1820wrdata(uchar wdata) /*Write data*/
{
unsigned char I,temp=0x00;
for (i=8;i>0;i--)

{ DQ=0;

delay_18B20(15)

temp=1<<i-1;

DQ=wdata&temp;
delay_18B20(45);
DQ=1;
}
}

3. Read data operation

( 1) Pull the data line high to "1".
( 2) Delay 2 microseconds.
( 3) Pull the data line low to "0".
( 4) Delay 3 microseconds.
( 5) Pull the data line high to "1".
( 6) Delay 5 microseconds.
( 7) Read the status of the data line to obtain 1 status bit and perform data processing.
( 8) Delay 60 microseconds.
Read a binary number
bit ds_read_bit(void)
{
bit dat;
DQ=0; delay_18B20(2); DQ=1; delay_18B20(3); dat=DQ; delay_18B20(100); return(dat); } Read a byte, 8-bit binary number uchar ds1820readdata() //Read data { unsigned char i,j,value=0; for(i=0;i<8;i++)











{

j=ds_read_bit();

value |=j<<7-i;

}

return(value);
}

4. Main features of DS18B20.

( 1) It can adapt to a wider voltage range, voltage range: 3.0 ~ 5.5V, and can be powered by the data line in parasitic power mode

( 2) Unique single-line interface mode. When DS18B20 is connected to a microprocessor, only one line is needed to realize two-way communication between the microprocessor and DS18B20.

( 3) DS18B20 supports multi-point networking function. Multiple DS18B20 can be connected in parallel on a single three-wire line to achieve multi-point temperature measurement.

( 4) DS18B20 does not require any external components during use. All sensor elements and conversion circuits are integrated into an integrated circuit shaped like a transistor.

( 5 ) Temperature range: -55℃~+125℃, accuracy is ±0.5℃ at -10~+85℃

( 6) The programmable resolution is 9 to 12 bits, and the corresponding resolvable temperatures are 0.5°C, 0.25°C, 0.125°C and 0.0625°C, respectively, which can achieve high-precision temperature measurement

( 7) When the resolution is 9 bits, the temperature can be converted to digital within 93.75 ms at most. When the resolution is 12 bits, the temperature can be converted to digital within 750 ms at most. The speed is faster.

( 8) The measurement result is directly output as a digital temperature signal, which is transmitted serially to the CPU via a "one-wire bus". At the same time, the CRC check code can be transmitted, which has a strong anti-interference and error correction capability.

( 9 ) Negative pressure characteristics: When the power polarity is reversed, the chip will not burn out due to heat, but it will not work normally.

The read and write timing and temperature measurement principle of DS18B20 are the same as those of DS1820, except that the number of bits of the obtained temperature value varies due to different resolutions, and the delay time during temperature conversion is reduced from 2s to 750ms. The oscillation rate of the temperature coefficient crystal oscillator changes significantly with temperature changes, and the generated signal is used as the pulse input of counter 2. Counter 1 and the temperature register are preset to a base value corresponding to -55°C. Counter 1 subtracts the pulse signal generated by the low temperature coefficient crystal oscillator. When the preset value of counter 1 is reduced to 0, the value of the temperature register will be increased by 1, the preset of counter 1 will be reloaded, and counter 1 will start counting the pulse signal generated by the low temperature coefficient crystal oscillator again. This cycle continues until counter 2 counts to 0, stops accumulating the temperature register value, and the value in the temperature register is the measured temperature.
VI. 4 main data components:

( 1) The 64-bit serial number in the photolithography ROM is photolithography-prepared before leaving the factory. It can be regarded as the address serial code of the DS18B20. The arrangement of the 64-bit photolithography ROM is: the first 8 bits (28H) are the product type label, the next 48 bits are the serial number of the DS18B20 itself, and the last 8 bits are the cyclic redundancy check code of the previous 56 bits (CRC=X8+X5+X4+1). The role of the photolithography ROM is to make each DS18B20 different, so that the purpose of connecting multiple DS18B20s on one bus can be achieved.

( 2) The temperature sensor in the DS18B20 can measure the temperature and convert the 12-bit value into a 16-bit sign-extended binary complement reading, expressed as 0.0625°C/LSB, where S is the sign bit.

S18B20 temperature value format table:

S18B20 temperature data table:

( 4) The meaning of each bit of this byte in the configuration register is as follows:

Configuration register structure:

TM

R1

R0

1

1

1

1

1

The lower five bits are always "1". TM is the test mode bit, which is used to set whether the DS18B20 is in working mode or test mode. This bit is set to 0 when the DS18B20 leaves the factory. Users should not change it. R1 and R0 are used to set the resolution, as shown in the following table: (DS18B20 is set to 12 bits when it leaves the factory)

Temperature resolution setting table:

DS18B20 temporary register distribution:

According to the communication protocol of DS18B20, the host (single-chip microcomputer) must go through three steps to control DS18B20 to complete temperature conversion: reset the DS18B20 before each read and write, send a ROM instruction after the reset is successful, and finally send a RAM instruction, so that the DS18B20 can perform the predetermined operation. Reset requires the main CPU to pull down the data line for 500 microseconds and then release it. When DS18B20 receives the signal, it waits for about 16 to 60 microseconds, and then sends a low pulse of 60 to 240 microseconds. The main CPU receives this signal to indicate that the reset is successful.

ROM instruction table:

RAM instruction table:

External power supply mode of DS18B20

In the external power supply mode, the DS18B20 working power supply is connected to the VDD pin. At this time, the I/O line does not need to be strongly pulled up, and there is no problem of insufficient power supply current. The conversion accuracy can be guaranteed. At the same time, any number of DS18B20 sensors can be connected to the bus in theory to form a multi-point temperature measurement system. Note: In the external power supply mode, the GND pin of DS18B20 cannot be left floating, otherwise the temperature cannot be converted and the read temperature is always 85℃.



This post is from MCU
Personal signature

嵌入式、汇编语言等免费视频<

 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list