Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 02:27 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 2 of 6    
Author Message
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 09:07pm 14 Jul 2020
Copy link to clipboard 
Print this post

Hi Volhout,

good idea, just tried it - no success. I also tried a similar attempt:

I connected another of my ds18b20 on pin 24 (BUS) from there a 4,7k to 5Volts and the other pin to GND - this is the way I am used to connect the sensor with my other projects on the atmega328p, but: no success again.

I measured the voltage again on the 1-wire BUS with your 22k suggestions: it was now at 3,2 to 3,3 volts.

With my attempt, it was at 3,3 volts on the 1-wire-BUS and as I said 5v at the Vdd (accordingly to your picture).

I don't know whats going wrong... I checked all my three sensors again with my other little BASIC computer, based on atmega328.. and yes they are still working.

??? no idea...

Greetings
Daniel
Edited 2020-07-15 07:09 by Amnesie
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8607
Posted: 09:53pm 14 Jul 2020
Copy link to clipboard 
Print this post

just to be pedantic run the following:

option milliseconds on
do
pause 1000
print time$
loop

is the time incrementing by 1 second +/- 2 mSec?
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 10:05pm 14 Jul 2020
Copy link to clipboard 
Print this post

  matherp said  just to be pedantic run the following:

option milliseconds on
do
pause 1000
print time$
loop

is the time incrementing by 1 second +/- 2 mSec?


Here it is...


 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 10:38pm 14 Jul 2020
Copy link to clipboard 
Print this post

Your timing looks good so that is not the problem.

Can you confirm that you are operating in external power mode.
Using three wires as in fig 5 of Volhout's post

Jim
edit:
I just changed mine over to parasitic power but it still works 100% of the time
Edited 2020-07-15 08:45 by TassyJim
VK7JH
MMedit   MMBasic Help
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 10:55pm 14 Jul 2020
Copy link to clipboard 
Print this post

Hi Jim,

I am using the external power mode. Tried it with 3.3V supply and with 5v supply (external on breadboard with a 4,7kohm to 1-wire-bus)
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3590
Posted: 06:53am 15 Jul 2020
Copy link to clipboard 
Print this post

Hi Amnesie,

Just to be sure....
You are connecting to a single DS18B20, correct? Not a chain of 3?

Volhout

Edit: it must be something digital. Otherwise you would never get exactly 1000. It is like this '1000' is some form of error message or default when the CMM cannot resolve the message from the DS18B20. Or when the DS18B20 is still busy....and you are trying to communicate with it too early for it's chosen resolution (9/10/11/12 bit)..
Edited 2020-07-15 16:59 by Volhout
PicomiteVGA PETSCII ROBOTS
 
TassyJim

Guru

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

1000 is the error value. It is what you get returned if no device is present.

Amnesie,
Can you try this program.
It was written before we had the builtin TEMPR function and might be easier to find the problem.

I have made a couple of changes to allow it to run on the CMM2
You may have to change the PinNbr if you are not using the pin 42.
 '1WDS1820.BAS     29 March 2012
 'By Ian Delaney
 
 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
 
 ''''''''''''''''''''''''''''''''''''''''''''''
 '   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


My system with the DS18B20 configures for parasitic power gives:
MM.ONEWIRE  1
The temperature is: 21.000 degrees C
on DS18B20 with ROM Code 28 CA A0 F2 05 00 00 3E using Parasitic Power.
>



Jim
edit
fixed bug in code
Edited 2020-07-15 18:08 by TassyJim
VK7JH
MMedit   MMBasic Help
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 09:55am 15 Jul 2020
Copy link to clipboard 
Print this post

Hi,

thank you Jim for the help, my ds18b20 is reacting every time different. On the image you can see all kinds of errors. :(

I attached my ds18b20 libarary, which works for all my sensors on the atmega328p below (maybe anyone can spot a difference?)

@ Volhout, no I am using just one ds18b20 at a time. I am used to this sensors from my atmega328 projects, so at least, I know how to work with them on the atmega328p (there all three work). I just mention three because I have got all the tested individualy with the maximite. None of the works all the time.

On the image, you can see 3 different "states" / possible readings (I don't know how to call it), over the time, all those redings are repeating in a coincitential sequence.
I took a picture, so you can see all three  possible readings.

It is interesting, that with this program, the temperature isn't correct (if it has found the sensor). -16,062°C? Also the ROM Code appears to be whether FF FF FF ...
or 28 5C BA 56 .....

Now




With this library for my atmega328 all three sensors work! Just in case you can see some differences...
Edited 2020-07-15 20:09 by Amnesie
 
TassyJim

Guru

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

The conversion time should be about 600mS.
It looks like the data being returned is very unreliable.
Do you have a CRO that you can monitor the data line with?

Can you change it to parasitic power and try again.
That way the program waits 750mS rather than interrogate the device while waiting for the conversion to finish.

Jim
VK7JH
MMedit   MMBasic Help
 
Amnesie
Guru

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

I have attached a library to my other post, but somehow it dosn't work and I again can not edit my earlier post.. So another try. With this libarary, all my three snsors work on the atmega328.

@ Jim, what do you mean by CRO? Never heard that before. cathode ray ocilloscope? The only words, which make sense to me :)

Sadly I have got no oscilloscope around me.


ds18b20.zip
Edited 2020-07-15 20:15 by Amnesie
 
Amnesie
Guru

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

In parasitic mode I get not one single correct reading at all!


 
TassyJim

Guru

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

No Oscilloscope...
We will have to see if we can make the CMM2 into one.
But not tonight.

I will think about it and do some experiments tomorrow.

I really do want to see what is happening on those data lines.

Jim
VK7JH
MMedit   MMBasic Help
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 12:12pm 15 Jul 2020
Copy link to clipboard 
Print this post

Hi Jim,

pretty impressive, to make the CMM2 into an oscilloscope.
Sooner or later I will buy one, as prices are falling with every year.
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 12:37pm 15 Jul 2020
Copy link to clipboard 
Print this post

The Forum software still sucks in some ways and ate up my reply.

I just want to point on my last in case of need.

And if you make the CMM2 an Oscilloscope just also make it a new topic for being separately interesting!

Andre ... such a GURU?
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 12:51pm 15 Jul 2020
Copy link to clipboard 
Print this post

  TassyJim said  
Can you try this program.

 ' Only 1 device allowed on the cable.

 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '   get ROM Code - useful if you want more than 1 device on wire
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Hi Jim,
I assume this code can be modified to run more than one device per cable if you know the ROM addresses?

Brian
ChopperP
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 12:58pm 15 Jul 2020
Copy link to clipboard 
Print this post

arduinos generally run the micro at 5v, whereas micromites and maximites are generally operated at 3v3. i wonder if it could be that all your DS18B20 devices are 'clones' and only operate reliably with everything at 5v.

try hooking the DATA pin of the DS18B20 to a 5v tolerant pin (3, 5, 11, etc) on the CMM2, and run both the 4k7 pullup and the Vdd pin of the DS18B20 to 5v (pin 2 or 4 on the 40-pin connector).


cheers,
rob   :-)
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 12:58pm 15 Jul 2020
Copy link to clipboard 
Print this post

  Poppy said  The Forum software still sucks in some ways and ate up my reply.


Gizmo has mentioned a few times that longish replies are probably best done in a text editor then copied into the reply box.

Copying your message to the clip board every few lines as you go would also work as you could paste it back again if lost.
ChopperP
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 01:03pm 15 Jul 2020
Copy link to clipboard 
Print this post

@ Andre

Thank you, but I have ordered now original Dallas 18b20 sensors in germany. The point is; my sensors do 100% work, I checked all three of them with my other BASIC computer which is bulilt up on an atmega328p and all of them are working without a single problem or miss-reading. That is why it might help, if I post the ds18b20 library I am using with them?

Would be interesting, if there is a different approach in "my" library than in the maximite one - although I am sure that Peter doesn't used a premade library, instead coded it all by himself.

I am curious whether my just ordered original ds18b20 will work...

Just in case anybody is interested, with this library, all my sensors do work:


ds18b20.zip

@ Rob

  Quote  try hooking the DATA pin of the DS18B20 to a 5v tolerant pin (3, 5, 11, etc) on the CMM2, and run both the 4k7 pullup and the Vdd pin of the DS18B20 to 5v (pin 2 or 4 on the 40-pin connector).


I posted this in an earlier post, done that before. This was my assumption, too. But doesn't work.
Edited 2020-07-15 23:08 by Amnesie
 
bigfix
Senior Member

Joined: 20/02/2014
Location: Austria
Posts: 124
Posted: 01:25pm 15 Jul 2020
Copy link to clipboard 
Print this post

Not sure if this was posted already :

Github Doc: Your DS18B20 temperature sensor is likely a fake, counterfeit, clone...
Github DS18B20 Clones

Here you see the flavors and different behaviours and some hints how to ident

Maybe somebody will write a certification test program ?
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 385
Posted: 01:58pm 15 Jul 2020
Copy link to clipboard 
Print this post

I just tested whether my ds18b20 is a fake or not with the suggested test methods via my atmega328p

RESULT as expected:  

  Quote  
28-8A-39-56-B5-01-3C-CD: ROM does not follow expected pattern 28-xx-xx-xx-xx-00-00-crc. Error.
 Scratchpad Register: 90/01/55/05/7F/A5/A5/66/B4
 Info only: Scratchpad bytes 2,3,4 (55/05/7F):  not Maxim default values 4B/46/7F.
 Scratchpad byte 5 (0xA5):  should have been 0xFF according to datasheet. Error.
 Scratchpad byte 6 (0xA5):  unexpected value. Error.
 Scratchpad byte 7 (0x66):  should have been 0x10 according to datasheet. Error.
 0x4E modifies alarm registers:  ok.
 0x4E accepts 10 bit resolution:  ok.
 0x4E preserves reserved bytes:  ok.
 0x4E accepts 12 bit resolution:  ok.
 0x4E preserves reserved bytes:  ok.
 Checking byte 6 upon temperature change: not necessary. Skipped.
 --> Sensor appears to be counterfeit based on 4 deviations.


But what I still not understand: why does the sensor work with my atmega328p?
There must be something different in the maximite firmware than in the library I used.
The obvious fact, that on my atmega328, the sensors run @ 5Volts can not be the problem, because I tried it with the maximite, too.

But as I said: I ordered a original ds18b20 here in germany at a licenced distributor. And will reply the results!

Nevertheless it would be cool, if the maximite would even run with counterfeits, since (according to this link Andre & bigfix posted) nerly every sensor @ ebay is a fake one!
Edited 2020-07-16 00:00 by Amnesie
 
     Page 2 of 6    
Print this page
© JAQ Software 2024