Page 1 of 1
DS18S20 Temp. Reading (HELP)
Posted: Tue May 03, 2011 11:33 pm
by Jordy101091
Hi, everyone
I have bought 2 DS18S20-PAR digital temperature sensors, to implement into my aquarium controller. Ad first I had an analogue sensor KTY26-1 witch you have to make a lookup table to determine what the temperature is. Now I understand How I need to do this, Thanks a lot for your help people I really appreciate it.
So far so good,
Now I want to go a step further. because I had some trouble with the accuracy of my analogue sensor I wanted something more reliable (and easier) to work with. So I decided to purchase two DS18S20-PAR temp. sensors. I new that these type of sensor where already calibrated by default so I dont have to worry about that. And also I have read that these type of sensors are communicating with what is called a ONE-WIRE bus. I was really excited because I never heard from it before and really want to learn how it works. I also noticed that flowcode has macros for the one wire bus and specifically 3 macros for the DS1820. NICE
After reading the datasheet 3 times and looking into the One-Wire help file I have made this program to read the raw temperature data from the sensor. White my weather station left of my, I can use his temperature as my base point to confirm my DS18S20 is working correct. Because if my room temperature is rounded 25"C then my DS18S20 should probably give 400. After a calculation |Temperature = (400*10)/16| Temperature is = 250.
But to start understanding I only want to read the raw temperature value.
So as I have seed before, I have made A program that can detect how many device there are connected on the bus so that greet

. After that I used these macro's:
# DS1820_Start_Conversion
<<<<1000ms delay
# DS1820_Read_Scratchpad <<<<< Stored in variable: (
one_wire_scratchpad)
# DS1820_Get_Temp <<<<< Stored in variable: (
ds18s20_temp)
So uploaded the program to my EB006 programmer board
CHIP = PIC16F887a
CLOCK = 19.6608 MHz
LCD = PORTB
One-Wire = PORTA.0
DS18S20 is in parrasite mode and I used a 4.7K pullup from DQ and PORTA.0 to 5V+
After I have loaded the program, YES the program doesn't work. Here is where the learning part begins. My program detects if there is a device connected if not the program keeps checking. If a device is found It will continue and preform a convert macro every 1000ms.
The result is 170. no matter what I do, I can stair at it pull it out and back in reset the uC. It keeps showing me 170.
Can you help me why this is and help me understand and learn from it. So I can say; Ah haa now I get it, now I know how it works.
Thanks Guys
Regards Jordy Kleian

Re: DS18S20 Temp. Reading (HELP)
Posted: Wed May 04, 2011 10:55 am
by Jordy101091
Hi, all I have made some changes to the program just to see if there is time-out and if it reads the scratch pad correctly.
On the display you will see:
StrConv = DS1820_Start_Conversion return value <<<< this must be a 0 otherwise the DS18S20 has a time-out
RdScrat = DS18S20_Read_Scratchpad return value <<<< This must be a 0 otherwise the DS1820 has not read th scratch pad
ds18s20_temp = the raw temperature value <<<< keeps saying 170
Please Correct me if im wrong
One other thing:
If I read the help file from the One-Wire Bus:
DS1820_Read_Scratchpad()
Specific to the DS1820 and DS18B20 devices. This function must only be called if there is only one device on the bus as it skips the ROM address. If there is more then one device on the bus then the ScanBus and ReadDevice functions must be used. Loads the remote scratchpad from the device into the local buffer. See the GetPadByte function.
DS1820_Get_Temp()
Specific to the DS1820 and DS18B20 devices. This function returns the integer value representing the temperature which is stored in the local buffer. The value returned represents the temperature in levels of 0.0625 degrees Celcius. Therefore if you get a value of 400 then the temperature is equivalent to 25 degrees C. An easy way to convert this into a readable value is to either devide by 16 and have an integer number or use the 32 bit floating point plugin and devide by 16 to get the temperature to within 0.0625 of a degree.
So by reading this I think that I must use the
Getpadbyte Function
oo_GetPadByte(byte index)
Returns a byte from the last read scratchpad at position index. The index byte can go from 0 - 8 to reference the 9 individual scratchpad bytes.
But to me I doesn't make sense, Hope some one can explain in detail what im missing here.
Re: DS18S20 Temp. Reading (HELP)
Posted: Wed May 04, 2011 6:44 pm
by Jordy101091
Hi, again
I have done something but I dont know what to do with it.
I have add the getpadbyte function into my program to see what the values are of the different addresses of the scratchpad.
So I have pointed the index byte to:
0 = LSB
1 = MSB
6 = Count_Remain
7 = Count_P_"C
8 = CRC
What I found was this:
0 = 170
1 = 0
6 = 12
7 = 16
8 = 135
(all are in byte values)
I don't know exactly what this means ore what I can do with it.
Hope you guys can help me further out and together make this work.
Regards Jordy
Re: DS18S20 Temp. Reading (HELP)
Posted: Wed May 04, 2011 11:24 pm
by Jordy101091
Hi, again
I have some important news
I build it
I test it
I hath a problem
And finally
I fixed it.
Yes, Yes
It works thanks to the datasheet that I have read over and over again (10x)
The datasheet says that if the DS1820 puts out a value of 85C its a default value on power-up. And it also tels you that the conversion is not done in time (750ms in parasite mode)
So what I did is connect the damn thing to use an external power supply, pressed the reset button and Hurray the damn thing works.
It gives a nice temperature of 24,0 "C.
Anyway thanks
Regards Jordy Kleian

Re: DS18S20 Temp. Reading (HELP)
Posted: Thu May 05, 2011 9:56 am
by Benj
Hello Jordy,
That's great news, I was worried I would have to try and find some of the devices to do some testing. Thanks for letting us know how you solved the problem. To be honest I always used a power supply when I was working with the devices too rather then using the parasitic power as this did seem to have issues. There is also the fact that there are multiple variations of the same device out there which does not help as they are all marked the same but do not work the same.
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu May 05, 2011 11:56 am
by Jordy101091
Hé Ben,
Maybe you can explain me how I can have a better resolution.
I have now a resolusion of 0.5 but it would be nice if I can get this to 0.1
I have read about that on many forums and also in the datasheet, but I dont know how I can do that.
I know that I need information from the scratchpad I think only these byte would do the trick:
0,1,6, and 7
But if I use the read_scratchpad function in flowcode then it reads the whole scratchpad, but i think that I only need these four bytes.
I also think that I need to use Gedpadbyte function but I dont know exactly.
Hope you can help me with this, would be nice
Regards Jordy
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu May 05, 2011 2:58 pm
by Benj
Hello Jordy,
I would recommend using the custom code feature to edit the code for the function DS1820_get_temp.
This is basically reading the values out the scratchpad and then returning the values as a temperature.
Currently scratchpad entries 0 and 1 are being used but 6 and 7 are also available at this point.
Do you know how you have to combine the scratchpad values to get a better resolution?
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu May 05, 2011 3:51 pm
by Jordy101091
Hi ben thanks for your reply,
How do I use the Costume Code to edit the code for the function DS1820_get_temp
Would you mind to explain to my how that can be done.
I would really appreciate it.
And no i dont know how to combine the scratch pad values to get a better resolution.
Hope you can explain that to.
Thanks
Regards Jordy
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu May 05, 2011 5:26 pm
by Benj
Hello,
Select the one wire component on the panel, ensure you have the properties pane visible and you will see there are 4 buttons available.
Ext Properties
Connections
Custom Code
Help
Alternatively you can right click the component on the panel and select Custom Code.
Do you have a link to the datasheet for your specific devices you could post onto the forums?
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu May 05, 2011 7:31 pm
by Jordy101091
Here is the link to the datasheet :
http://datasheets.maxim-ic.com/en/ds/DS18S20.pdf
Hope you can help me.
Thanks,
Regards Jordy
Re: DS18S20 Temp. Reading (HELP)
Posted: Fri May 06, 2011 10:21 am
by Benj
Hello Jordy,
Please can you send your current working program and I will make a few changes to give you the extended resolution temperature.
Re: DS18S20 Temp. Reading (HELP)
Posted: Fri May 06, 2011 5:59 pm
by Jordy101091
Hi ben sorry for the late response,
Here is my program
Thanks
Regards Jordy
Re: DS18S20 Temp. Reading (HELP)
Posted: Mon May 09, 2011 10:10 am
by Benj
Hello Jordy,
Here is the program with what I think should work correctly on the hardware.
Re: DS18S20 Temp. Reading (HELP)
Posted: Mon May 09, 2011 4:06 pm
by Jordy101091
Thanks, Ben
I will try this to night, hope it works.
I will let you know.
Regards Jordy
Re: DS18S20 Temp. Reading (HELP)
Posted: Mon May 09, 2011 4:59 pm
by Benj
BTW if it does work correctly and you need to change the number of decimal points appearing on the float string then please see this topic.
http://www.matrixmultimedia.com/mmforum ... 373#p24371
Re: DS18S20 Temp. Reading (HELP)
Posted: Mon May 09, 2011 6:58 pm
by Jordy101091
First Off all,
Thanks Ben for your'e support.
Your solution is very nice, I like it a lot.
What I dont like about your solution is that it uses floating point calculations, it uses much more flash memory then if you wont use it.
but over all its very well done.
But still floating point
I thought by my self, what if I just give it a try.
So what I did was looking into the datasheet for the formula on how to calculate for a better resolution.
I found it and goes like this:
Temperature = Temp_read -0.25 + (Count_p_C - Count_remain) / Count_p_C
But as you can see it uses a decimal value (0.25) and therefore I needed to use floating point, but I dont want to. So Why dont multiply Temp_read by a 100 and do the seem for (Count_p_C - Count_remain) and change 0.25 to just 25.
OK well that was send so hard to do, well then I read in the data sheet that you need to truncate 0.5 resolution from the temperature. But how i'm going to do that. I knew that I needed to some how shift with bytes. but where to.
So I checked the datasheet again, and it says that the 0.5 resolution is in the LSB. So I needed to shift >> 1
After I have done that It was time to calculate the High and Low temp values.
The High temp value you get from this part of the formula: Temp_read*100 - 25
The Low temp Value you get from this part of the formula: ((Count_p_C - Count_remain)*100) / Count_p_C
Then you just convert High and Low to a String:
for example:
TemperatureHigh = ToString$(High)
TemperatureLow = ToString$(Low)
then you just print these on you LCD like this:
TemperatureHigh,TemperatureLow *C
Ben, Thanks for giving me that little push in the wright direction.
Regards Jordy
Re: DS18S20 Temp. Reading (HELP)
Posted: Mon Aug 01, 2011 3:02 am
by billduck
I note that the help file, that no more than 8 OneWire devices can be used. Is addressing more than 8 devices a matter of writing custom code, or can another controller pin be used for the second 8 devices? And the third 8 devices?
Thanks in advance.
Re: DS18S20 Temp. Reading (HELP)
Posted: Mon Aug 01, 2011 7:41 am
by JohnCrow
Hi Bill
I could be wrong here, but from my experiments with the DS1820 and the data sheet, I think 8 devices / bus is the limit of the 1 wire standard. Not sure if you can have more than one bus connected to different bits on a port, I not tried more than a couple of devices at a time.
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu Aug 11, 2011 4:11 am
by billduck
I was able to read and report the temperature with multiple DS18B20's (4 each), just by following the directions in the help menu. (Scanbus - Get device count - Start conversion - Read device - Get Temp). My question is about the order in which the temps are reported. If I warm the first one in the One Wire string, it is reported as the third device. I always wondered how data from multiple devices is separated out, especially if it is on one bus. Can anyone describe the process? And, of course, what is the solution? I will try to sort the devices, For example, move device #3 to be the first in the string.
Thanks in advance.
I followed thru, and sorted the devices in the string, to where the temp in the first device in the string is reported as device #1. I also discovered that hot swapping devices may be a bad thing, as one of the devices is reporting the temp as -1 (in it's raw form. 0xFFFFFFFF) . It may be trying to tell me something.
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu Aug 11, 2011 7:03 am
by jgu1
Hi Billuck!
About: "just by following the directions in the help menu".
I have searched and searched through the helppanel but can not find anything about One Wire component. Would you be kind to give me a clue. I use FC Ver.4.5
Thanks in advance.
jgu1.
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu Aug 11, 2011 7:48 am
by JohnCrow
Hi
If you put the 1wire comp on the form, open the properties and the click the help file inside the component you will get the full information (Same for all the components)
Re: DS18S20 Temp. Reading (HELP)
Posted: Thu Aug 11, 2011 1:48 pm
by jgu1
Hi John!
Ok, it works, thank you
Regard
jgu1

Re: DS18S20 Temp. Reading (HELP)
Posted: Mon Aug 15, 2011 3:44 am
by billduck
I was able to read the temperature of 4 DS18B20's, detailed in an earlier post. I am delving deeper, as I would like to use a DS2438 - Voltage / Temp monitor, in a battery pack. So, I am trying to read the family code of the DS18B20. Then I would like to read the unique 64 bit serial code. I have uploaded the trial. In it, I read the scratchpad, then get bad byte, and print same. The printed sequence is 80,5,75,70,127,255,12,16,28. If I switch out the DS18B20 to another, I get the same sequence. The last # is correct for the family code. If the previous 8 #'s is the unique 64 bit serial code, I would expect it to change, when I switch devices, but it doesn't. Any suggestions? I am using a AVR AT90USB162.
I might mention that I found that it is important which port pin to use, as it did not work on the first random choice. I read in this tutorial <
http://www.maxim-ic.com/products/1-wire ... /index.cfm> that the pin needs to be a "open drain, bi-directional port pin", in slide 3 of 17. Maybe that is the trick.
Thanks in advance.