DS18B20 Does readtemp12 set configuration register to 12bit?

radiosparks

Member
I've been given a hand full of these (DS18B20) temperature sensors. They are known to be counterfeit. During testing with readtemp12 they are all resolving 11BITs or a step of 0.125. This could mean the EEPROM has been set or the configuration register cannot be written to.

I've probably answered the question myself from testing the temperature sensors ... I would to hear it from (the horses mouth) ...

Does the configuration register get set to 12BITs when using the function readtemp12?


Sorry, I don't seem the get the correct code colouring. There is no BASIC selection.


C:
'   /**************************************************/
'  /* Read DS18B20 Temperature 12 bits - (08M2 chip) */
' /*  radiosparks - rhb.20231202                    */
'/**************************************************/

#PICAXE 08M2
#Terminal 4800 ; start terminal as needed

'  /**********************/
' /*      PORT/PIN      */
'/**********************/

Symbol     OneWirePORT = C.4

'  /**********************/
' /* Register Variables */
'/**********************/

symbol TemperatureWORD = w0
symbol        varPREV  = w1
symbol        varTEMP2 = w2
symbol        varTEMP3 = w3

'  /*********************/
' /* Main Program Loop */
'/*********************/

INITcode:

pause 3000 ; Delay to allow terminal to startup
Sertxd ( "Program Start: READY", CR, LF )

Main:

Do
    Gosub showSignedTemperature
Loop

'  /***************/
' /* Subroutines */
'/***************/

showSignedTemperature:
    
    readtemp12 OneWirePORT, TemperatureWORD
    pause 800
    
    if TemperatureWORD <> varPREV then
        
        if TemperatureWORD < $8000 then
            sertxd( "+" )
            varTEMP2 = TemperatureWORD
        else
            sertxd( "-" )
            varTEMP2 = -TemperatureWORD
        end if
    
        varTEMP3 = varTEMP2 & 15 * 625
        bintoascii varTEMP3, b15,b14,b13,b12,b11
    
        varTEMP3 = varTEMP2 / 16
        Sertxd( #varTEMP3, ".", b14,b13,b12,b11 )
    
        Sertxd( " C", cr, lf )
        
    end if

    varPREV = TemperatureWORD
                    
return
25946
 

hippy

Technical Support
Staff member
Does the configuration register get set to 12BITs when using the function readtemp12?
I don't know the answer to that but, given a genuine DS18B20 defaults to 12-bit, I would suspect not.

My understanding is that the DS18B20 will return a 16-bit sign-extended two's complement value no matter what resolution it is using, so the reading at 11-bit using READAC12 should be correct except for the least significant bit, which does, as you say, give a resolution of 0.125C rather than 0.0625C.
 
Top