readtemp takes 750ms - utilizing the time?

KTarke

Senior Member
Hi Ktarke try this as your covert program
even tho accuracry only of the sensor 5% from-10 to 85 degrees.
this will give you a bit more resolution.
and give you a negative result to
Code:
Convert.
IF w0 > 64655 THEN                  '  info     - 55 degrees          = 64656
                                             ' display temp negative degrees -c                           
w0 = - w0                                ' make neg positive lol
ENDIF
w0 = w0* 5/8                           ' do the temp pos side  (0.0625)
                                              'accuracy   to 12bit (on the maths side lol)
let b2=w0/10
let b3=w0//10

That was my point: no use of reading with better resolution, if only half-grade results are used.

Today I was looking at the negative conversion ,too.
And do not fully understand Your code.

I wrote one like this:

Code:
if bit3=1 then:b10=5 :endif					'detect half grade
if bit11=1 then:neglippu=1:b9= w0/16:b9= NOT b9:endif	'convert negative to positive
if neglippu=0 then:b9=w0/16 AND 127:endif
-b10 is used to keep the half-grade
-variable "neglippu" is negative flag (word flag seems to be reserved...)
-operator NOT converts the negative binary to positive

Then I can:
serout (#b9,".",#b10," C")
OR this,if negative flag is set:
serout ("-",#b9,".",#b10," C")

It is good to keep the whole degree and half-degree separate, because in thermostat-circuits the comparisons (and actions) base themselves on the whole degrees, anyway.
 

marks

Senior Member
Hi Kt,
sorry I dont have lcd yet so cant try serout
i just have a 20x2 took me a while to work out sertxd lol
just open the terminal seems to start at 9600 by itself
do have one for F degrees to

Code:
temp:
owout c.7,%1001,($CC,$44)                          'reset(send skip rom ,send convert t)
  
owout c.7,%0001,($CC,$BE)                          'reset(send skip rom ,send read lsb msb)
                          
owin c.7,%0000,(b2,b3)                             'read in result ds18b20

 convert:                                          '  info     +125 degrees / 0.0625 =  2000
  let b9 =43                                       'Display + (43)   space (32)
IF W1 > 64655 THEN                                 '  info     - 55 degrees          = 64656
  let b9 =45                                       'Display - (45)
W1 = - W1                                          '  info   if - ie w1=1000   display 10.00 -c
ENDIF                                
W1 = W1 * 50 / 8                                    '  info      + ie w1=8500   display 85.00c
                                          
BINTOASCII w1,b8,b7,b6,b5,b4 
IF b8 = "0" THEN  : b8 = " "  :ENDIF                       ' zero blanking b8
IF b8 =  " "  AND  b7 =  "0"  THEN : b7 = " "  :ENDIF      ' zero blanking b7
  
SERTXD (CR, LF, "Temperature  ",b9,b8,b7,b6,".",b5,b4,"  Degrees C", CR, LF)'resolution to 0.06

pause 1000
goto temp
 
Last edited:

marks

Senior Member
Hi Again,
shouldbe doing me own stuff but know u got me interested in the term prog lol
this will display Fahrenheit jeus had to think about spellin that
to one decimal place ie 00.0 F to 257.0 F
Code:
temp:
owout c.7,%1001,($CC,$44)                          'reset(send skip rom ,send convert t)
  
owout c.7,%0001,($CC,$BE)                          'reset(send skip rom ,send read lsb msb)
                          
owin c.7,%0000,(b2,b3)                             'read in result ds18b20
 
 convert:
                                           
  IF W1> 65251then                                   '   info 0.F - 32.F
 W1=-W1
 W1=W1*9/8-320
 W1=-W1                                               '   info   ie  w1=10      Display   01.0F
 else                                               '   info 32.F - 257.F
 W1 = W1*9/8+320                                      '   info   ie  w1=2570    Display 257.0F
 ENDIF
 
b1=w1/100
b2=w1//100/10
b3=w1//1

SERTXD (CR, LF, "Temperature  ",#b1,#b2,".",#b3,"  Degrees F", CR, LF)

pause 5000
goto temp
just wish to know how to blank b1 lol
 
Last edited:

KTarke

Senior Member
This is a very good asset to the "conversion-code-list"!

I must admit, that I cannot even in my head figure how many C-degrees is 100F... but there is a lot of people in those countries that uses F.

AND I wrote an answer to Your previous messag, too, but it vanished somehow, when sending.

To the previous one, I just commented, that (if someone wants to use / understand these experiments) reading with full resolution takes 750ms, reading with 9-bit resolution takes 100ms, and that should "show" in the code. Else the example code does not work...

And if someone is wondering, what is actually done in these conversion -examples, one should download the DS18B20 -datasheet.
Page 4 in it gives a good expression, how 1820 stores the temp-reading.
 
Last edited:

marks

Senior Member
convert code is just converting the sensor data as a word in original form
its easier than converting the bytes seperately will be the same for 9,10,11,12 bit reading
but if our convert code is not so good we can also loose resolution in the maths also
luckily our ds18b20 scales easily.

(when using above owin commands)
by default is set to 12 bit read which we get
using same supply just using simple read command
is very quick.(oh yes 1 slave on bus only)

if using other functions alarm and eprom this will take longer

if using external supply and requiring read time slots
this can take up to a MAX 750ms for 12bit
if we need this quicker we can reduce the bit read.

the above code is abit of trick lol because we are not waiting for the conversion
we are infact reading from the previous one so if we update every minute
the data is one minute old.
it was found a PAUSE 510 was needed after the convert command
owout c.7,%1001,($CC,$44) to get the instant update
and when first powered up you would need longer
its probaly why readtemp12 takes 750ms you dont need to pause
and it guarentees instant update even when first powered up.
 
Last edited:

KTarke

Senior Member
The remark of reading datasheets was not meant for You...:)

I just see this thread has grown educational, and wanted to give the future readers tips, how to understand the shown codes.

As conclusion, this thread began with considering ,how to use the "spare" time when waiting DS1820 giving a result (because it takes so long, 750ms)

And we have ended with a new routine, that reads the temperature in 100ms.

Plus, there is already many different examples, how to convert the DS1820's result to degrees (You are right, conversion codes are the same, no matter in what resolution the temperature is measured)
 

westaust55

Moderator
@Marks,


Note that
b1 = w1/100 ; w1 = byte variables b3:b2
b2 = w1/100/10 ;
b3 = w1/1 ; but the previous line has corrupted w1 since b2 and w1 overlap.


As a suggestion, for the display program line,
If word variable w1 contains the temp value x 10 for 1 decimal place then try (untested)

BINTOASCII w1, b8,b7, b6, b5,b4 ; variable b8 is then just thrown away – could even try b7 in place of b8 and see if 10,000’s is worked out before 1,000’s part.

For a leading blank use:
IF b7 = "0" THEN
B7 = " "
ENDIF
SERTXD ( b7, b6, b5,".",b4)
 
Last edited:

marks

Senior Member
Have to write a hint book for oneself
having trouble with the title

Westys brilliant code snipets
or
Marks bad coding examples lol
Code:
temp:
owout c.7,%1001,($CC,$44)                          'reset(send skip rom ,send convert t)
  
owout c.7,%0001,($CC,$BE)                          'reset(send skip rom ,send read lsb msb)
                          
owin c.7,%0000,(b2,b3)                             'read in result ds18b20
 
 convert:
                                           
 IF W1> 65251 THEN                                    '   info 0.F - 32.F
 W1=-W1
 W1=W1*9/8-320
 W1=-W1                                               '   info   ie  w1=10      Display   1.0F
 ELSE                                                 '   info 32.F - 257.F
 W1 = W1*9/8+320                                      '   info   ie  w1=2570    Display 257.0F
 ENDIF
 
BINTOASCII w1,b8,b7,b6,b5,b4
IF b7 = "0" THEN  :  B7 = " "  :  ENDIF                  ' zero blanking b7
IF b7 = " " AND b6 = "0"  THEN : B6 = " " : ENDIF        ' zero blanking b6

SERTXD (CR, LF, "Temperature  ",b7,b6,b5,".",b4,"  Degrees F", CR, LF)'resolution to 0.1

PAUSE 1000
GOTO temp
This works better
Had so much fun with sertxd may have to look into getting a lcd lol
 
Last edited:
Top