Page 1 of 1
ds1820 temp sensor
Posted: Wed Dec 12, 2012 1:58 pm
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
Re: ds1820 temp sensor
Posted: Wed Dec 12, 2012 2:29 pm
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.
Re: ds1820 temp sensor
Posted: Wed Dec 12, 2012 3:45 pm
by siliconchip
hi enamul in your flowcode i have noticed you are using the 877 im after using the 16f88
Re: ds1820 temp sensor
Posted: Wed Dec 12, 2012 5:43 pm
by Enamul
Here the code is in PIC16f88..Data in RA0 and remember to pull-up by 4.7K
Re: ds1820 temp sensor
Posted: Thu Dec 13, 2012 1:03 pm
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
Re: ds1820 temp sensor
Posted: Thu Dec 13, 2012 1:14 pm
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.
Re: ds1820 temp sensor
Posted: Thu Dec 13, 2012 3:06 pm
by siliconchip
ive compiled and run with the crc ticked and unticked but it makes no difference wondering if my ds1820 is defective
Re: ds1820 temp sensor
Posted: Thu Dec 13, 2012 3:40 pm
by Enamul
May be..I have tested this code in my sensor 2 days back..it worked fine.
Re: ds1820 temp sensor
Posted: Thu Dec 13, 2012 3:44 pm
by siliconchip
just a thought but would oscillator settings affect this i am using the internal oscillator at 8Mhz
Re: ds1820 temp sensor
Posted: Thu Dec 13, 2012 4:04 pm
by Enamul
Yes, of course. Can you try with external 20MHz please?
Re: ds1820 temp sensor
Posted: Thu Dec 13, 2012 8:29 pm
by siliconchip
will let you know
Re: ds1820 temp sensor
Posted: Sat Dec 15, 2012 3:59 pm
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
Re: ds1820 temp sensor
Posted: Sat Dec 15, 2012 4:47 pm
by Enamul
Can you try this please as your system improves?
Re: ds1820 temp sensor
Posted: Sat Dec 15, 2012 6:18 pm
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
Re: ds1820 temp sensor
Posted: Sat Dec 15, 2012 7:17 pm
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
Re: ds1820 temp sensor
Posted: Sun Dec 16, 2012 3:01 pm
by siliconchip
thanks for the help its appreciated