View previous topic :: View next topic |
Author |
Message |
evelikov92
Joined: 10 Mar 2015 Posts: 23
|
Problem with DS18B20 |
Posted: Wed May 06, 2015 1:44 pm |
|
|
Hi everybody
I using pic18f6722, 20x4 lcd with this driver http://www.ccsinfo.com/forum/viewtopic.php?t=24661&highlight=flex and ds18b20 with this driver http://www.ccsinfo.com/forum/viewtopic.php?t=28425&highlight=ds18b20
I reading for problem with ds18b20 which is printing wrong temperature.
My problem is other. When I started program on device is working to ds1820_read() function and after that is stopped work.
I started the program in Proteus and is working ok.
I testing to write in LCD something before and after ds1820_read() function, and is display only text before function.
My question is what the problem probably is, the hardware or the software.
Probably is the temperature sensor is not working, and that is problem, or is the software, the fuses is wrong.
Here is my code simple code
This is the c file
Code: |
#include "main.h"
#use delay(clock=32000000)
#include <flex_lcd.c>
#include <one_wire.c>
#include <ds1820.c>
void main()
{
float temperature;
setup_oscillator(OSC_32MHZ);
lcd_init();
lcd_gotoxy(2, 2);
while(1)
{
printf(lcd_putc, "123");
temperature = ds1820_read();
printf(lcd_putc,"\fTemperature: %3.1f", temperature);
printf(lcd_putc, "456");
}
}
|
This is the h file
Code: |
#include <18F6722.h>
#device adc=12
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode enabled
#FUSES BBSIZ1K //1K words Boot Block size
#use delay(clock=32000000)
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 06, 2015 3:58 pm |
|
|
Quote: |
When I started program on device is working to ds1820_read() function
and after that is stopped work.
I testing to write in LCD something before and after ds1820_read() function, and is display only text before function.
|
This means the code is not returning from the ds1820_read() function.
The only thing that could cause this problem is the busy loop:
Code: |
while (busy == 0)
busy = onewire_read();
|
So it could be a hardware problem. Check the connections to the
ds18b20. Do you have a 4.7K pull-up resistor on the DQ line ?
This is required. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed May 06, 2015 6:20 pm |
|
|
Code: | 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 |
Make sure you select the proper option, which is the later(commented) option for your sensor.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
evelikov92
Joined: 10 Mar 2015 Posts: 23
|
|
Posted: Thu May 07, 2015 3:39 am |
|
|
PCM programmer wrote: | Quote: |
When I started program on device is working to ds1820_read() function
and after that is stopped work.
I testing to write in LCD something before and after ds1820_read() function, and is display only text before function.
|
This means the code is not returning from the ds1820_read() function.
The only thing that could cause this problem is the busy loop:
Code: |
while (busy == 0)
busy = onewire_read();
|
So it could be a hardware problem. Check the connections to the
ds18b20. Do you have a 4.7K pull-up resistor on the DQ line ?
This is required. |
I have resistor, but is only 0.7K, and connection is OK. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu May 07, 2015 5:30 am |
|
|
You are overloading the chip....
Though the low resistor means quick charging times for the capacitor, it also means more current than the chip is rated to pull down when signalling. Read the data sheet. For high pull up currents, they recommend using a FET, so it can be switched off when the chip is signalling. The suggested standard resistor is 4.7KR. The chip is not rated to pull down more than 4mA. |
|
|
|