Speed of reading DS18B20

Begonnen von malc_b, 22 März 2020, 13:41:49

Vorheriges Thema - Nächstes Thema

malc_b

Hi,

I've tested the reading speed of a DS18B20 in Fhem using OWDevice and OWServer.  The test code is:


my $result;
my $Tstart = time();
for (my $i=0; $i<10; $i++) {
$result = fhem("get DS18B20_AD5579A21603 temperature9");
}
my $Tend = time();
print "temperature9 = $result\n";
print "time for 10 is ".($Tend-$Tstart) ."s\n";

return ($Tend-$Tstart)/10;


Time taken is 6s whether I use temperature9 or temperature12 (I am reloading utils after changing BTW).  Attrib uncached is set to 1.  If I set uncached to 0 then time is 1s for 10 so it looks like uncached is working.  I've tried setting the resolution attribute to 9 or 12, no difference in times.  I've tried change the resolution direct in OWFS which the scratchpad data shows has occurred.  Always 6s.  According to the datasheet conversion time is ~100ms at 9 bits and 750ms at 12bits, so 10 runs should be longer than 6s anyway.
 

KölnSolar

I did similar testing with GPIO4, changed the module to be able to change precision. The reading times measured changed as expected according to the data sheet. Nevertheless, since I changed the module to blockingcall, time is no longer an issue.
RPi3/2 buster/stretch-SamsungAV_E/N-RFXTRX-IT-RSL-NC5462-Oregon-CUL433-GT-TMBBQ-01e-CUL868-FS20-EMGZ-1W(GPIO)-DS18B20-CO2-USBRS232-USBRS422-Betty_Boop-EchoDot-OBIS(Easymeter-Q3/EMH-KW8)-PCA301(S'duino)-Deebot(mqtt2)-zigbee2mqtt

malc_b

Did you mean non-blocking call so time no longer an issue?

Time for DS18B20 conversion at 12 bits is meant to be ~1s so how does it do 10 in 6s?  Admitted ~1s is max figure but if 12 bits is running faster then why is 9 bit conversion not faster than still and much less than 6s?

KölnSolar

ZitatDid you mean non-blocking call so time no longer an issue?
Yes. But be aware: in GPIO4(raspberry without busmaster)
ZitatAdmitted ~1s is max figure but if 12 bits is running faster then why is 9 bit conversion not faster than still and much less than 6s
I don't know. Maybe the change of resolution didn't work ?  :-\
RPi3/2 buster/stretch-SamsungAV_E/N-RFXTRX-IT-RSL-NC5462-Oregon-CUL433-GT-TMBBQ-01e-CUL868-FS20-EMGZ-1W(GPIO)-DS18B20-CO2-USBRS232-USBRS422-Betty_Boop-EchoDot-OBIS(Easymeter-Q3/EMH-KW8)-PCA301(S'duino)-Deebot(mqtt2)-zigbee2mqtt

malc_b

I've switched to using owshell in a terminal (I using a raspberry PI with DS2482-100 as 1-wire master).  What I get is:

:~# time owread /uncached/28.AD5579A21603/latesttemp
     23.8125
real    0m0.062s
user    0m0.000s
sys     0m0.021s
:~# time owread /uncached/28.AD5579A21603/temperature12
     22.4375
real    0m0.600s
user    0m0.000s
sys     0m0.021s
:~# time owread /uncached/28.AD5579A21603/temperature9
          22
real    0m0.585s
user    0m0.000s
sys     0m0.021s


lasttemp does not do a conversion, so that is very fast as expected.  Conversions should be done by temperature9 and temperature12 and the times confirm they are converting.  I've also warmed the DS18B20 up with a finger.  Doing lasttemp gives the same reading repeatedly.  Switch to temperatureX and the reading changes (up on down as finger is on/off).  So, for some reason conversion time is constant, despite the datasheet saying it changes.  I guess either the datasheet is wrong or out of data, or owserver waits a a fixed period of time for conversion (rather than checking if ready).  Given the response looks too quick then it might not be waiting long enough.



malc_b

I've tracked down the problem to a fake DS18B20.  Maxim semi say the batch number and date code don't match.  I've tried a different part and that gives:

~# owwrite /uncached/28.FF004FC21701/tempres 9
~# time owread /uncached/28.FF004FC21701/temperature
          22
real    0m0.224s
user    0m0.002s
sys     0m0.019s
~# owwrite /uncached/28.FF004FC21701/tempres 10
~# time owread /uncached/28.FF004FC21701/temperature
       21.75
real    0m0.418s
user    0m0.008s
sys     0m0.014s
~# owwrite /uncached/28.FF004FC21701/tempres 11
~# time owread /uncached/28.FF004FC21701/temperature
      21.625
real    0m0.568s
user    0m0.000s
sys     0m0.023s
~# owwrite /uncached/28.FF004FC21701/tempres 12
~# time owread /uncached/28.FF004FC21701/temperature
     21.6875
real    0m0.900s
user    0m0.000s
sys     0m0.024s

Which is more reasonable and acting as expected.