ds1820 temp sensor

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

ds1820 temp sensor

Post by siliconchip »

hi all i am interested in making a basic program for a DS1820 temp sensor and also to gain some understanding of writing code for them, and have downloaded the one wire example from flowcode, the chip used is a pic16f877, i have altered the code so i can use a 16f88, i connected the data pin to RA0/AN0 but all i got on the lcd screen was no device found as per the program, the other 2 pins of the sensor were connected to +/- respectively, is it possible to do what i am intending ie substituting the chip for the 16f88 also does the data or d/q pin need to go to a ccp1 pin which i believe is capture/compare /pwm ? any input would be appreciated

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: ds1820 temp sensor

Post by Enamul »

Hi

Please try this code attached here.

Edit: Did you put 4.7K pull-up resistor from data pin to Vcc=+5V? If not please do that as without that sensor will not work.
Attachments
1. Single OneWire device.fcf
(12 KiB) Downloaded 376 times
Enamul
University of Nottingham
enamul4mm@gmail.com

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

hi enamul in your flowcode i have noticed you are using the 877 im after using the 16f88

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: ds1820 temp sensor

Post by Enamul »

Here the code is in PIC16f88..Data in RA0 and remember to pull-up by 4.7K
Attachments
1. Single OneWire device.fcf
(8 KiB) Downloaded 320 times
Enamul
University of Nottingham
enamul4mm@gmail.com

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

hi enamul i have tried your flowcode (compiled to hex) and i am using the 4.7K resistor but all i get on the lcd is crc error and if the sensor is not connected i get no device found,as per program canyou tell me what crc means please

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: ds1820 temp sensor

Post by Enamul »

If you are having CRC error..this code will work for your case..please check in the properties of the one wire component whether the CRC check is enabled or not..I have checked that if not please click that enable.
Attachments
1. Single OneWire device.fcf
(8 KiB) Downloaded 348 times
Enamul
University of Nottingham
enamul4mm@gmail.com

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

ive compiled and run with the crc ticked and unticked but it makes no difference wondering if my ds1820 is defective

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: ds1820 temp sensor

Post by Enamul »

May be..I have tested this code in my sensor 2 days back..it worked fine.
Enamul
University of Nottingham
enamul4mm@gmail.com

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

just a thought but would oscillator settings affect this i am using the internal oscillator at 8Mhz

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: ds1820 temp sensor

Post by Enamul »

Yes, of course. Can you try with external 20MHz please?
Enamul
University of Nottingham
enamul4mm@gmail.com

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

will let you know

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

ive tried with an external 20Mhz and i am now getting a reading but it shows 2.6 C if i touch the sensor i can get it to rise to around 3.8 C how can i get it to show room temp

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: ds1820 temp sensor

Post by Enamul »

Can you try this please as your system improves?
Attachments
1. Single OneWire device.fcf
(8 KiB) Downloaded 353 times
Enamul
University of Nottingham
enamul4mm@gmail.com

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

i am now getting readings of 20C rising to over 30C if sensor touched so now close to actual room temp if not actual, can you explain the following code so i can see what prompted you to change the calculation to the values shown please

Temp2 = (( Temp MOD 2 ) * 10)/2
Temp = Temp / 2

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: ds1820 temp sensor

Post by Enamul »

In the datasheet I have seen that the value we read has a relation with temperature is following:
Temp = Data/2
So like for 35 Data temp should be 17.5
I have divided the data by 2 to get integer part of temperature. Decimal point can get by remainder. (Data mod 2)=1 so multiply by 10 will produce 10 so divide by 2 will produce 5. Which results to 17.5
Enamul
University of Nottingham
enamul4mm@gmail.com

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: ds1820 temp sensor

Post by siliconchip »

thanks for the help its appreciated

Post Reply