Skip to main content

DS18S20 : 1-Wire Digital Thermometer and mikroC OneWire Library

Introduction
The DS18S20 is a 1-Wire digital thermometer device from MAXIM that provides 9-bit Celsius temperature measurements and communicates over a 1-Wire bus with a central microprocessor. It also has in-built alarm function with nonvolatile user-programmable upper and lower trigger points. The operating temperature range of the device is –55°C to +125°C with an accuracy of ±0.5°C over the range of –10°C to +85°C. Each DS18S20 has a unique 64-bit serial code, which allows multiple DS18S20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18S20s distributed over a large area.




Device Overview
The figure below shows a block diagram of the DS18S20. The 64-bit ROM stores the device’s unique serial code. The scratchpad memory contains the 2-byte temperature register that stores the digital output from the temperature sensor. In addition, the scratchpad provides access to the 1-byte upper and lower alarm trigger registers (TH and TL). The TH and TL registers are nonvolatile (EEPROM), so they will retain data when the device is powered down.

Operation


The core functionality of the DS18S20 is its direct-to-digital temperature sensor. The temperature sensor output has 9-bit resolution, which corresponds to 0.5°C steps. The output data is calibrated in degrees centigrade and is stored as a 16-bit sign-extended two’s complement number in the temperature register. The power-on-reset value of the temperature register is +85°C. The sign bits (S) indicate if the temperature is positive or negative: for positive numbers S = 0 and for negative numbers S = 1. A table below shows some examples of digital output data and corresponding temperature reading.

Step-by-Step Operation Sequence
Now we will discuss one of the simplest ways for accessing the DS18S20. We assume that there is only one such device on bus, and say the bus is connected to RB.0 pin of a PIC16F628A. We will also discuss the built-in OneWire library functions available in mikroC for PIC 2009.

1) All transactions on the wire bus should begin with an initialization sequence. The bus master (microcontroller) should transmit a reset pulse first, and in its response, the DS18S20 will send the presence pulse indicating that it is on the bus and ready to operate. During the initialization sequence the bus master transmits (TX) the reset pulse by pulling the 1-Wire bus low for a minimum of 480ฮผs. The bus master then releases the bus and goes into receive mode (RX). When the bus is released, the 4.7kฮฉ pullup resistor pulls the 1-Wire bus high. When the DS18S20 detects this rising edge, it waits 15ฮผs to 60ฮผs and then transmits a presence pulse by pulling the 1-Wire bus low for 60ฮผs to 240ฮผs.
The mikroC function to reset the DS18S20 is Ow_Reser(&PORTB, 0).

2) Since there is only one device on the bus, no need to search, read and match the 64-bit ROM address. Rather, the master device can skip the whole ROM sequence by sending SKIP ROM [CCh] command. If there were more than one device on the bus, the master can use SEARCH ROM [F0h], READ ROM [33h], and MATCH ROM [55h] commands to address one specific device on the same bus. The mikroC function to issue SKIP ROM command is Ow_Write(&PORTB, 0, 0xCC).

3) Next use CONVERT T [44h] command to initiate a single temperature conversion. Following the conversion, the resulting thermal data is stored in the 2-byte temperature register in the scratchpad memory. The mikroC function to issue CONVERT T command is Ow_Write(&PORTB, 0, 0x44).

4) Use READ SCRATCHPAD [BEh] command to read the contents of the scratchpad. The data transfer starts with the least significant bit of byte 0 and continues through the scratchpad until the 9th byte (byte 8 – CRC) is read. The master may issue a reset to terminate reading at any time if only part of the scratchpad data is needed. The mikroC function to issue READ SCRATCHPAD command is Ow_Write(&PORTB, 0, 0xBE). After that you can use Ow_Read(&PORTB, 0) to read one byte of data via the one wire bus. In order to read both the bytes of temperature register, use Ow_Read command twice.
 OneWire Library in mikroC for PIC


To explore more about DS18S20 device, read the datasheet.

Comments

  1. Any time children's temperatures reach or exceed 101ยบ Fahrenheit it should be reported immediately to the pediatrician. High temperatures may indicate the beginning of a serious infection requiring medical attention. Many households now have digital thermometers which came with specific instructions.

    nitrile exam gloves

    ReplyDelete
  2. hye mr raj..
    im hv some problem to interface with PIR sensor (PIR sensor (#555-28027)). im use PORTA.0 as a input then when the sensor detect,it will turn ON the LED at PORTB.0(pin B0).. can u show me,how exactly the coording..

    ReplyDelete
  3. Thanks for the post.

    For AVR/PIC/8051 Projects And Tutorials
    Embedded Projects Blog
    microcontrollerprojects00.blogspot.in/

    ReplyDelete
  4. Thanks for sharing information about measuring device. Digital Thermometer

    ReplyDelete

Post a Comment

Popular posts from this blog

Contact less tachometer using PIC16F628A

Introduction Tachometer is a device that gives you the information about the rotational speed of any shaft or disc. It usually measures the speed in revolutions per minute (RPM). Today we are going to make a simple tachometer that could measure the rotation speed of a disk without making any physical contact (that's why it is contact less) with the rotating object. The range of this tachometer is 0 - 9999 RPM and displays the RPM on a multiplexed 4-digit seven-segment display. Of course, we are going to do this project on our usual PIC16F628A development board. Infrared sensor Contact-less measurement of RPM will be achieved through an IR sensor. An IR diode will send a beam of infrared towards the rotating disc, and any reflected pulse will be received by a photo diode. The resistance of a photo diode drops drastically when exposed to infrared. An infrared is reflected by a white surface and absorbed by the dark ones. The test disc for this project is shown below. You can see

Experiment No. 2 : Push Button and Seven Segment Display Interface

In this experiment, we will program the PIC16F628A as an UP/DOWN Decade Counter. The count value will be displayed on a Seven-Segment Display and will be incremented/decremented by two push buttons on the board. Experimental Setup: The board has built in interface for a multiplexed 4-digit seven segment display (HS-5461AS2 from www.futurlec.com ).We will select only one digit by connecting a Digit Select pin to Vcc, as shown in figure below. A black jumper wire is used for this purpose. The seven segments will be driven through PORTB (already wired on the board). Connect Push Buttons (PB3 and PB4) to RA1 and RA0 female headers using jumper wires.

PIC16F628A Development Board

The development board we are going to make for our experimental microcontroller PIC16F628A will look like this. Here are the features it is going to have: Access to all I/O pins through female header pins 4 Push Buttons for Input 4 LEDs for Output An LCD Interface Port A 4-digit Seven-Segment Display Interface LCD Backlight Switch and Contrast Adjustment ICSP Programming (Very Important)