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

Driver for TC72 Temperature Sensor

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



Joined: 09 Aug 2005
Posts: 32

View user's profile Send private message

Driver for TC72 Temperature Sensor
PostPosted: Thu Aug 18, 2005 2:41 pm     Reply with quote

Anyone has a driver for the Microchip TC72 device?

Please help....


Thanks...
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

TC72 Driver Info
PostPosted: Thu Aug 18, 2005 3:12 pm     Reply with quote

Try the Microchip AN940 and accompanying source code for information on how a driver should be built.

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en020348

http://ww1.microchip.com/downloads/en/AppNotes/00940A%20Source%20Code.zip

Here is some C Source for the TC77 that might help...

http://forum.microchip.com/attachment.asp?m=103923
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Thu Aug 18, 2005 3:41 pm     Reply with quote

Code:

#include <16F876.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000) /* one instruction=1us? */
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use I2C(master, SCL=PIN_C3, SDA=PIN_C4)

void main(void)
{
            int data;
            int ack;
            long int fahr;

    printf ("\r\n\r\n\r\n");
    printf ("T C 7 2   D E M O\r\n");
    while (1)
    {     
         i2c_start();
         ack = i2c_write(0x9A);
        ack = i2c_write(0x00);

        /* send start again */
        i2c_start();
        ack = i2c_write(0x9b);
        data = i2c_read();     
        i2c_stop();
        fahr = (9 * (long)data);
        fahr = fahr/5;
        fahr = fahr + 32;
        printf ("Temp: %ld\r\n", fahr);       
        delay_ms(200);
    }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 18, 2005 3:55 pm     Reply with quote

Quote:
printf ("T C 7 2 D E M O\r\n");
while (1)
{
i2c_start();
ack = i2c_write(0x9A);
ack = i2c_write(0x00);

TC72 is a SPI chip, not i2c.

http://www.microchip.com/stellent/idcplgidcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010748
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Thu Aug 18, 2005 4:09 pm     Reply with quote

oops. I cut and pasted code that i once wrote for the PICDEM. And i added some printf's in there. Looking at the schematic i realize now it is a TC74.

Why don't you just use a TC77 or a TC74. The code is here.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Aug 18, 2005 4:13 pm     Reply with quote

Just think how much will be learned if they use the Microchip info and develops a driver instead of having someone else do all the work... I have been forced to write written custom drivers 10-12 times now and have gotten pretty good at it. Not so hard with a little practice...
newpic



Joined: 09 Aug 2005
Posts: 32

View user's profile Send private message

TC72 Help
PostPosted: Fri Aug 19, 2005 8:11 am     Reply with quote

Can any body look at my code, why it does not work. Do I need to have the driver or not?

Thanks in advanced.

Code:
#include <16F876A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 

#define clk      pin_c3                   // set pin clock is using
#define din      pin_c5                   // set pin data in is using
#define cs       pin_b2                   // set pin load/cs is using

int16 temp1;

void main()
{

    output_low(clk);                      // set clk line low 
      delay_us(1);
    output_low(din);                      // set data line in low
      delay_us(1);
    output_low(cs);                       // set load/cs line high
      delay_us(1);
   
                             

     setup_adc_ports(NO_ANALOGS);
     // Configure TC72 temperature sensor
     setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);

   while(1)
   {
      
      output_high(cs);                     // set cs line high
      delay_us(1); 
         spi_write(0x80);                 // Write Address
      delay_us(1);
      spi_write(0x00);             // Continuous mode
      delay_ms(150);                // Delay 150ms to let it complete conversion
   
      spi_write(0x02);              // Point to MSB temp register
      delay_us(1);
        temp1=spi_read(0);                // read temp
       delay_us(1); 
      output_low(cs);
      
      printf("Temperature is: %lu\n\r",temp1);
   
      }
   
}
Guest








Re: TC72 Help
PostPosted: Fri Aug 19, 2005 9:49 am     Reply with quote

newpic wrote:
Can any body look at my code, why it does not work. Do I need to have the driver or not?


Actually, your spi_write() and read functions are the "driver".
Guest








PostPosted: Fri Aug 19, 2005 9:52 am     Reply with quote

It always display

"Temperature is: 0 "

It does not get the right temperature data with the above code.
Did I do anything wrong in the code?
Guest
Guest







PostPosted: Fri Aug 19, 2005 11:15 am     Reply with quote

If you see icicles in the room, then I guess you did it right.
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