Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20562

BASCOM-AVR : 18B20 errors : NEWTOPIC

$
0
0
For some time now I have had a problem with rogue temperatures from the Dallas 18B20 sensor, and have decided to do some investigation. This problem is on about 20 different boards so is not a faulty sensor. I am using it in the power mode, with regulated +5, and a 4k7 pullup on the signal line. The sensor is on 400mm of twisted 3 core cable, connected directly to my PCB. My code is shown below. I have left a test setup running for 24 hours and so far have had 65 temperature errors, doing a temperature read about every 2 seconds. This sub is called every second. the processor is the atmega 1284P. The sensor is reading the temperature of my office, which in winter ranges between 15C and 20C. [code:1:3e6eacb98a] read18b20: '------------------------------------------------------------------------- 'DALLAS DS18B20 ROM and scratchpad commands '&H33 read rom - single sensor '&H55 match rom, followed by 64 bits '&HCC skip rom '&HEC alarm search - ongoing alarm >TH <TL '&HBE read 9 bytes incl CRC from scratchpad '&H44 convert T '&H48 copies scratch to eeprom '&H4E write 3 bytes to scratch. Th, Tl, Config 'unit defaults to 12 bit on power up '12 bit = 0.0625deg C '---------------------------------------------------------------------------------- 'Dim DS18B20_integer_temp As Integer Dim DS18B20_Sc(9) As Byte Dim mytemperature as integer dim mytemperaturesingle as single dim tempb as byte 'temporary 1wreset 'reset the device if err <> 0 then incr tempb 1wwrite &HCC 'skip-address all devices 1wwrite &H44 'convert T wait 1 'wait 1 sec for conversion 1wreset 'convert if err <> 0 then incr tempb 1wwrite &HCC 'skip rom command 1wwrite &HBE 'read scratchpad Ds18b20_sc(1) = 1wread(2) mytemperature = makeint(Ds18b20_sc(1) , Ds18b20_sc(2)) 'print #1 , bin(mytemperature) mytemperaturesingle = mytemperature * .0625 print #1 , mytemperaturesingle ; if mytemperaturesingle > 30 or mytemperaturesingle < 10 then incr tempb print #1 , " Errors = " ; tempb return [/code:1:3e6eacb98a] Here is a typical instance of an error [list:3e6eacb98a] 15.875 Errors = 23 15.9375 Errors = 23 1039.9375 Errors = 24 15.9375 Errors = 24 15.9375 Errors = 24[/list:u:3e6eacb98a] So far i have had bad readings of : 50.5, 1042.5, 530.375, 274.5, -2029.375, 146.0625, 1039.5 etc None of the errors have been due to the err bit being set. I am about to try a 2k2 pullup and will report back. [b:3e6eacb98a][color=red:3e6eacb98a](BASCOM-AVR version : 2.0.7.6 )[/b:3e6eacb98a][/color:3e6eacb98a]

Viewing all articles
Browse latest Browse all 20562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>