Automobile site - Behind the wheel

Automobile site - Behind the wheel

» Temperature sensor DS1621. Detailed description of the sensor Hack #1: Phantom power for the COM port

Temperature sensor DS1621. Detailed description of the sensor Hack #1: Phantom power for the COM port

The microcircuit is a thermometer and thermostat “in one bottle” with digital input and output, which guarantees measurement and control accuracy with an error of plus or minus 0.5 g. Celsius. If you use the DS1621 sensor as a thermometer, then the data must be processed via the I2C/SMBus serial bus in an additional nine-bit code with an accuracy of the least significant digit plus or minus 0.5 g. Celsius.

For applications that require increased temperature resolution, additional registers and simple arithmetic must be read to achieve more than 12-bit resolution (with the smallest bit costing 0.0625 degrees Celsius). The DS1621 chip has three addressable inputs, thus making it possible to connect up to eight DS1621 sensors to one bus.

Using the DS1621 as a thermostat, the DS1621 has TH (high temperature) and TL (low temperature) registers. When the current temperature exceeds the TH level, the sensor output will go into the active state and will continue to remain in it until the current temperature drops below the TL mark. Thus, control with a given hysteresis is implemented.

Description of the DS1621 sensor pins

  • S.D.A. I2C bus data output.
  • SCL - I2C bus clock output.
  • Tout— thermostat output.
  • Vdd - power output, plus.
  • GND - power output, minus.
  • A0..A2 — line of least significant bits.

Operating principle of the DS1621 sensor

The measurement principle is based on the instability of the oscillation frequency when temperature changes. To implement this measurement principle, two generators are included in the microcircuit structure.

The first of them has high temperature stability. Its operating frequency corresponds to a temperature of 55 degrees. Celsius and does not actually change. The operating frequency of the second generator, on the contrary, changes in proportion to the temperature change. Special counters count pulses over an equal period of time and, based on the difference, calculate the current temperature, which is presented in the form of a 9-bit binary code.

Data is divided into high and low bytes. If for any purpose an integer temperature value is needed, then only the high byte should be used. The low byte has only one information bit - LSB, which implements a discreteness of 0.5 g. Celsius. The remaining bits of the low byte are always zero.

Status register

The DS1621 chip has several operating modes. These modes are configured and controlled using the status register. The following bits exist:

  • DONE conversion completion flag. Set at the end of the conversion.
  • THF—"high temperature" flag. Set when the temperature increases above the TH threshold. The flag is reset by software or by turning off the power.
  • TLF -"low temperature" flag. Set when the temperature decreases below the TL threshold. The flag is reset by software or by turning off the power.
  • NVB flag for recording data into the non-volatile memory of the sensor. A set flag indicates that the recording has not been completed. The approximate time for writing data to cells is 10 ms.
  • POL - selection of output polarity Tout. A high value indicates straight polarity, a low value indicates reverse polarity. This bit is non-volatile.
  • ISHOT measurement cycle control bit. A single measurement occurs when the logic level of this bit is high. It is usually used to create energy-saving systems. The low logical level of this bit allows the conversion to be performed in constant mode. This bit is non-volatile.

Exchange commands

Data exchange with the DS1621 sensor occurs using the standard I2C protocol. The sensor takes part in it as a SLAVE device. Its SLAVE address looks like this:

where xxx is the state of lines A0-A2 of the microcircuit. The following commands are used to interact with the DS1621:

  • 22h —“Stop conversion” - the command ends the operation of the temperature conversion circuit. No extra data is required for work.
  • AAh—“Read temperature” - The result of the command is two bytes of data that contain the value of the measured temperature.
  • A1h—“Setting TH” is a command for selecting the upper threshold for thermostat operation. After this command, two bytes of the threshold value must be transmitted.
  • A2h—“Setting TL” is a command for selecting the lower threshold for thermostat operation. After this command, two bytes of the threshold value must be transmitted.
  • A8h—"reading the temperature meter." The command is read-only and allows reading data from a counter whose operating frequency depends on temperature.
  • A9h—"read stable counter". The command is read-only and allows reading data from a counter whose operating frequency does not depend on temperature.
  • ACh —"Configuration Register". If the bit is equal to R, the configuration register is written, and if W, the configuration register is read.
  • EEh —“Start counter” is a command to start temperature measurement. No extra data required.

Improved measurement accuracy

The DS1621 sensor can improve the accuracy of the measured temperature. For this purpose, the counter values ​​of the stable N and the temperature-dependent N generator are available. Knowing the measured temperature value T and the counter values, you can get an accurate reading using the formula:

T=T – 0.25 + (N-N)/N

Thermostat mode DS1621

The DS1621 sensor also has a mode of operation as a thermostat. To control actuators there is a digital output Tout, set depending on the temperature value. The output on and off levels are set in the TH and TL registers, and the output polarity is selected by the POL bit of the configuration register.

Schematic diagram of a homemade thermostat, which is designed to work with a heating system based on an electric boiler. The circuit is based on the DS1621 chip. The DS1621 chip is a thermometer and thermostat with digital input/output, providing an accuracy of ±0.5°C.

When used as a thermometer, data is read via l2C/SMBus serial bus in an additional 9-bit code with a least significant bit value of ±0.5°C.

For applications requiring higher resolution, the user can read additional registers and perform simple arithmetic to achieve greater than 12-bit resolution (with a least significant bit value of 0.0625°C). The DS1621 provides 3 addressable inputs to allow users to connect up to 8 DS1621s to a single bus.

When using this microcircuit as a thermostat, data about the temperature that needs to be maintained is stored in internal non-volatile memory (EEPROM) in the form of user-defined control points for temperature rise (TH) and temperature drop (TL). The difference between TN and TL forms hysteresis.

When the temperature is insufficient (TL and below), pin 3 of the microcircuit is set to a low logic level. When the temperature is sufficient (TN and above), this pin is a logical one.

The DS1621 chip is available in 8-pin PDIP and 8-pin SOIC packages.

Schematic diagram

Figure 1 shows a diagram of connecting this microcircuit to a personal computer.

Rice. 1. Schematic diagram of a thermostat for an electric boiler.

The software with which the thermostat according to Fig. 1 will work together with a personal computer can be found in, download the program - Download (1.5 MB).

After setting the temperature using a personal computer, it can be disconnected from the circuit in Fig. 1. The specified data will be saved in the memory of the microcircuit, and this circuit will work independently, maintaining the set temperature using triac VS1, controlling it to power the heating element of the heating boiler.

Rice. 2. Thermostat circuit on the ATTINY2313 microcontroller.

The computer, with success, can be replaced with a control and monitoring circuit based on a microcontroller, for example, the ATTINY2313 circuit shown in Figure 2. This is a complete independent device that can maintain room temperature in the range from 10 to 40 degrees Celsius, and at the same time serve as a thermometer showing a specific room temperature.

The temperature is displayed on a two-digit LED digital indicator. Three button control. S1 is used to turn the thermometer on and off.

And with buttons S2 and S3 you can set the temperature to be maintained. The HL1 LED is used to indicate the on state of the electric boiler. When the boiler heating element is working, it flashes.

MK firmware

The HEX file for programming the microcontroller is located at this link: Download (1.9 KB).

The microcontroller operates with a built-in 4 MHz oscillator. When programming in Features you need to select:

int. R.C. Osc. 4 MHz; Start-up time: 14 CK + 0 ms;

Brown-out detection disabled;

check the box for Serial program downloading (SPI) enabled;

Fuses: (check the boxes) SUT1, SPIEN, SUTO, CKSEL3, CKSEL2, CKSELO

Details

You need to use an ohmmeter to select the terminals of the primary winding with the highest resistance between them, and connect them to the electrical network. ALSZZZA LED indicators are quite old. They can be replaced with any seven-segment digital LEDs with a common cathode.

Kozhukhin V. A. RK-08-16.

Literature: 1. Thermometer for PC on DS1621 - cxem.net/mc/mc136.php.

Chip DS 1621, manufactured by Dallas Semiconductors, is designed to perform the functions of a thermometer and thermostat. The capabilities of the microcircuit allow measurements in the temperature range from -55 to +125 degrees Celsius. The temperature reading step is 0.5 degrees. DS 1621 is equipped with an interface I 2C. In thermostat mode, autonomous operation is possible.

Pin assignment

  • S.D.A.- I2C bus data line
  • SCL- I2C bus clock line
  • Tout- thermostat output
  • Vdd- positive power output
  • Vss- negative power supply
  • A0..A2- lines for forming the least significant bits of the address

Principle of operation

temperature sensor D.S. 1621 uses the principle of instability of oscillation frequency with temperature changes to measure. For this purpose, it includes two generators. The first has high temperature stability. Its frequency corresponds to a temperature of –55 degrees and is practically not subject to change. The operating frequency of the second generator, on the contrary, changes proportionally to the temperature. Special pulse counters count for the same time interval and, based on the difference, calculate the temperature value. This value in 9-bit binary code is available to the user. The data is divided into high and low bytes. If the integer temperature value is sufficient, then only the high byte can be used. The low byte has only one information bit LSB, providing a resolution of 0.5 degrees. The remaining bits of the low byte are always 0.

The DS 1621 chip has several operating modes. These modes are configured and monitored using the status register. The available bits are:

  • DONE– conversion completion flag. Set upon completion of conversion.
  • THF– “high temperature” flag. Set when the TH threshold is exceeded. Can be reset by software or by turning off the power.
  • TLF- “low temperature” flag. Set at a temperature lower than the threshold value TL. Can be reset by software or by turning off the power.
  • NVB– flag for writing data to non-volatile memory. A set flag indicates that the recording is incomplete. The cell recording time is approximately 10 ms.
  • POL– output polarity Tout. A high value corresponds to direct polarity, a low value to reverse polarity. The bit is non-volatile.
  • ISHOT– measurement cycle management. When the logic level is high, the measurement is performed once. This mode is used in energy-saving systems. A low logical bit level allows the conversion to be carried out in continuous mode. The bit is non-volatile.

Working with DS1621

Exchange commands

Data exchange with DS 1621 is carried out using the standard I 2C protocol. The microcircuit participates in it as a slave device. The slave address of the DS 1621 has the form 1001xxx, where xxx is the state of the lines A0-A2 of the microcircuit. The following commands are used to work with DS 1621:

  • 22h– “Stop conversion” - the command terminates the temperature conversion circuit. No additional data is required for operation.
  • AAh– “Read temperature” - The result of the command is two bytes of data containing the value of the measured temperature.
  • A 1h– “Setting TH” - a command to set the upper threshold of the thermostat. After this command, the transmission of two bytes of the threshold value is required.
  • A 2h- “Setting TL” - a command to set the lower threshold of the thermostat. After this command, the transmission of two bytes of the threshold value is required.
  • A 8h– “reading the temperature meter”. The command is read-only and allows you to read data from a counter whose operating frequency depends on temperature.
  • A 9h- “reading a stable counter”. The command is read-only and allows you to read data from a counter whose operating frequency does not depend on temperature.
  • A Ch– “Configuration register”. Depending on the state of the R/W bit, the configuration register is written or read. The format of the data used is byte.
  • EEh– “Start counter” - command to start temperature measurement. No additional data required.

Increasing measurement accuracy

The DS1621 temperature sensor allows for increased measurement accuracy. For this purpose, the values ​​of the stable N and temperature-dependent N generator counters are available to the user. Knowing the measured temperature T and the counter values, you can use the formula:

T=T – 0.25 + (N-N)/N

It is also desirable to calibrate the sensor to determine the necessary corrections. These corrections must be taken into account in the controller.

Thermostat mode

The DS 1621 chip can operate in thermostat mode. For this purpose, there is an output Tout, which is set depending on the temperature value. The thresholds for turning the output on and off are set by the values ​​in the TH and TL registers. The polarity of the output is set by the POL bit of the configuration register.



The DS1621 is a digital I/O thermometer and thermostat that provides ±0.5°C accuracy. When used as a thermometer, data is read via the I2C/SMBus serial bus in 9-bit's complement code with the least significant bit value ±0.5°C. For applications requiring higher resolution, the user can read additional registers and perform simple arithmetic to achieve greater than 12-bit resolution (with a least significant bit cost of 0.0625°C). The DS1621 provides 3 addressable inputs to allow users to connect up to 8 DS1621s to a single bus.
When used as a thermostat, the DS1621 chip has user-programmable over-temperature (TH) and under-temperature (TL) setpoints in its internal non-volatile memory (EEPROM). One dedicated logic output will operate when TH is reached and the output will remain active until the temperature drops below TL (programmable hysteresis).
The DS1621 is offered in 300mil, 8-pin PDIP and 150mil, 8-pin SOIC. For applications that do not require ±0.5°C accuracy, the DS1721 is available with reduced ±1°C accuracy, a lower cost, fully compatible IC (SOIC only).
The DS1621 is supported by the DS1702k Demo Kit.
Distinctive features:
±0.5°C accuracy from 0°C to 70°C
9-bit resolution, expandable to 12-bit
special logic output for temperature control
Thermostat settings are non-volatile and user programmable
Data is transferred via I2C/SMBus serial interface
3 address inputs (8 DS1621 can be used on one bus)
Operating supply voltage range from 2.7V to 5.5V
8-pin PDIP or 150mil, 8-pin SOIC packages
DS1621 8-PIN DIP (300-MIL)
DS1621S 8-PIN SOIC (150-MIL)
DS1621V 8-PIN SOIC (208-MIL)



The device is simple, without calibration and microcontrollers.

This incredibly simple thermometer plugs into any available serial port. No programmable components or microcontrollers are used. The measurement accuracy is up to 0.5°C without calibration. It's so cheap that I made one for every computer I use. It's so nice to have a temperature on the Windows taskbar that many friends have asked me to make one!

Make yourself an accurate thermometer

D This project is quite easy for beginners, but there may be difficulties associated with hardware incompatibility of the serial port on different computers. The single sensor version only requires a sensor chip, a voltage regulator, and a few diodes and resistors. Make it and learn the secrets of the IIC bus, how to implement an IIC bus using only two resistors and a pair of zener diodes, how to control it on a serial port using Visual Basic. The components used are readily available in online radio stores.

Characteristics:

The temperature is displayed both on the Windows taskbar and outside it (see figure).

Installs into any free COM port of a PC.

Measuring range -20 … +125°C (-4 … 257°F).

Basic accuracy and resolution 0.5°C.

Celsius (°C) and Farenheit (°F) scale.

The data is written to an easy to read text file (good for Excel).

Sampling rate 1, 5, 30 or 60 seconds.

One or two temperature sensors (expandable to 8)

Powered by COM port, no external source required.

Easy to do, no exotic software or hardware parts.

Does not require calibration.

Making a PC thermometer is easy. I will describe in detail the version with surface mount elements. Those who are not familiar with soldering small SMT elements will be happy to know that a lead-out board is also available.

First you need to assemble all the elements except the boards. Here is the list of elements:

Number Type Description
U1, U2 DS1621 or DS1631 Digital temperature sensor

Plastic housing SO8 (SMD) or DIP (Input)

U3 LM2936Z-5.0 Ultra low loss voltage regulator, TO92 housing (both versions)
D1, D2 LL4148 Small pulse diode (like 1N4148)
DZ1, DZ2 MMSZ5V1 Zener diode 5.1V 0.5W.
C1, C2 47 µF/16V Electrolytic capacitor
C3, C4 100nF Low Voltage Ceramic Capacitor (SMD 1206)
R1, R2 4700 Ohm 5% Resistor 0.25W (SMD 1206)
COM DB9F 9-pin female connector, straight (SMD) or angled (Leadout)

This is an enlarged view of the assembled SMT board (The small board is a remote temperature sensor).

Once I assembled all the elements, I printed the board at its actual size to check the dimensions of all the elements relative to it. If an element is too big or small, I can adjust the board or look for a suitable element before starting work.

After all the elements are checked, I make the board. Since it is single-sided, you can easily etch it yourself. It takes less than an hour and does not require any special materials using the method described here.

The board must be spotlessly clean (no oxidation or fingerprints) for good etching and soldering. Rub it with a soft abrasive until it shines (kitchen scourer, steel wool, or even an office eraser). Don't forget to mirror your board design before printing! I love SMT boards because there aren't as many tedious holes to drill before soldering.

Soldering requires a soldering iron with a thin tip, sharp tweezers and a steady hand. I hold the board to the table while soldering. I actually attach it to the printout to make it easier to check while soldering.

To avoid accidentally mixing up items, keep them in their original packaging until needed. I suggest you start soldering with small elements (resistors, diodes...) and finish with large ones (electrolytic capacitor), tall elements can make it difficult to access small ones.

Don't apply too much solder, and be careful not to overheat the components (especially diodes and ICs). If necessary, allow the element to cool. Most elements are polar, so be careful not to mix them up. The diode cathode (K) is marked with a black ring, the negative terminal of the electrolytic capacitors is marked with a black stripe. If you prefer to use tantalum capacitors, remember that their markings are reversed, with a black stripe indicating the positive terminal!

Keep an eye on the photo and always double check until you are sure there is no difference.

Those who are not experienced in soldering SMT components may be concerned about soldering the sensor chip.

I clean the soldering iron tip before each soldering point, and use very thin solder to ensure I apply as little solder as possible. I apply a small amount of solder only to the pad intended for pin 1.

I place the microcircuit on the board, and when its pins match the pads, I clean the tip and heat pin 1 until it is soldered. I check that the chip is still aligned correctly (all pins are centered on their respective pads). If it has moved, I heat pin 1 and move it, or I still solder the remaining pins, cleaning the tip and using little solder. The last step is to solder pin 1, which was initially soldered with a very small amount of solder.

The LM2936Z5 voltage regulator requires special preparation for soldering. I had through holes, but I wanted to solder it on the SMT side of the board. The figure shows how to bend and shorten the contacts.

The printed circuit board is designed to be installed between the pins of the serial port connector. This is the last part of the soldering. Don't forget to solder pins 7 and 8 on the opposite side of the PCB.

I usually clean the board of flux residue using a solvent such as acetone and allow the board to dry completely before turning it on. Once the board is tested and working, I apply a coat of clear spray varnish to protect the copper from oxidation.

The last step is to download and install the software. If you are confused by the Microsoft Installer prompts (... in Italian), these screenshots (first and second) will help you do everything right.

When you first start, you need to select the serial port number to which the circuit is connected, and you will be ready to receive temperature. Good luck!

How it works?

The circuit is derived from the Claudio Lanconelli PonyProg programmer. The key component is the Dallas Semiconductor DS1621 temperature sensor. This is a digital temperature sensor, which means that it measures temperature and turns it into digital values ​​(binary numbers, that is, a sequence of ones and zeros, like bytes in a computer).

Simply supply a regulated 5V supply, and the DS1621 is capable of transmitting ambient temperatures via the IIC serial bus (Inter-Integrated Circuit bus, also written I2C). This is a standard transmission circuit developed by Philips Semiconductors for connecting multiple chips together using just two lines: clock (SCL) and data (SDA).

See the documentation for more detailed information about the operation of the bus, but for now it is enough to know that any I2C chip has its own address (a number in the range from 0 to 127) and a set of commands. This way you can connect many chips in parallel and still be able to communicate with each one individually, starting each message with the appropriate address.

Straight from the factory, all DS1621s come with a base address ($40), but you can customize it by connecting the address pins (A0, A1, A2) to 5V or GND respectively (see table). So you can connect up to 8 sensor chips in parallel on the bus, although the supplied software only supports and tabulates two (you can add more sensors by changing the software).

So we can power the DS1621 with 5V DC and connect it to the SCK and SDA wires of the PC's I2C interface, right? Unfortunately, computers don't have 5V DC connectors and I2C ports, so we have to hack them!

Hack #1: Phantom power for COM port

A temperature sensor doesn't require much power to operate, so why not eliminate the need for power by "stealing" power from the signals already available on the RS232 port?

12V from the RS232 lines is transmitted to the regulator through diodes D1, D2, filtered by C1 and regulated to +5V on the LM2936-Z5. This is a special regulator that can operate with a minimum input voltage and save every mA. The LM2936 is capable of regulating input voltages as low as 5.2 (most serial ports are only powered by 6V). By comparison, conventional 78L05 regulators require at least 6.7V input and consume 100 times the current required by the LM2936-Z5.

Hack #2: Make the COM port pretend that it is an I2C bus.

The thermometer PC software emulates the I2C bus wires with two pins of the COM port, available on all motherboards.

The SCL line uses RTS (Request To Send, pin 7), and the SDA line uses a line originally designed for the DTR serial port (Data Terminal Ready, pin 4). These signals are accessible from Visual Basic by setting the DTR and RTS properties of the MSComm object.

You cannot feed the COM port signal to the DS1621 directly as the voltage levels must be adapted. According to the EIA-RS232 standard, most computers output voltage reaches +15VDC and drops to -15VDC at the COM port connector, so we must limit them to more convenient voltages of 0 to +5VDC before connecting to the DS1621 SDA and SCL wires. A 5.1V zener diode and a 4700 limiting resistor are sufficient for this purpose.

If you look at the circuit carefully, you will notice that the SDA pin is also connected to the CTS (Clear To Send, pin 8) pin. This way, the thermometer PC software can control the SDA logic level to read the chip's responses, making this line bidirectional. Although a serial port theoretically requires a negative signal from its input, signals in the 0...5V DC range work well on almost any computer on earth.

Software

The software comes pre-compiled and with an installer (setup.exe), but source code is included for those interested in programming.

I wrote the program in Visual Basic. I did this the direct way, deliberately avoiding optimizations that would make the code less readable.

The I2C bus functions are grouped into a file that can be reused for other applications. It provides functions for all basic I2C bus operations: such as starting and stopping the bus, or sending and receiving a single byte.

The main program provides a temperature function (chipaddress), which instructs the I2C bus to obtain the temperature from the chip.

To read the temperature of a chip in Visual Basic all you need to do is query for temperature ($&48), where $&48 is the address for the first chip, $H49 is the address for the second chip, and so on according to the table above. My program uses two sensors, but it's not that hard to modify it to support up to 8 chips.

The very first time you run the program, you will receive a warning that there is no configuration file (it will be automatically created at the end of the session) and the settings will be default. Select the serial (COM) port you use if your device includes U2 to read outside air temperature, measurement interval, units of measurement and if you want temperature logging to the file "pc_thermometer.txt" (ASCII text file that you you can import into Excel for processing or plotting).

Check the "start minimized" field, if it is enabled, then on subsequent launches the program will not open a window on the desktop, but will be minimized on the taskbar, providing a "temperature icon". This is my preferred way to use the program.

When you click on the icon, a window opens.

Download files for the project

Original article in English (translation: Alexander Kasyanov for the site cxem.net)