electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Read temp with DS18S20 temperature sensor


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Read temp with DS18S20 temperature sensor
Author Message
Hasher



Joined: 14 Apr 2009
Posts: 17


Post07 May 2009 14:50   

ds18s20


I'm using PIC18F2420 with DS18S20 temperature sensor.
PIC ==> 10-bit resolution A/D module
TempSensor ==> 9-bit resolution
TempSensor ==> range: -55 C° to 125 C°

I want to read the Temp. Sensor volt as a temperature value.

I did this:

unsigned int volt;
unsigned int temp;

Code:
void main()
{
    while(1)
   {
        volt = ADC_Read(2);
        temp = 5*volt*/1024;
    }
}


Should I use Op-Amp to increase the o/p analog volt?

Or what is in code is enough?
Back to top
Jack// ani



Joined: 02 Dec 2004
Posts: 488
Helped: 25


Post07 May 2009 16:33   

ds18s20 pic


Excuse me, isn't DS18S20 a digital temperature sensor!

Why would you need a ADC when the sensor's output is already binary. Just convert it into decimal for readout.
Back to top
ndru_w



Joined: 02 Oct 2007
Posts: 26
Helped: 1


Post08 May 2009 9:32   

ds1820 temperature sensor


Exactly DS18S20 is a digital sensor which communicates with a 1-wire protocol.
Read about it, implement it (see the www.maxim-ic.com for more info - exactly: http://www.maxim-ic.com/products/1-wire/) and it'll work excellent.
Back to top
Google
AdSense
Google Adsense




Post08 May 2009 9:32   

Ads




Back to top
hugo



Joined: 01 Jan 1970
Posts: 286
Helped: 27
Location: canada


Post08 May 2009 12:45   

ds1820 pic


Hi,

Here's an example :

/*
* Project name:
Onewire_Test (Interfacing the DS18x20 temperature sensor - all versions)
* Copyright:
(c) MikroElektronika, 2005-2008.
* Description:
After reset, PIC reads temperature from the sensor and prints it on the Lcd.
The display format of the temperature is 'xxx.xxxx°C'. To obtain correct
results, the 18x20's temperature resolution has to be adjusted (constant
TEMP_RESOLUTION)
* Test configuration:
MCU: PIC16F877A
Dev.Board: EasyPIC4
Oscillator: HS, 08.0000 MHz
Ext. Modules: DS18x20 connected to RE2 pin, LCD_2x16
SW: mikroC v8.0.0.0
* NOTES:
- Pull up and turning off diode on pin used for one wire bus may be required (in this example PORTE)
*/


// Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
// 18S20: 9 (default setting; can be 9,10,11,or 12)
// 18B20: 12
const unsigned short TEMP_RESOLUTION = 9;

char *text = "000.0000";
unsigned temp;

void Display_Temperature(unsigned int temp2write)
{
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
char temp_whole;
unsigned int temp_fraction;

// check if temperature is negative
if (temp2write & 0x8000)
{
text[0] = '-';
temp2write = ~temp2write + 1;
}

// extract temp_whole
temp_whole = temp2write >> RES_SHIFT ;

// convert temp_whole to characters
if (temp_whole/100)
text[0] = temp_whole/100 + 48;

text[1] = (temp_whole/10)%10 + 48; // extract tens digit
text[2] = temp_whole%10 + 48; // extract ones digit

// extract temp_fraction and convert it to unsigned int
temp_fraction = temp2write << (4-RES_SHIFT);
temp_fraction &= 0x000F;
temp_fraction *= 625;

// convert temp_fraction to characters
text[4] = temp_fraction/1000 + 48; // extract thousands digit
text[5] = (temp_fraction/100)%10 + 48; // extract hundreds digit
text[6] = (temp_fraction/10)%10 + 48; // extract tens digit
text[7] = temp_fraction%10 + 48; // extract ones digit

// print temperature on LCD
Lcd_Out(2, 5, text);
}//~

void main()
{
ADCON1 = 7; // Configure AN pins as digital I/O
Lcd_Init(&PORTD); // Lcd_Init_EP4, see Autocomplete
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Out(1, 1, " Temperature: ");
// Print degree character, 'C' for Centigrades
Lcd_Chr(2,13,223);
Lcd_Chr(2,14,'C');

//--- main loop
while (1)
{
//--- perform temperature reading
Ow_Reset(&PORTE,2); // Onewire reset signal
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0x44); // Issue command CONVERT_T
Delay_ms(750);

Ow_Reset(&PORTE,2);
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0xBE); // Issue command READ_SCRATCHPAD

temp = Ow_Read(&PORTE,2);
temp = (Ow_Read(&PORTE,2) << Cool + temp;

//--- Format and display result on Lcd
Display_Temperature(temp);

}
}
Back to top
Hasher



Joined: 14 Apr 2009
Posts: 17


Post09 May 2009 21:34   

ds1820+pic


Ooooooooh!

Thanks budy!

But I cannot use the mikroC I have to use the Hi-Tech C compiler & it has not the 1 wire library?

????
Back to top
hugo



Joined: 01 Jan 1970
Posts: 286
Helped: 27
Location: canada


Post10 May 2009 2:29   

pic ds18s20


It's not that dificult to write 1 wire lib in C...

check this out :

http://www.pichobby.bravehost.com/DS18B20.html
Back to top
garg29



Joined: 17 Nov 2004
Posts: 352
Helped: 10


Post11 May 2009 20:54   

read temp


if you want adc type use LM35 which is also cheaper tan DS1820
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Read temp with DS18S20 temperature sensor
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Temperature regulator (how do i measure temp with pic) (5)
DS18s20 display on 20X4 LCD for temperature (1)
atmega8L avr with temp sensor (1)
Temperature Controller with TI Temperature sensor (7)
Dallas DS1821 TEmp Sensor interface with 89C51 (3)
temperature sensor - help me with this circuit (11)
Conditionning a temperature sensor type PT1000 with an FPAA (2)
interfacing pic16f73 with pressure and temperature sensor (7)
lm35-how to interface temperature-sensor circuit with zilog (4)
SHT11 temperature and humdity sensor interface with pic16 (2)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS