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

How to use TPA81 Thermopile Array with PIC16F877

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



Joined: 16 Jun 2010
Posts: 31

View user's profile Send private message

How to use TPA81 Thermopile Array with PIC16F877
PostPosted: Tue Jul 20, 2010 2:49 pm     Reply with quote

I want to use TPA81 Thermopile Array with PIC16F877 but I don't know how to use, and in data sheet not have more data for use. If you have simple code for read data from TPA81 Thermopile Array and send to serial port for show data. Sad Please help me.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 20, 2010 3:03 pm     Reply with quote

Look at the webpages of the online sellers. They have tons of sample
code for the TPA81. It might not be in CCS, but it's close enough.

Look at the .Zip file at the bottom of this page:
http://www.robot-electronics.co.uk/htm/thermabot.htm
It has a getTemperature() function that reads the temperature from
the TPA81. Just translate it to CCS. Change i2c_tx() to i2c_write().
Change i2c_rx() to i2c_read(). Keep the same parameters as in
their code. You will also need to use their global array, temperature[].
Keep that same declaration of it. Add the normal framework for a
CCS program, with the #use i2c() line, and that gives the basic code
that you need.
xbach



Joined: 21 Jul 2010
Posts: 1

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 6:43 am     Reply with quote

Hi, maybe..
Code:
//*********************************************************************//
//  P2P_TPA81.c     (PICDEM(tm)2 PLUS DEMO BOARD)                      //
//                                                                     //
//  Funktion: lest 8 (9) Temperaturwerte des Devantech TPA81           //
//  Thermopilesensors und setzt das Servo.                             //
//                                                                     //
//  Pinbelegung TPA81 :    +------------+                              //
//               gr  +5V --|o           |                              //
//               li  SDA --|o           |                              //
//               bl  SCL --|o  TPA81    |                              //
//                    nc   |o           |                              //
//               gn  Gnd --|o           |                              //
//                         |            |                              //
//                  Pulse--|o           |                              //
//           Servo    +5V--|o           |                              //
//                    GnD--|o           |                              //
//                         +------------+                              //
//                                                                     //
//   Bach 30.04.2009                                                   //
//*********************************************************************//
//#include <18F4520.h>
//#fuses INTRC_IO,NOWDT,NOPROTECT
//#use delay(clock=8000000)
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use i2c(master, SCL=PIN_C3, SDA=PIN_C4)

#include <_lcd_p2p.c>

byte  TPA81_ID = 0xD0; // Standardadresse I2C für TPA81
byte  t[10], i, servo;

// liefert die Temperatur in t[] array und
// Firmwareversion in t[0]
//***************************************************
void read_tpa81( byte slaveID ) {

   for ( i=0; i<10; i++) {

      i2c_start();
      i2c_write(slaveID);
      i2c_write(i);            // Leseregister
      i2c_start();
      i2c_write(slaveID+1);
      t[i] =  i2c_read(0);
      i2c_stop ();
      delay_ms(10);
   }
}

// setzt Servoposition 0..32
//***************************************************
void set_servo_tpa81 ( byte slaveID, byte servo_pos ) {
   i2c_start();
   i2c_write(slaveID);
   i2c_write(0);
   i2c_write(servo_pos&0x1F);              // 0.. 31
   i2c_stop ();
}

//****************************************************
void main() {

   lcd_init();
   printf(lcd_putc,"\f  PICdem2 Plus  ");
   printf(lcd_putc,"\n   (c)Bach09");
   delay_ms(2000);
     //    .........  1234567890123456 ......
   printf(lcd_putc,"\f* Sensor TPA81 *\n");
   read_tpa81( TPA81_ID );
   printf(lcd_putc,"Firmware V.1.%u", t[0]);
   delay_ms(1000);
   servo=0;

while (1) {

   if (!input(PIN_A4)) servo += 3;
   read_tpa81( TPA81_ID );
   printf (lcd_putc,"\f%u %u %u %u\n", t[1], t[2], t[3], t[4]);
   printf (lcd_putc,"%u %u %u %u", t[5], t[6], t[7], t[8]);
   set_servo_tpa81 ( TPA81_ID, servo );
   while (!input(PIN_B0)) printf(lcd_putc,"\f ServoPos %u",servo);
   delay_ms(1000);
  }
}
mmc01



Joined: 16 Jun 2010
Posts: 31

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 7:18 pm     Reply with quote

I use this code and it show
255 255 255 255
255 255 255 255 only. I can't read data from tpa81. please help me.

Code:
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(BAUD=9600,xmit=PIN_C6,rcv=PIN_C7)
#use i2c(master, SCL=PIN_C3, SDA=PIN_C4)


byte  TPA81_ID = 0xD0; // Standardadresse I2C f?r TPA81
byte  t[10], i, servo;

// liefert die Temperatur in t[] array und
// Firmwareversion in t[0]
//***************************************************
void read_tpa81( byte slaveID ) {

   for ( i=0; i<10; i++) {

      i2c_start();
      i2c_write(slaveID);
      i2c_write(i);            // Leseregister
      i2c_start();
      i2c_write(slaveID+1);
      t[i] =  i2c_read(0);
      i2c_stop ();
      delay_ms(10);
   }
}

// setzt Servoposition 0..32
//***************************************************
void set_servo_tpa81 ( byte slaveID, byte servo_pos ) {
   i2c_start();
   i2c_write(slaveID);
   i2c_write(0);
   i2c_write(servo_pos&0x1F);              // 0.. 31
   i2c_stop ();
}

//****************************************************
void main() {

   
   printf("\f  PICdem2 Plus  ");
   printf("\n   (c)Bach09");
   delay_ms(2000);
     //    .........  1234567890123456 ......
   printf("\f* Sensor TPA81 *\n");
   read_tpa81( TPA81_ID );
   printf("Firmware V.1.%u", t[0]);
   delay_ms(1000);
   servo=0;

while (1) {

   if (!input(PIN_A4)) servo += 3;
   read_tpa81( TPA81_ID );
   printf ("\f%u %u %u %u\n", t[1], t[2], t[3], t[4]);
   printf ("%u %u %u %u", t[5], t[6], t[7], t[8]);
   set_servo_tpa81 ( TPA81_ID, servo );
   while (!input(PIN_B0)) printf("\f ServoPos %u",servo);
   delay_ms(1000);
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 7:39 pm     Reply with quote

Do have 4.7K pull-up resistors on the SDA and SCL lines ?
One reason for getting 0xFF is if you forget to put the pull-ups on.
They are part of the i2c specification.
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