View previous topic :: View next topic |
Author |
Message |
adrix
Joined: 04 May 2012 Posts: 24
|
|
Posted: Sun May 13, 2012 4:44 am |
|
|
How can I make that the output would be 0,1 deg accuracy? I'm using DS18S20, so the division by 16 doesn't work. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun May 13, 2012 5:26 am |
|
|
Of course it doesn't work.
I don't even use these parts, but I can read the data sheet.
Best ACCURACY is 0.5C.
DS18S20 is 9 bit RESOLUTION part.
LSB represents 0.5C, so that's the best it can do.
If you want better RESOLUTION, maybe use the DS18B20 which goes to 12 bits.
Each LSB is then 0.0625C, you get nearest 0.1C by rounding off.
But ACCURACY is still only 0.5C at best.
I'm assuming you understand the difference between ACCURACY and RESOLUTION.
Mike |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Tue Aug 21, 2012 1:06 am |
|
|
I have a problem. I tried your codes but the 18B20 returned very high temperatures - 85 degrees for example. The temperature in the room is not more the 25 degrees.
Where is the problem??? |
|
|
shaharyar
Joined: 09 Jan 2013 Posts: 1 Location: Pakistan
|
|
Posted: Wed Jan 09, 2013 1:23 pm |
|
|
Thanks jds-pic and scanan
the code worked like a charm with a single error
cheers |
|
|
yuripace
Joined: 26 Nov 2013 Posts: 21
|
|
Posted: Tue Dec 31, 2013 4:15 am |
|
|
i have ds18b20.
all is working good at 5v.
at 3.23v temp is stucked to 127.93. I'm using 4,7k resistor connected to datapin on A0 pin of a pic16f876.
any suggestion? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Dec 31, 2013 9:02 am |
|
|
Are you using parasite power mode?
Mike |
|
|
yuripace
Joined: 26 Nov 2013 Posts: 21
|
|
Posted: Sat Jan 04, 2014 2:53 am |
|
|
on ds18b20 Pin1 connected to gnd, pin3 to 3.5v, DQ connected to A0 pin of pic16f876 with a resistor connected to vcc |
|
|
yuripace
Joined: 26 Nov 2013 Posts: 21
|
|
Posted: Sat Jan 04, 2014 4:03 am |
|
|
i'm trying different configuration. i'm using scanan code, pic16f876 and external 16mhz clock. I dont know why, now also 5v dont work, stucked at 85°.
1 - parasite power mode: pin 1 and 3 connected to gnd, pin 2 connected to A0 with a pullup resistor: result, 85°
2 - normal mode, pin 1 gnd, pin 2 dataline to A0 pin, pin3 VCC, no resistor result: -0,06
whats wrong?
Code: | #include <16F876.h>
#use delay(clock = 16000000)
#fuses HS, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#include "flexlcd.c"
#include "1wire.c"
void ds18b20_init()
{
//for 10 bit resolution mod
onewire_write(0xCC);
onewire_write(0x4E);
onewire_write(125);
onewire_write(-55); //this should be done for proper working of DS18B20
onewire_write(127);
onewire_reset();
onewire_write(0xCC);
onewire_write(0x48);
delay_ms(15);
}
float ds1820_read()
{
int8 busy=0, temp1, temp2;
signed int16 temp3;
float result;
onewire_reset();
onewire_write(0xCC);
onewire_write(0x44);
while (busy == 0)
busy = onewire_read();
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE);
temp1 = onewire_read();
temp2 = onewire_read();
temp3 = make16(temp2, temp1);
//result = (float) temp3 / 2.0; //Calculation for DS18S20 with 0.5 deg C resolution
result = (float) temp3 / 16.0; //Calculation for DS18B20 with 0.1 deg C resolution
delay_ms(200);
return(result);
}
void main()
{
delay_ms(500);
float temperature;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
delay_ms(500);
ds18b20_init();
delay_ms(500);
lcd_init();
delay_ms(1000);
while (1)
{
output_high(PIN_B4);
lcd_gotoxy(1,1);
temperature = ds1820_read();
printf(lcd_putc,"\nTEMP: %f ", temperature);
output_low(PIN_B4);
delay_ms(1000);
}
} |
|
|
|
yuripace
Joined: 26 Nov 2013 Posts: 21
|
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Fri Aug 15, 2014 4:11 am |
|
|
The code below is based on "ds1820.c" made by hansolo.
I made some changes according to the datasheet to increase resolution (about 0.1 ° C): datasheet page 3.
I hope this can be useful for someone.
ds18s20.c
Code: |
float ds1820_read()
{
int8 c, SCRATCHPAD[8];
int8 busy=0;
signed int16 temp;
float result;
onewire_reset();
onewire_write(0xCC);
onewire_write(0x44);
while (busy == 0)
busy = onewire_read();
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE);
for(c=0;c<8;c++)
{
SCRATCHPAD[c] = onewire_read();
}
temp = make16(SCRATCHPAD[1], SCRATCHPAD[0]);
result = (float) (SCRATCHPAD[7] - SCRATCHPAD[6])/(SCRATCHPAD[7]);
result = (float) ((temp/2) - 0.25 + result);
delay_ms(200);
return(result);
}
|
|
|
|
|