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

need help with TC74 digital thermal sensor
Goto page 1, 2  Next
 
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: Mon Sep 11, 2006 10:24 am     Reply with quote

In all your previous programs you were testing against a positive
number such as 60, so I had that in mind when I made that program.
However, it's for the best, because you've shown up a bug in the
driver that I posted. All of the variables should have been 'signed int8'
instead of 'int8'. Also, in the printf() statement, "%d" should have been
used instead of "%u". So here's the revised test program with all
those corrections added.
Code:

#include <16F877.H>
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(master, sda=PIN_C4, scl=PIN_C3)

#define TC74_I2C_WRITE_ADDRESS   0x9A
#define TC74_I2C_READ_ADDRESS    0x9B
#define TC74_READ_TEMP_COMMAND   0x00
#define TC74_READ_CONFIG_COMMAND 0x01


signed int8 TC74_read_temperature(void);

//====================================
void main()
{
signed int8 temp;

while(1)
  {
   temp = TC74_read_temperature();
   printf("Temperature (C) = %d\n\r", temp);
   delay_ms(1000);
  }

}

//====================================

// Read the temperature (in degrees Centigrade)
// from the TC74.

signed int8 TC74_read_temperature(void)
{
signed int8 retval;

i2c_start();
i2c_write(TC74_I2C_WRITE_ADDRESS);
i2c_write(TC74_READ_TEMP_COMMAND); 

i2c_start();   // Re-start
i2c_write(TC74_I2C_READ_ADDRESS);
retval = i2c_read(0);
i2c_stop();

return(retval);
}

Note that all the int8 variables have been changed to signed int8.


I got out a can of freeze spray and tested the program.
Here is the output:
Quote:

Temperature (C) = 14
Temperature (C) = 15
Temperature (C) = 16
Temperature (C) = 15
Temperature (C) = 15
Temperature (C) = 8
Temperature (C) = -2
Temperature (C) = -5
Temperature (C) = -7
Temperature (C) = -21
Temperature (C) = -26
Temperature (C) = -28
Temperature (C) = -28
pdswar



Joined: 18 Jul 2006
Posts: 33
Location: Maryland, USA

View user's profile Send private message

PostPosted: Mon Sep 11, 2006 11:50 am     Reply with quote

I changed the data type from 'int8' to 'signed int8'

My buzzer still beeps at (temp==-1) but it doesnot beep at (temp>0) as it did with temp datatype as 'int8'.

void main()
{
signed int8 temp;
set_tris_c(0x00); //Buzzer output Port C

while(1)
{
temp = TC74_read_temperature();
if(temp==-1) //Buzzer beeps
{
buzzerbeep();
buzzerbeep();
buzzerbeep();
}

}

}

Am I doing something wrong with 'temp' data conversion/comparision?
I understand that PCM programmer is sending data through RS232 to display in LCD or computer monitor. All I am trying to to do is read the temperature, compare it to some standard value and trigger buzzer when it exceeds that standard value.

I compared my schematics with PIC DEMO2 PLUS schematics and I found no differences except my pull-up resistors in I2C bus are 10k instead of 4.7k and PIC microcontroller that I am using is 18F6722 instead of 18F458
And I am using TC74 SOT-23-5 instead of TO-220.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 11, 2006 12:08 pm     Reply with quote

The fahrenheit conversion code needs to be fixed. The 'fahr' variable
needs to be signed 16-bit because it holds an intermediate result that's
larger than 8 bits. I tested this code and it works. The buzzer doesn't
really beep. It just clicks. That's on a PicDem2-Plus board.
Code:
void main()
{
signed int8 temp;
signed int16 fahr;

while(1)
  {
   temp = TC74_read_temperature();
   printf("Temperature (C) = %d\n\r", temp);

   //Convert data into Fahrenheit.
   fahr = 9 * (signed int16)temp;
   fahr = fahr / 5;
   fahr = fahr + 32;
   printf("Temperature (F) = %ld\n\r", fahr);
   printf("\n\r");

   if(fahr > 40)
     {
      buzzerbeep();
     }

   delay_ms(1000);
  }

}
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Mon Sep 11, 2006 1:11 pm     Reply with quote

pdswar wrote:
My buzzer still beeps at (temp==-1) but it doesnot beep at (temp>0) as it did with temp datatype as 'int8'.
Code:

void main()
{
signed int8 temp;
set_tris_c(0x00); //Buzzer output Port C

while(1)
  {
   temp = TC74_read_temperature();
   if(temp==-1)   //Buzzer beeps   WHERE ARE YOU CHECKING FOR temp > 0???
      {
         buzzerbeep();
         buzzerbeep();
         buzzerbeep();
        }
 
  }

}



I don't see where you are checking for temp > 0??? Only if temp == -1.
pdswar



Joined: 18 Jul 2006
Posts: 33
Location: Maryland, USA

View user's profile Send private message

PostPosted: Mon Sep 11, 2006 2:00 pm     Reply with quote

jspencer,

Sorry about the confusion. What I meant was that if I replace
if(temp==-1) statement with if(temp>0) the buzzer still beeps.
That problem has been fixed with PCM Programmer's code. i.e. by using "signed int8" instead of "int8"

I am sure PCM Programmer's code is right. I am checking my schematics again. Now, I think it could be a hardware problem. In my PCB, I was missing SDA signal. I also didnot have pull-up resistors placed for my I2C bus in my original PCB. I am connecting SDA signal with external wire and pull-up resistors externally which could be a source of problem. I had SCL signal routed inside the board. Now I am connecting pull-up resistors to SCL signal and again connecting to TC74. Now there are two paths for SCL signal to reach TC 74.

Thank you all for your help.
pdswar



Joined: 18 Jul 2006
Posts: 33
Location: Maryland, USA

View user's profile Send private message

PostPosted: Mon Sep 18, 2006 7:35 am     Reply with quote

Not reading the datasheet for TC74 was the source of my errors. I am using TC74A0-5.0VCT but I was copying codes written for TC74A5-5.0VCT

Everything worked when I replaced

i2c_start();
i2c_write(0x9A);
i2c_write(0x00);

i2c_start();
i2c_write(0x9B);
temp = i2c_read(0);
i2c_stop();

with correct address for TC74A0-5.0VCT (changed 0x9A->0x90 and 0x9B->0x91)

i2c_start();
i2c_write(0x90); //For
i2c_write(0x00);

i2c_start();
i2c_write(0x91);
temp = i2c_read(0);
i2c_stop();

[/b]

Thank you all for your help.
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 1, 2  Next
Page 1 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