Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 01:06 20 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: DS18B20 Temp sensor problem

     Page 4 of 6    
Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 09:53pm 16 Jul 2020
Copy link to clipboard 
Print this post

Hi Daniel,
I have run out of ideas.
Your last tests show that the chips you have are capable of pulling the data line low so it is not a problem with high on resistance. I was expecting to see high on resistance which could be 'fixed' with different value pullup resistors.

My current guess is that your chip need 5V to operate and it is difficult interfacing to 5V with the CMM2 when you are relying on pullups and parasitic mode as an option.
Any changes to the firmware will most likely prevent parasitic mode from being used and while I prefer external power, we need to keep both as an option.

If you do want to use the CMM2 to monitor an Arduino in action, you will need to put in a voltage divider to drop the 5V to 3.3V
18k and 33k resistors should be OK without loading the Arduino circuit too much.

While I haven't succeeded in solving your problem, I have enjoyed the chase.

Jim
VK7JH
MMedit   MMBasic Help
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 04:16am 17 Jul 2020
Copy link to clipboard 
Print this post

Hi All,

I have been reading this thread with interest.
Sorry I haven't got any suggestions to try but I am wondering as to IF you know your DS18B20 is fake, why would you use it, even if it did `sort of work'?

Surely you couldn't rely on its accuracy in measuring anything, which is of course what you want them to do.

On the subject of fake DS18B20, I have in my pile of ... errr Crap.. somewhere a dozen or so DS18B20 probes that I bought several years ago. Assuming I can excavate deep enough to find them, is there some 'mite or even PC based code that we can run to test them as to their legitimacy?

It would be nice to know whether to toss them in the garbage bin or not.

Kind Regards

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 05:46am 17 Jul 2020
Copy link to clipboard 
Print this post

FYI, like others I just tried one I found in a spares box and it works perfectly in the CMM2.

Mike.
It's all too hard.
Mike.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 06:42am 17 Jul 2020
Copy link to clipboard 
Print this post

  bigmik said  Hi All,

It would be nice to know whether to toss them in the garbage bin or not.

Kind Regards

Mick


It is a fake if its ROM address does not follow the pattern 28-xx-xx-xx-xx-00-00-xx
There are other tests but if the ROM address doesn't have the two zero fields, It ain't right.

I have added a line to the program I posted earlier to print Fake or Genuine.

 '1WDS1820.BAS     29 March 2012
 'By Ian Delaney
 ' modified by TassyJim
 
 PinNbr = 42
 
 GetTemp PinNbr, Temp, pow$, dev$, code$
 Print "The temperature is:" format$(Temp,"% 1.3f"); " degrees C"
 print dev$;code$;pow$
 
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' Subroutine to get the temperature from a Dallas DS18B20/DS18S22
 '    or DSS20/DS1820 externally or parasite powered via 1-wire protocol.
 ' Reports temperature, device family, ROM Code and Power connection.
 ' Only 1 device allowed on the cable.
 '                                                 Iandaus
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
Sub GetTemp (PinNbr, Value,pow$,dev$, code$)
 Local T1, T2, t, a1,a2,a3,a4,a5,a6,a7,a8, device, presence, power
 Local Countrem, T1C, TConv, T1t, T1t16, Value12, a,b,c,d,e,f,g,h
 
 Tconv=750    'max time mS for temp conversion in parasite mode
 ' for slowest device
 
 ''''''''''''''''''''''''''''''
 '   Check a device is present
 ''''''''''''''''''''''''''''''
 ONEWIRE RESET PinNbr
 presence  = mm.onewire            ' reset
 print "MM.ONEWIRE ";presence
 if presence = 0 then                  ' no device
   temp = 999.99
   dev$ = "No device found!"
   code$ = ""
   pow$ = ""
   exit sub
 endif
 
 ''''''''''''''''''''''''''''''''''''''''''''''
 '   check whether power external or parasitic
 ''''''''''''''''''''''''''''''''''''''''''''''
 ONEWIRE RESET PinNbr
 ONEWIRE Write PinNbr, 1,2,&hcc, &hb4
 ONEWIRE Read PinNbr,4,1,power
 if power = 1 then
   pow$ = " using External Power."
 else
   pow$ = " using Parasitic Power."
 endif
 
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '   get ROM Code - useful if you want more than 1 device on wire
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ONEWIRE Write PinNbr,1,1,&h33 'read ROM code
 ONEWIRE Read PinNbr,0,8,a1,a2,a3,a4,a5,a6,a7,a8
 code$ = " with ROM Code "+ hex$(a1,2)+" "+hex$(a2,2)+" "+hex$(a3,2)+" "+hex$(a4,2)+" "
 code$ = code$ + hex$(a5,2)+" "+hex$(a6,2)+" "+hex$(a7,2)+" "+hex$(a8,2)
 
 ''''''''''''''''''''''''''''''''''''''''''''''
 '   determine device family from code
 ''''''''''''''''''''''''''''''''''''''''''''''
 if a1=16 then
   dev$ = "on DS1820/DS18S20"
 elseif a1=34 then
   dev$ = "on DS18S22"
 elseif a1=40 then
   dev$ = "on DS18B20"
 else
   dev$ = "Not known"
 endif
  if a6=0 and a7 = 0 then dev$ = dev$ + " (Genuine)" else dev$ = dev$ + " (FAKE!!!)"
 ''''''''''''''''''''''''''''''''''''''''''''''
 '   read temperature
 ''''''''''''''''''''''''''''''''''''''''''''''
 ONEWIRE reset PinNbr                        ' reset before command (or use flag=9)
 ONEWIRE Write PinNbr, 8, 2, &hcc, &h44      ' start conversion
 
 'read external when bit goes hi, for parasitic just wait
 If power = 0 Then
   Pause Tconv
 Else
   t = Timer
   Do
     If Timer - t > 1000 Then Error "Sensor not responding"
     Onewire Read PinNbr, 4 , 1 , b            ' conversion done?
   Loop Until b = 1
   print "Conversion time: ";timer-t
 EndIf
 
 'read temperature from scratchpad and convert to degrees C + or -
 ONEWIRE Write PinNbr, 1, 2, &hcc, &hbe      ' command read data
 ONEWIRE Read PinNbr, 2, 2, T1, T2           ' get the data
 ONEWIRE Reset PinNbr
 
 ''''''''''''''''''''''''''''''''''''''''''''''
 '   calculate temp depending on device in use
 ''''''''''''''''''''''''''''''''''''''''''''''
 'Need to analyse type of chip to calculate temp from T1 and T2
 'T2 is MSB containing sign, T1 is LSB
 if a1=34 or a1=40 then          'DS18S22 or DS18B20 is 12 bit
   If T2 And &b1000 Then       'negative temp
     'make 2s complement (1s complement+1)
     T2 = (T2 xor &b11111111)
     T1 = (T1 xor &b11111111)+1
     if T1=1 then T2=T2+1        'add the carry if required
     Value = ((T2 And &b111) * 256 + T1) / 16
     Value = -Value
   else                            'positive temp
     Value = ((T2 And &b111) * 256 + T1) / 16
   endif
 elseif a1=16 then                   'DS18S20 or DS1820 is 9bit or calc to 12bit
   if T2 AND &b10000000 then       'if MSB of T2=1 then negative
     'Read 12bit resolution and adjust
     'read scratchpad using matchrom to get Count Remaining @byte 7
     ONEWIRE Write PinNbr,1,9,&h55,a1,a2,a3,a4,a5,a6,a7,a8  'read from scratchpad
     ONEWIRE Write PinNbr,0,1,&hbe
     ONEWIRE Read PinNbr,0,8,a,b,c,d,e,f,g,h
     COUNTREM=g
     'truncate 0.5deg value (or use integer division \)
     T1t = T1 AND &b11111110
     T1t=T1t / 2                   'make whole degrees
     'add compensation values read from scratchpad
     T1t16=T1t*16                  'make lsb 1/16 degree
     Value12 = T1t16 -4 +(16 - COUNTREM)    'add 12 bit value
     'take 2s complement
     T1C = (Value12 XOR &b11111111111) + 1
     Value = T1C/16                'make decimal value in degrees
     Value = -Value
   else                              'positive temp
     Value = T1 / 2                '9bit value
     'Read 12bit resolution and adjust
     'read scratchpad using matchrom
     ONEWIRE Write PinNbr,1,9,&h55,a1,a2,a3,a4,a5,a6,a7,a8  'read from scratchpad
     ONEWIRE Write PinNbr,0,1,&hbe
     ONEWIRE Read PinNbr,0,8,a,b,c,d,e,f,g,h
     COUNTREM=g
     T1t = T1 AND &b11111110      'truncate 0.5deg(or use integer division \)
     Value = T1t/2
     Value = Value - 0.25 + (16 - COUNTREM) /16   '12 bit value
   endif
 endif
End Sub


Jim
VK7JH
MMedit   MMBasic Help
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1995
Posted: 09:30am 17 Jul 2020
Copy link to clipboard 
Print this post

one for the toolbelt - great work. shame about the outcome though.

I will be testing my stock of these this weekend
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 09:34am 17 Jul 2020
Copy link to clipboard 
Print this post

Thanks Jim,


Just what I want.

Mik
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 09:53am 18 Jul 2020
Copy link to clipboard 
Print this post

Found a fake device, it returns 1000 or 3.0625 if polled to fast, polled > 500ms returns only 1000 on the CMM2.

Tested with the Code posted by Jim:

Conversion time of 572.85

Temperature 24.500 degrees C.

DS1820/DS18S20  FAKE!!!

Mike.
Edited 2020-07-18 20:01 by KeepIS
It's all too hard.
Mike.
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 10:26am 18 Jul 2020
Copy link to clipboard 
Print this post

  KeepIS said  
DS1820/DS18S20  FAKE!!!


I am wondering "how fake" those are ...

Of course if you order and pay for a genuine item then it has to be!

But how bad are the cheap chinese ones really?

Are they really useless or at least worth their price?
Andre ... such a GURU?
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 10:57am 18 Jul 2020
Copy link to clipboard 
Print this post

Hi all,

sorry for my late reply!

@ Jim
I tested to operate the fake ds18b20 at 5 volts supply. but didn't worked either on the maximite. I think after all these tests it is kind of pointless to do further tests on it because as Mick already said; I should better use Genuine ones.

@ Mick

I was never foreced to check whether my sensors are couterfeit or not, because they worked for me (not one single problem or missreading) on my atmega328 projects. The problems on the maximite got me to check whether they are fake or not. So I ran a testprogram to prove it.

As far as I can tell, after working with those fake sensors for years (!) they worked pretty preceise for me. But as I already said, I bought some real Genuine ones now.
I am still waiting for them, so I wasn't able to test them yet. But if I have done this, I will post the result here.

What have I learned from this? Sometimes it is better to question whether it is a counterfeit or not. The problem is, that nowadays there are so many fakes... And often the fakes are working without any problems, at least to a certain point.

Greetings
Daniel
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 11:49am 18 Jul 2020
Copy link to clipboard 
Print this post

  KeepIS said  Found a fake device, it returns 1000 or 3.0625 if polled to fast, polled > 500ms returns only 1000 on the CMM2.

Tested with the Code posted by Jim:

Conversion time of 572.85

Temperature 24.500 degrees C.

DS1820/DS18S20  FAKE!!!

Mike.


DS18S20
That is different to he DS18B20 so I am not sure what it can or should do.

Jim
VK7JH
MMedit   MMBasic Help
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3027
Posted: 12:01pm 18 Jul 2020
Copy link to clipboard 
Print this post

  Poppy said  But how bad are the cheap chinese ones really?


It depends. I've had 4 or 8 fake ones all in a row on a PCB module, no reason to think there should be any difference between them, but have gotten variance of nearly 2 degrees C (between different DS18B20s, not on the same one with multiple readings).

~
Edited 2020-07-18 22:02 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1995
Posted: 06:37pm 18 Jul 2020
Copy link to clipboard 
Print this post

Dammit. Pretty much to be expected. All my stock report the same      

> RUN
MM.ONEWIRE  1
Conversion time:  503
The temperature is: 22.25 degrees C
on DS18B20 (FAKE!!!) with ROM Code 28 59 DF 07 D6 01 3C 00 using External Power.


but a funny thing happened. I had one doing pretty much the same as the OP... occasionally OK but largely 1000.00C (failed)... this was on a 28 pin '170 using the TEMPR function

However Jim, your code never failed to read. Odd.
Edited 2020-07-19 04:40 by CaptainBoing
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 10:48pm 18 Jul 2020
Copy link to clipboard 
Print this post

  Quote  
but a funny thing happened. I had one doing pretty much the same as the OP... occasionally OK but largely 1000.00C (failed)... this was on a 28 pin '170 using the TEMPR function

However Jim, your code never failed to read. Odd.


Same here, the code supplied by Jim always reads the correct temperature, the CMM2 will not read the temperature at all.

FYI the fake unit was purchased from a big company in AU around 10 years ago, it was supplied as a test sensor with a 4 input sensor to RS-232 board, two Stainless steel temp probes were ordered separately, I'll have to test those when I get a chance.

Mike
It's all too hard.
Mike.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 11:20pm 18 Jul 2020
Copy link to clipboard 
Print this post

Can you try using TEMPR START to see if that makes a difference.
tempr start 42, 3 : print tempr(42)


Try different levels of precision 0-3

Jim
VK7JH
MMedit   MMBasic Help
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 11:45pm 18 Jul 2020
Copy link to clipboard 
Print this post

  TassyJim said  Can you try using TEMPR START to see if that makes a difference.
tempr start 42, 3 : print tempr(42)


Try different levels of precision 0-3

Jim


tempr start 42, [0,1,2] return 1000,  3 returns 2.5625. Fake tester returns 20.438 C.
It's all too hard.
Mike.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 11:59pm 18 Jul 2020
Copy link to clipboard 
Print this post

If your device is a 18S20, I suggest you read about the differences.
https://www.maximintegrated.com/en/design/technical-documents/app-notes/4/4377.html

Jim
VK7JH
MMedit   MMBasic Help
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 12:51am 19 Jul 2020
Copy link to clipboard 
Print this post

Actually I think this might be DS1820 which was the very old type and not expected to work in the CMM2 without custom 1-wire code as in your Test app. The dev markings are mostly worn off and it was the result of the Test app that made sense of what was left on the case, interestingly it says it's a fake from 10 years ago. BTW thanks for the link.

Mike.
Edited 2020-07-19 10:52 by KeepIS
It's all too hard.
Mike.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 01:01am 19 Jul 2020
Copy link to clipboard 
Print this post

I am not sure if the serial number test is valid for anything other than 18B20 so the fake call may be false.

Your devices are certainly acting like a 1820 or 18S20.
Need the slow conversion speed and if you multiply the reading by 8, you get a close to expected reading.

Jim
VK7JH
MMedit   MMBasic Help
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 04:57am 19 Jul 2020
Copy link to clipboard 
Print this post

  Amnesie said  [...]
What have I learned from this? Sometimes it is better to question whether it is a counterfeit or not. The problem is, that nowadays there are so many fakes... And often the fakes are working without any problems, at least to a certain point.

Greetings
Daniel


hi Daniel,
   i would still be really keen to see the output from Jim's capture program, of the data exchanged between the 'clone' DS18B20 and arduino when a sucsssful data read is made:



ie, using the CMM2, effectively, as an oscilloscope. in this way we can determine why the sensor can be read by an arduino but not by mmbasic, and eliminate there being any defect in mmbasic. or, indeed, so geoff can improve mmbasic so that it can read from both 'varieties' (genuine and clone) of DS18B20.


cheers,
rob   :-)
Edited 2020-07-19 15:00 by robert.rozee
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 07:07am 19 Jul 2020
Copy link to clipboard 
Print this post

I just tested 5 of them; all genuine but coming up as on parasitic power inc pin(42). All are 3 wire.

Speaking of fakes. I ordered & received a batch from Ebay a number of years ago. These weren't just fakes, they were something entirely different within the standard package.

I found one this morning when doing some tidying up. Got really hot when plugged in for a test.

Brian
ChopperP
 
     Page 4 of 6    
Print this page
© JAQ Software 2024