CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with DS18B20

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
evelikov92



Joined: 10 Mar 2015
Posts: 23

View user's profile Send private message

Problem with DS18B20
PostPosted: Wed May 06, 2015 1:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 06, 2015 3:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 06, 2015 6:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 07, 2015 3:39 am     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Thu May 07, 2015 5:30 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group