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

wrong temperature reading
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 08, 2004 10:39 pm     Reply with quote

You're having so much trouble making this work.

Peter Anderson has some code for the DS1820 on his website.
He uses the CCS compiler:
http://www.phanderson.com/PIC/PICC/CCS_PCM/ds1820.html
Here's the main page:
http://www.phanderson.com/PIC/PICC/index.html

The only problem with his code is that he doesn't always
use CCS functions. For example, he writes his own
delay functions, in order to make his code be more
"universal". But by doing so, he makes it more
difficult for CCS users who run their PIC at a different
crystal frequency than he uses. So I suggest that
when you see his code like this
Code:
delay_10us(50);

then you should change it to use the CCS function, like this:
Code:
delay_us(500);  // 10 us x 50 = 500 us

Also, delete his delay_ms() function, since CCS has its own
delay_ms() function.

At the end of his DS1820 code, he has some LCD code which
you don't need. Just delete it.
Guest








PostPosted: Fri Jul 09, 2004 6:29 am     Reply with quote

Hi PCM:
thank you for you answer.
I did make 1820 working using Peter Anderson's program after make a little modification on parasite power situation, when I change the connection to non-parasite power situation, the reading is consistantly 85 degree c. could you tell me why. and where should I changed. I tried to remove _1w_strong_pull_up(sensor); in the program, but there is no change.
Code:

#if defined(__PCM__)
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#include <lcd420_1.c>
#include <math.h>

#byte PORTA  =0x05
#byte TRISA  =0x85

#define MAX_SENSORS 4

// 1-wire prototypes
void _1w_init(int sensor);
int _1w_in_byte(int sensor);
void _1w_out_byte(int d, int sensor);
void _1w_pin_hi(int sensor);
void _1w_pin_low(int sensor);
void _1w_strong_pull_up(int sensor);   // not used in this routine

void main(void)
{
   int sensor, n;
   float buff;
   sensor=5;

   while(1)
 //  for (sensor=0; sensor<MAX_SENSORS; sensor++)
   {
      _1w_init(sensor);

      _1w_out_byte(0xcc, sensor);  // skip ROM

      _1w_out_byte(0x44, sensor);  // perform temperature conversion
      _1w_strong_pull_up(sensor);

      _1w_init(sensor);
      _1w_out_byte(0xcc, sensor);  // skip ROM

      _1w_out_byte(0xbe, sensor);  // read the result

      buff=(float)(_1w_in_byte(sensor))/(2.0);
      lcd_init();
      printf(lcd_putc,"               ");
      printf(lcd_putc,"               ");
      lcd_gotoxy(1,1);
      printf(lcd_putc,"* Temperature *");
      lcd_gotoxy(1,2);
      printf(lcd_putc,"Tem=%4.2f%1cC",buff,0xdf);

      }
}

// The following are standard 1-Wire routines.
void _1w_init(int sensor)
{
   _1w_pin_hi(sensor);
   _1w_pin_low(sensor);
   delay_us(50);

   _1w_pin_hi(sensor);
   delay_us(50);
}

int _1w_in_byte(int sensor)
{
   int n, i_byte, temp, mask;
   mask = 0xff & (~(0x01<<sensor));
   for (n=0; n<8; n++)
   {
      PORTA=0x00;
      TRISA=mask;
      TRISA=0xff;
#asm
      CLRWDT
      NOP
      NOP
#endasm
      temp=PORTA;
      if (temp & ~mask)
      {
        i_byte=(i_byte>>1) | 0x80;   // least sig bit first
      }
      else
      {
        i_byte=i_byte >> 1;
      }
      delay_us(6);
   }
   return(i_byte);
}

void _1w_out_byte(int d, int sensor)
{
   int n, mask;
   mask = 0xff & (~(0x01<<sensor));
   for(n=0; n<8; n++)
   {
      if (d&0x01)
      {
         PORTA=0;
         TRISA=mask;      // momentary low
         TRISA=0xff;
         delay_us(6);
      }

      else
      {
          PORTA=0;
          TRISA=mask;
          delay_us(6);
          TRISA=0xff;
      }
      d=d>>1;
   }
}

void _1w_pin_hi(int sensor)
{
   TRISA = 0xff;
}

void _1w_pin_low(int sensor)
{
   PORTA = 0x00;
   TRISA = 0xff & (~(0x01 << sensor));
}

void _1w_strong_pull_up(int sensor)   // bring DQ to strong +5VDC
{
   PORTA = 0x01 << sensor;
   TRISA = 0xff & (~(0x01 << sensor));
   delay_ms(120);
   TRISA = 0xff;
}

Jerry I



Joined: 14 Sep 2003
Posts: 96
Location: Toronto, Ontario, Canada

View user's profile Send private message

PostPosted: Fri Jul 09, 2004 4:14 pm     Reply with quote

Do you have more than one sensor.

This happened to me also, and I found out that sensor was dead.

Try that first.

Jerry Very Happy



I did make 1820 working using Peter Anderson's program after make a little modification on parasite power situation, when I change the connection to non-parasite power situation, the reading is consistantly 85 degree c. could you tell me why. and where should I changed. I tried to remove _1w_strong_pull_up(sensor); in the program, but there is no change.
Guest








PostPosted: Mon Jul 12, 2004 12:27 pm     Reply with quote

Hi Jerrt:
No I just have one 1820 sensor. I believe my sensor is working.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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