Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:09 09 May 2025 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 3 of 7    
Author Message
Amnesie
Guru

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

Forum Software is buggy; it is obviously on page 3, but doesn't show my post on page 3!(the one that is my latest on page 2 - this page 3 was empty until now)
@ Forum Admin
It would be great if one could edit the very first post in a topic, becaus this would allow, if a soloutin is found, to update the initial post with those hints! As it is now, you can only read through the whole topic... Not a good solution.


Again:

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!

To say something positive: The good thing is, becaus I had to order at a distributor, I took the chance to buy some left parts for my other two maximite PCBs, so I can populate & build myself another two CMM2!      

Maybe even good for cross-checking further problems  
Edited 2020-07-16 00:21 by Amnesie
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3309
Posted: 02:21pm 15 Jul 2020
Copy link to clipboard 
Print this post

  Amnesie said  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!

But it's almost certainly the case that only +some+ counterfeits fail, and a small number, since there's a huge amount of experience in the use of DS18B20s of uncertain provenance with MMBasic on a wide variety of platforms (PIC, R-Pi, ArmMite varieties for me).

It will be interesting to see if Peter or someone else can find a fix for this particular failure. Strange that it is so intermittent (but solid on the atmega328).

I wonder if you are able to test it on any other device, like the ESP8266 D1 Mini running Annex, or on a PICAXE, or on a 170, pi-cromite, or F4 running MMBasic.
Edited 2020-07-16 00:30 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Amnesie
Guru

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

@ lizby

you are right! I am really curious about the fresh ordered... Maybe in 3 days, when it arrived, we know more about it.

Weired that I come up with such a rare case again...  

  Quote  I wonder if you are able to test it on any other device, like the ESP8266 D1 Mini running Annex, or on a PICAXE.


Ahhh! Good you are saying this! I forget to mention that my sensors even work on my ESP32!!!
Edited 2020-07-16 00:28 by Amnesie
 
Amnesie
Guru

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

Sometimes a video is better to show things!

Here you can see my sensors are really working.

Youtube:

https://www.youtube.com/watch?v=hnEZUYLCCPw
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10064
Posted: 03:46pm 15 Jul 2020
Copy link to clipboard 
Print this post

Is it possible your devices are DS18S20? These have a longer conversion time than DS18B20 always > 500mSec whereas the MM range assume 200mSec per bit over 8 - i.e. 200mSec for normal operation

If this is the case using tempr start with a wait of 600mSec might work
 
Amnesie
Guru

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

  matherp said  Is it possible your devices are DS18S20? These have a longer conversion time than DS18B20 always > 500mSec whereas the MM range assume 200mSec per bit over 8 - i.e. 200mSec for normal operation

If this is the case using tempr start with a wait of 600mSec might work


No, I tried it with even higher pause. After testing all my sensors on different microprocessors / microcontroller (esp32, atmega328p) I think it is the way, the firmware does works with the ds18b20. I mean on all other devices they work (even if they are counterfeits).
The maximite is the only one it does not. I tried everything, external power mode, parasitic power mode, different supply voltage, measured the contacts and voltage.
I tried the "internal" pin 42 & a fully external wiring on breadboard on pin 24.

All things, that are obvious are tested. Timing, too.

The only thing I can't do, is analyze the onewire-bus with an oscilloscope  

If we look at it there are only two possibilities in my mind, that could be the problem.

Frist: The Maximite firmware does something differently then the library, I use on the atmega328 and ESP32.

Second: There is some noise or whatever on the onewire-bus. But for this I would need an oscilloscope. (at least I tried different powersupplys and supply-voltages on the sensor, to minimize this...)

But please don't get me wrong, I am sure there is no real "fault" or bug in your firmware! You designed it not with all those counterfeits in mind, I know.
Edited 2020-07-16 02:13 by Amnesie
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 09:43pm 15 Jul 2020
Copy link to clipboard 
Print this post

Amnesie,
can you try this change to my program
Add the line
PAUSE 700
at about line 79
 'read external when bit goes hi, for parasitic just wait
 pause 700
 If power = 0 Then
   Pause Tconv
 Else
   t = Timer


Run your module in external power mode.

Your modules are telling us they are ready immediately instead of after ~700 mS when in 12 bit resolution.

Even though the check program you ran suggests that they are switching to 10 bit mode, I suspect that they are not and that will cause problems with the MMBasic code.

Jim
VK7JH
MMedit
 
Amnesie
Guru

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

@ Jim

Tried it, doesn't change anything. I even tried a 1000ms pause and with no pause.
No difference.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 11:34pm 15 Jul 2020
Copy link to clipboard 
Print this post

Next test
Still with the device on pin 42 and external power mode.
We are giving the device a manual reset and looking for the return pulse

dim presence(2048)
dim integer n
setpin 7, din
pin(42) = 1
setpin 42, dout, oc
pulse 42, 0.481 ' change this value for testing
setpin 42, din
timer = 0
for n = 1 to 1000
presence(n) = pin(42)
next n
print timer
for n = 1 to 100
print presence(n);
if (n mod 20) = 0 then print
next n


The output should be
11.445
1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>


try changing line 7 to 0.600 or longer to give a longer reset pulse

My DS18B20 is happy with anything from 0.300 to 0.600

Jim
VK7JH
MMedit
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 12:10am 16 Jul 2020
Copy link to clipboard 
Print this post

Hi Jim,

the reading is pretty much the same every time:

  Quote  
Value is set to: 0.3
13.416
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Value is set to: 0.4
13.432
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Value is set to: 0.6
13.414
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Value is set to: 1
13.476
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 12:23am 16 Jul 2020
Copy link to clipboard 
Print this post

Time for one more test before I have things to do.
You need to connect pin 42 to pin 7 with the device still connected as before.

setpin 7, ain
setpin 42, din, pullup
pause 10
v1 = pin(7)
pause 1000
setpin 42, din, pulldown
pause 10
v2 = pin(7)
print v1
print v2

print "estimated external pullup =";str$((v1/v2)*40-40,2,2);"k"


Jim
VK7JH
MMedit
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 529
Posted: 12:38am 16 Jul 2020
Copy link to clipboard 
Print this post

That gave me:


  Quote  
>RUN
3.299949645
2.954163424
estimated external pullup = 4,68k
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 12:56am 16 Jul 2020
Copy link to clipboard 
Print this post

Thanks for that
So far we know that:
You have the correct pullup resistor.
Changes to the timing for the reset pulse makes no difference.

The next thing I will try is to see if we can measure the level that your devices are bringing the data line down to.
I suspect that they have a high impedance and are not pulling the line low enough for the CMM2 to recognise a LOW
To do this, I need to use the DAC command to read the PIN 7 fast enough.

I have run out of time today so it will have to wait again.

If timing was the answer, we could have fixed it but now I am doubtful.
I guess that the Arduino chips toggle their state at a different level.

Jim
VK7JH
MMedit
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2398
Posted: 01:24am 16 Jul 2020
Copy link to clipboard 
Print this post

try disconnecting the 4k7 pullup and test again. also try with a much higher value of pullup - say 100k.

i just read that some of the DS18B20 'clones' may have the pullup implemented internally.
https://forum.arduino.cc/index.php?topic=544145.msg3711300#msg3711300


cheers,
rob   :-)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 02:34am 16 Jul 2020
Copy link to clipboard 
Print this post

  robert.rozee said  try disconnecting the 4k7 pullup and test again. also try with a much higher value of pullup - say 100k.

i just read that some of the DS18B20 'clones' may have the pullup implemented internally.

cheers,
rob   :-)

That's why I did the measurement of the external pullup with the device still connected.
A test with the device disconnected should give the same ~4.7k result.

Jim
VK7JH
MMedit
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 03:31am 16 Jul 2020
Copy link to clipboard 
Print this post

We are ready to chart the analogue values on the data line.

 ' DS18B20 connected to PIN 42 in external power mode and link from PIN 42 to PIN 7
 ' TassyJim July 2020
 DIM FLOAT presence(2048)
 '
 ADC OPEN 200000, 7,12,13,allDone
 ADC TRIGGER 1, -2 ' start reading when level drops below 2
 ADC START presence()
 PIN(42) = 1
 SETPIN 42, DOUT, OC
 PULSE 42, 0.481 ' change this value for testing
 SETPIN 42, DIN
 DO
 LOOP UNTIL INKEY$<>""
END
 
SUB alldone
 LOCAL INTEGER n, y1,y2
 ADC CLOSE
 CLS
 FOR n = 0 TO 3
   LINE 0,400-n*100,799,400-n*100,1, RGB(RED)
   TEXT 0,380-n*100,STR$(n,2,1)
 NEXT n
 FOR n = 0 TO 750 STEP 50
   LINE n,390,n,410,1, RGB(RED)
   TEXT n,410,STR$(n*5,3,0)
   TEXT 400,440,"Time in uS",c
 NEXT n
 y1 = 400 - presence(0)*100
 FOR n = 1 TO 800
   y2 = 400 - presence(n)*100
   LINE n-1, y1, n, y2,1,RGB(WHITE)
   y1 = y2
 NEXT n
 SAVE IMAGE "capture_"+MID$(DATE$,4,2)+MID$(DATE$,1,2)+MID$(TIME$,1,2)+MID$(TIME$,4,2)+".bmp"
 TEXT 100,500,"Press any key to continue"
END SUB


This program samples every 5uS starting form the first negative going transition

Sample from a 'good' DS18B20
It is encased and with a 1M lead.


As a comparison, this is the same run captured on my CRO



Jim
VK7JH
MMedit
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 03:50am 16 Jul 2020
Copy link to clipboard 
Print this post

By changing the trigger to a normal TEMPR(42) read
 ADC OPEN 200000, 7,12,13,allDone
 ADC TRIGGER 1, -2 ' start reading when level drops below 2
 ADC START presence()
'  PIN(42) = 1
'  SETPIN 42, DOUT, OC
'  PULSE 42, 0.481 ' change this value for testing
'  SETPIN 42, DIN
x = tempr(42)
 DO
 LOOP UNTIL INKEY$<>""


We get



Not enough resolution to decode easily but enough to show that it works.

I really do like the background ADC capture.

Jim
VK7JH
MMedit
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10064
Posted: 07:22am 16 Jul 2020
Copy link to clipboard 
Print this post

  Quote  The next thing I will try is to see if we can measure the level that your devices are bringing the data line down to.
I suspect that they have a high impedance and are not pulling the line low enough for the CMM2 to recognise a LOW


Jim may well be correct in which case there is nothing to be done except try a higher value pullup - say 6K8 as a start. The low threshold for a STM32H743 is 0.4 * VDD - 0.1 so in our case 1.22V

You could try the attached. I've set the timings to be exactly the same as the Arduino library


CMM2V1.5.zip

PS: Jim this is wonderful work you are doing and really shows off the CMM2 in new and interesting ways
Edited 2020-07-16 17:23 by matherp
 
Amnesie
Guru

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

So I have done some testing:

first I ran Jims tests, here are my results:




Then "By changing the trigger to a normal TEMPR(42) read"




I've done all readings multiple times, the result is always stable and the same.

After this I tested all kinds of pullups and even without pullup. Things got worse here.
Without a pullup I only get error readings (1000) and with values up to 30k I get false readings like 16.120 (instead of 22°C) - so the pullup @ 4,7k seems to be right.

After this I tested matherp's new firmware. But nothing has changed. The missreadings / errors in relation to the correct readings seems to be the same as before. So there are
some correct readings, but a lot of errors, too.


Just a reminder: the above readings from Jims test are done BEFORE FLASHING the firmware!


It is really amazing how helpful and focused - all of you - are. I've never ever seen something similar on the internet. Wow!

I think, I have to wait for the original ds18b20 sensor to arrive here.

Greetings
Daniel
Edited 2020-07-16 20:33 by Amnesie
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2398
Posted: 10:46am 16 Jul 2020
Copy link to clipboard 
Print this post

just a thought - are you able to hook the DS18B20 up to your arduino and get it outputting valid temperature readings, then use jim's (excellent) code to monitor JUST the data stream to see what it looks like when the sensor is working correctly?


cheers,
rob   :-)
 
     Page 3 of 7    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025