Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

temp conversion?

Status
Not open for further replies.

MrDEB

Well-Known Member
using this code from Pommie, I am curious as to how accurate the temperature is?
I placed a potted temp sensor in ice water and could only get down to 1.5C
should it not be )c?
perhaps I need to freeze the probe in ice? for )c
Then need to ACCURATLY convert to Farienheight.
(9*Tc)/5+32
I have this but it says my temperature is 21.5celius or 145degrees farienght (Am not real good at math so I know in the code I did the conversion wrong.
My goal is to use an LCD display that displays the temperature of 3 different coolers (food, walk-in and a beer cooler walk-in)
Health dept. want 36-40 degrees in the food coolers.
I want 34degrees in the beer cooler
Code:
DEVICE = 18F1320
CLOCK = 8 // 8MHz clock
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

INCLUDE "OW.bas"
INCLUDE "USART.bas"
INCLUDE "DS18B20.bas"
INCLUDE "CONVERT.bas"
INCLUDE "String.bas"

DIM Temperature AS WORD
DIM i AS BYTE
DIM ROM(8) AS BYTE

OSCCON = $72            // select 8MHz internal clock
ADCON1  = $7f           //all digital
TRISA.3=0               //A3 output
PORTA.3=1               //and high
SetBaudrate(br9600)
OW.SetPin(PORTA.4)
WHILE true
    IF OW.Reset THEN
        OW.WriteByte(owReadROM)    //Skip ROM
        USART.Write("Rom = ")
        FOR i = 0 TO 7
            ROM(i)=OW.ReadByte()
            USART.Write(Right("00"+HexToStr(ROM(i)),2))
        NEXT
        OW.Reset
        OW.WriteByte(owSkipROM)    //Skip ROM
        OW.WriteByte($44)          //Convert
        OW.Reset
        OW.WaitForHigh              //wait for convert to finish
        OW.Reset
        OW.WriteByte(owSkipROM)    //Skip Rom
        OW.WriteByte($be)          //Read Scratch Pad
        Temperature=OW.ReadByte()
        Temperature=(Temperature+OW.ReadByte()*256)
        IF ROM(0)=$28 THEN
            Temperature=Temperature/8
        ENDIF
        USART.Write(" Temperature = ",DecToStr(Temperature/2))
        IF (Temperature AND 1) = 1 THEN
            USART.Write(".5") 
            USART.Write("Celius",13,10) 
       USART.Write(" Temperature = ",DecToStr(Temperature*9/5+32))
       USART.Write("F",13,10) 
       DELAYMS(2000)     
        ENDIF
       
    ELSE
        USART.Write("No device found", 13, 10)
    ENDIF
    DELAYMS (100)
WEND
END
 
hi DEB,
If the tempr sensor is a LM35, the spec is +2Cdeg thru +150Cdeg.
It can be modified to read lower

EDIT: I dont do C, but is looks like DS18xxx so the above dosnt apply....
 
Last edited:
The variable temperature is double the actual so it should be,
Code:
    USART.Write(" Temperature = ",DecToStr(Temperature*9/[COLOR="red"]10[/COLOR]+32))

Mike.
 
Am trying the suggested math.
Using an ice bath.
QUESTION - in the data sheet it mentions about the resolution of temperature mesaurments.
( to 12 bits. What sets this resolution in the posted code and what to change to make it read 12 bits if it isn't already reading 12 bit resolution?
Then get the usart to display ONLY the temps not the ROM id number everytime it resets which seems eractic.
The reset is going wild as I type here (using a second computer) its constantly reseting.
Been sitting in ice bath for about 4 minutes and its only down to 1.5C 34F
 
resolution setting

in the DS18B20 .bas it has a resolution section
Code:
Public Sub SetResolution(pValue As Byte)
   ReadSP
   FSP(4) = pValue
   WriteSP
End Sub
but what to change?
was thinking change the pvalue but totally lost.
 
Status
Not open for further replies.

Latest threads

Back
Top