DS18B20 Temperature Component Macro

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

DS18B20 Temperature Component Macro

Post by TedO »

Good day,

I am inquiring whether there is a DS18B20 component macro download available for Flowcode V6? I have scratched around the forums but maybe I missed it?
The LM75B macro which is supplied as standard with FC 6 is an SMD chip in real life which is difficult to mount and be able to use when learning to write programs utilizing temperature sensors, the DS18B20 is much easier to use with a breadboard.

Thank you.
Ted

User avatar
cubitus54
Flowcode v5 User
Posts: 110
Joined: Wed Jun 19, 2013 7:18 am
Has thanked: 7 times
Been thanked: 32 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by cubitus54 »

Hello,

Use "One Wire" in "Comms"
Flowcode V6.1.2.0(11 05 2015)

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Thank you

Have opened up the help file in "One Wire" and seen that it has the DS18B20 sensor included, thanks for the help.

Rgds
Ted :oops:

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hello,

Have tried the "One Wire" example which I downloaded from Matrix website, however, the component used is a DS1820 and not a DS18B20....are there no examples for the latter available?

Thanks
Ted

User avatar
cubitus54
Flowcode v5 User
Posts: 110
Joined: Wed Jun 19, 2013 7:18 am
Has thanked: 7 times
Been thanked: 32 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by cubitus54 »

Hellos,

It's the same thing...

Do not forget to put the pull up resistor
Image3.gif
Image3.gif (7.29 KiB) Viewed 17342 times
Flowcode V6.1.2.0(11 05 2015)

keejay
Flowcode v5 User
Posts: 115
Joined: Tue Jul 23, 2013 10:02 am
Been thanked: 15 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by keejay »

The 18B20 temp sensor does not work with FC6. Works fine with FC5, but not FC6. There is a timing problem with the macro. I have asked the guys at MM to have a look at it numerous times, but alas...still nothing.

User avatar
cubitus54
Flowcode v5 User
Posts: 110
Joined: Wed Jun 19, 2013 7:18 am
Has thanked: 7 times
Been thanked: 32 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by cubitus54 »

Which chip you work?
It seems to me that it takes a minimum frequency of 8MHz ...
Flowcode V6.1.2.0(11 05 2015)

keejay
Flowcode v5 User
Posts: 115
Joined: Tue Jul 23, 2013 10:02 am
Been thanked: 15 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by keejay »

I use PIC18F series clocked at 20MHz. The exact same hardware reads the temp 100% with FC5, but not with FC6.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by Benj »

Hello,

Is it possible to send us a known working program in v5. I will compile to hardware here and then see if I can compare the waveforms generated by v5 and v6 to see if we can sort this out.

V6 has a more universal but slightly less efficient way of writing to the I/O which is probably effecting the strict 1 wire timings on slower devices. I may need to add a bit of a fiddle factor to the delays on certain families if the clock speed is under a specific threshold.

I may have a program stored somewhere so I'll have a root.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by Benj »

Hello,

I have just tried my known working v5 program in v6 using a 16F1937 running at 19.6608Mhz and it's working fine for me.

If you have a simple file that shows the problem then I will look into that.

Here is my file,
1. Single OneWire device_v6.fcfx
(9.15 KiB) Downloaded 623 times

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hi All,

I have been playing around with the LM35DZ temperature sensor which is much more user friendly to novices like me. Using the potentiometer to simulate the input for the sensor, I found that one needs to convert the input voltage to try and accurately determine the temperature which I did, but the temperature starts going horribly wrong when the temp is compared to a reference thermometer when the temp starts to drop at night.
With the LM35DZ giving an output of 10mV for each degree of Centigrade, reading the device with a multimeter gives one the temperature in millivolts, however, I am struggling to display the temp consistently over the whole spectrum of the devices range, ie if I deduct the amount that it is over reading according to the reference, it will only be accurate over about a 5 degree variance up and down, there after it becomes inaccurate.
Does anybody have the answer to read the input of the device over the whole range accurately, I am using a PIC16F690 chip at 20Mhz displaying on an LCD?

Thanks Benj for the sample DS18B20 program...will run it and see how it goes.

Thank you
Ted

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by medelec35 »

Hi Ted,
What I do is ReadAsInt then use:
Temperature = ReadIntValue * 49 * 10

The temperature will be temperature x 10

E.g if result is 214 then Temperature is 21.4 deg.

Personally I use MCP9701-E/TO becuse they are cheap, and very easy to use since the resolution of this device is 19.53mV/C
Which is the resolution of a bit = 5/256 = 0.01953
This means the calculation is more simple and accurate.
The temperature change measured is also more accurate and less rounding up/down to do

If you change to MCP9701-E/TO I can post the formula I currently use.

Martin
Martin

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hi Martin

Thanks for the valuable advice on the Lm35DZ sensor, I really appreciate your help. I am definitely going to acquire some of the MCP sensors suggested, got tired of struggling with the One Wire DS18B20 device that frustrated me to no end, hence me trying to get the LM35DZ to work instead. Will give the DS18B20 another go once I am a little more experienced in using temp sensors.

Please post the temp program that you spoke about, it helps tremendously to follow an experienced programmers flowchart.

Regards
Ted :D

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hi Martin

I checked my flowchart with the potentiometer macro that simulates the temp sensor but I do not see the commands that you spoke about, namely the ReadAsInt and ReadIntValue, all I have is GetInt which I am currently using?? Are you using something different or is this a piece of C code that one enters?
Please forgive the ignorance, but we all have to go through this learning curve.

Rgds
Ted

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by medelec35 »

Hi Ted,
Sorry, I had V5 on my mind as that uses ReadAsInt.
You are correct in saying GetInt as that is the V6 equivalent..
There is no C code

Martin
Martin

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hi Martin

I found this LM35 thermometer flowchart on the internet, it works perfectly well on the simulator, but alas, when it comes time to compile the program it gives me an "error 1" code.

Please can you check it out for me, as I have confidence in your ability having helped me very well with the fuel gauge project.

Thank you
Regards
Ted
Attachments
Themometer LM35 V1.fcfx
(8.27 KiB) Downloaded 313 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by medelec35 »

Hi Ted,
Thanks.
Reason Flowchart does not compile is because there are Two LCD's!
One on the Dashboard panel which is OK because it's pins are connected to C port.
The other is on the System panel which is causing compile to fail as its pins are connected to B port which does not exist on the selected target device 16F1824
If you select that LCD then right click select Cut you should be able to recompile.

Martin
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by medelec35 »

As MCP9701 you can try attached flowchart.

Martin
Attachments
MCP9701 TEST.fcfx
(9.82 KiB) Downloaded 309 times
Martin

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Thank you very much, I did not notice the second LCD to be honest. Will try the MCP9701 sensor flowchart as soon as I have received the sensors that I have ordered, much appreciated, you are a star....thank you.

Rgds
Ted :D

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hi Martin

Have managed to compile the Thermometer flowchart only to find that in reality it does not work as it is reading 102.3 degrees C while the ambient temp was 16 degrees C, so what a waste of time.
Will be receiving my order for the MCP9701 sensors tomorrow, am keen to get to know them better.

Thanks once again

Rgds
Ted

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by medelec35 »

Hi Ted,
TedO wrote: it does not work as it is reading 102.3 degrees C while the ambient temp was 16 degrees C
I can look at the flowchart and sort the issue out for you.
I can also let yo know how to check hardware side if you like?

Martin
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by medelec35 »

Spotted the issue in your flowchart.
There is a vital calculation missing:

Code: Select all

Celsius = Celsius * 49 / 10
So you should have:

Code: Select all

Celsius = Celsius * 49 / 10
CelsiusString = ToString$ (Celsius)
Length = Length$ (CelsiusString)
TempString = Left$ (CelsiusString,Length - 1)
Floats are not really recommended with 16F pics,
But if you want a more accurate thermometer then floats can be used, but will take a fair bit of storage depending on the target device.

Martin
Martin

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hi Martin

Have just realized my error in trying to use a 16F690 chip with the LM35 sensor, have just read your post from 2014 in which you speak about the internal voltage reference which the 16F1824 chip has, so once again......a valuable lesson.

Thanks
Ted

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by medelec35 »

Hi Ted,
Understood.
Flowchart you posted will work on 16F690 so long as you add the missing calculation line.
If the calculation line is removed then its for the 16F18xx range.
So basically the calculation line I added above will convert flowchart from Very accurate temperature sensor for 16F18xx to
not so accurate for all other target devices including 16F690

So if you add the calculation, change target device, change configuration settings ofr 16F690,
Display should show temperature with a small error.

Martin
Martin

TedO
Posts: 79
Joined: Sat Mar 14, 2015 7:52 am
Has thanked: 46 times
Been thanked: 26 times
Contact:

Re: DS18B20 Temperature Component Macro

Post by TedO »

Hi Martin

I added the calculation formula as you posted, when I run the program on a breadboard the LM35 outputs 102.3 and will not budge up or down.
I am struggling a bit to convert the ADC input from the LM35 to celsius degrees. When I take a reading direct from the sensor, it writes 43 on the LCD when the reference thermometer that I have hanging in my office shows 20 degrees C. I subtracted the amount that it is over reading to give me 20 degrees, however, this I found is not correct as the degree of accuracy goes completely out when the temp changes dramatically away from 20 degrees.
I am trying to help my friend (also a Martin) with a simple temp controller for his homemade bio diesel plant. He uses 2 temps for the process namely 60 and 110 deg C so I made this flowchart to simplify his having to babysit the heating cycle to prevent the oil from being overheated. My problem being that the temp is not correct.

Please can you check it for me and come up with some solution? By the way, your MPC9701 thermometer works very well, tried to modify it to suit the above application but came undone, will get there one day I suppose.
The program uses 2 switches, sw= 60 deg and sw2= 110 deg, I have added a reset button to break the loop as the program will shut down the heater at 60 deg and switch it back on when the temp goes down to 55 deg the same on the higher temp, this cycle will continue until the reset button is pressed. The LED is the relay output to the contactor.

Thanks
Ted
Attachments
Oil Temp Controller.fcfx
(18.89 KiB) Downloaded 319 times

Post Reply