|
|
View previous topic :: View next topic |
Author |
Message |
Becskei Guest
|
TCN75 temperature jumping |
Posted: Fri Dec 27, 2002 2:07 pm |
|
|
With a PIC16F877 controler I2c is writen the communication with TCN75 temperature sensor.
It is done with hardware and software both.
And the temperature is jumping [0-5 deegre], please help me!!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 10272 |
|
|
xvi.lajos
Joined: 06 Sep 2003 Posts: 12 Location: Hungary
|
Re: TCN75 temperature jumping |
Posted: Sun Dec 29, 2002 12:17 pm |
|
|
:=With a PIC16F877 controler I2c is writen the communication with TCN75 temperature sensor.
:=It is done with hardware and software both.
:=And the temperature is jumping [0-5 deegre], please help me!!!
May be two reasons.
Do you give enough time to the sensor between two readings?
TNC75 accuracy is around 2-3 deegre mey be you get a less accuracy one
George
___________________________
This message was ported from CCS's old forum
Original Post ID: 10312 |
|
|
mark r. hahn Guest
|
Re: TCN75 temperature jumping |
Posted: Sun Dec 29, 2002 2:51 pm |
|
|
I had some problems using i2c interfacing to talk to a tcn75. You should check the ACK bit returned from the TCN75 when reading from it. When I got no ACK back, I often read 0's (or at least that's what the CCS i2c function returned).
mark
___________________________
This message was ported from CCS's old forum
Original Post ID: 10315 |
|
|
xvi.lajos
Joined: 06 Sep 2003 Posts: 12 Location: Hungary
|
Re: TCN75 temperature jumping |
Posted: Fri Jan 03, 2003 2:04 am |
|
|
Hello,
I tried to answer your pivate mail, but your e-mail address is invalid.
Send me please a correct address if you want my answer.
George
___________________________
This message was ported from CCS's old forum
Original Post ID: 10387 |
|
|
gustavo
Joined: 01 Oct 2003 Posts: 4 Location: estudiante
|
Re: TCN75 temperature jumping |
Posted: Tue Oct 07, 2003 4:42 am |
|
|
[quote="mark r. hahn"]I had some problems using i2c interfacing to talk to a tcn75. You should check the ACK bit returned from the TCN75 when reading from it. When I got no ACK back, I often read 0's (or at least that's what the CCS i2c function returned).
mark
___________________________
This message was ported from CCS's old forum
Original Post ID: 10315[/quote]
Hello everybody.
My name is Gustavo Adolfo, please help me, I wanted to build an altimeter, but my problem is centered in that cannot operate the TCN75, this it is my code, please help me, they will be very grateful for everything it.
#include <16f876.h>
#device ADC=10 // A/D Result format
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOCPD,NOWRT
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3)
//SE DEFINE EL FORMATO PARA LA Tx a 9600 BAUDS VIA RS-232 STANDAR, DADO QUE SON LAS
//PROPIAS LIBRERIAS DEL COMPILADOR CCS, (VER EL LIBRO DE GARDER "PIC C")
//CON UN OSC. 4MHZ Vtx=1200 BAUDS , PARA UN OSC. 10MHZ Vtx=9600
#use delay (CLOCK=10000000)
#use rs232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
// SE DEFINE LA DIRECCION DEL PUERTO B COMO ELEMENTO DE ENTRADA SALIDA.
// ASI COMO LA DIRECCION DE MEMORIA DE CADA UNO DE LOS DEMAS PUERTOS A,B,C.
// DICHA INFORMACION SE ENCUENTRA ESPECIFICADA EN EL REGISTRO DE MEMORIA DEL PIC.
// (MAYOR INFORMACIÓN DATA SHEET DE MICROCHIP WWW.MICROCHIP.COM
// SE INCLUYE EL ENCABEZADO DE LA LIBRERIA PARA LA OPERACION DEL LCD
// POR EL PUERTO B,OBSERVAR PROGRAMA lcd_ptob.c
#use fast_io (b)
#byte porta = 5
#byte portb = 6
#byte portc = 7
#include <lcd_b.c>
#include <math.c>
// SON LAS LIBRERIAS QUE SE HACEN USO EN EL MENU PRINCIPAL PARA PODER
// DESPLEGAR LOS DATOS, ASI COMO EL MANEJOR DEL LCD POR EL PUERTO B.
// PROPIAS DE CCS
/************************************************************************************/
void algoritmo(void);
void setp0(void);
void writeEEp0(void);
void readEEp0(void);
void medida(void);
void calibrar(void);
void intermedida(void);
void readTemperatur(void);
void readEEProm(void);
byte read_ext_eeprom(long int address);
void write_ext_eeprom(long int address, byte data);
void initEEProm(void);
/************************************************************************************/
#define PortBConfig 0b11111111 /* Configure port B 0 = output */
#define PortCConfig 0b10000111 /* Configure port C 0 = output */
#define EE_P0 0x00 // Addr. im EE-Prom + 3 Byte !!!!
#define EE_OFFSET 0x04
#define EE_DT 0x05 // Intervalo de medida.
/*************************************************************************************/
/************************************************************************************/
#bit ADFM=0X9F.7
float dh,temp,p0,ph,valmed;
char offset, temperaturMSB, temperaturLSB, time;
short store;
long index;
Void main (void)
{
signed long h;
int ch;
ch=1;
lcd_init();
set_tris_b( PortBConfig );
set_tris_c( PortCConfig );
//Configuración del convertidor A/D a 10 Bits pto B o C
setup_adc_ports(ANALOG_RA3_REF); // Entrada RA3 es la referencia 5 Volts
setup_adc(ADC_CLOCK_DIV_32); // Especificación del reloj
ADFM=TRUE;
store=FALSE;
/**************************************************************************/
lcd_init(); // Habilita al LCD
readEEp0(); // Lee el Valor de p0
offset = read_eeprom(EE_OFFSET); // Lee el valor de Offset.
time = read_eeprom(EE_DT); // Lee el Intervalo de Medida.
printf(lcd_putc,"\fDISENO POR\n(c) GAMCH. 2003");
delay_ms(2000);
do
{
output_high(PIN_C5); // Pin de funcionamiento para el LCD.
medida();
algoritmo();
lcd_gotoxy(1,1);
printf(lcd_putc,"%4.0fkPa p0:%4.0f \n",ph, p0) ;
printf(lcd_putc,"dh:%3.0fm", dh);
if(store)
printf(lcd_putc,"*");
readTemperatur();
printf(lcd_putc,"%D.%U",temperaturMSB, temperaturLSB) ;
lcd_putc(0xDF); lcd_putc('C');
printf(lcd_putc," ");
output_low(PIN_C5);
// Pin de funcionamiento de la EEPROM 24LC16
if(store)
{
h = temp;
write_ext_eeprom(index,h>>8); // MSB
index++;
write_ext_eeprom(index,h); // LSB
index++;
}
// Pin de funcionamiento para la EEPROM EXTERNA 24LC16.
if(index == 2048)
store = FALSE;
setp0();
if(kbhit())
{
getc();
readEEProm();
}
}
While (1);
}
/*************************************************************************************/
/************************************************************************************/
void medida(void)
{
char i;
float valmed,m,x,k1,k2;
k1=10.844;
k2=14.3531;
x = 0;
for(i= 0; i<16; i++)
{
set_adc_channel (0);
valmed = read_adc();
x+= valmed;
}
valmed = x/16;
x = 0;
for(i= 0; i<16; i++)
{
set_adc_channel (0);
valmed = read_adc();
x+= valmed;
}
x = x/16;
valmed += x;
valmed /= 2;
valmed+=offset;
ph=((valmed/k1)+(k2)); // Medida en el sensor MPX4100 cuyas unidades son Kpascales
m = 0.00897571 * (float)valmed; // Coeficiente de error de presion.
temp=145.25+m; // Valor de referencia en Kpascales.
}
/**************************************************************************/
/* */
/**************************************************************************/
void algoritmo(void)
{
float b;
b = 101.325/ph;
b = log(b);
dh = b*8000.0;
}
/**************************************************************************/
/* */
/**************************************************************************/
void setp0(void)
{
long i;
char x;
for(x= 0; x < time; x++)
{
#ifdef DEBUG
for(i= 0; i<1000;i++)
{
if( !input(PIN_B1) )
{
delay_ms(10);
if( !input(PIN_B1) )
{
printf(lcd_putc,"\f<calibrar>");
while( !input(PIN_B1) )
;
calibrar();
intermedida();
goto ENDE;
}
}
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
printf(lcd_putc,"\f");
while( !input(PIN_B2) )
;
initEEProm();
store = TRUE;
index = 0;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
printf(lcd_putc,"\f");
while( !input(PIN_B3) )
;
p0 = ph;
writeEEp0();
}
}
delay_ms(1);
}
#else
for(i=0; i<1000;i++)
{
if( !input(PIN_C0) )
{
delay_ms(10);
if( !input(PIN_C0) )
{
printf(lcd_putc,"\f<calibrar>");
while( !input(PIN_C0) )
;
calibrar();
intermedida();
goto ENDE;
}
}
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
printf(lcd_putc,"\f");
while( !input(PIN_C1) )
;
initEEProm();
store = TRUE;
index = 0;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
printf(lcd_putc,"\f");
while( !input(PIN_C2) )
;
p0 = temp;
writeEEp0();
}
}
delay_ms(1);
}
#endif // DEBUG
}
ENDE:;
}
/**************************************************************************/
/* */
/**************************************************************************/
void calibrar(void)
{
#ifdef DEBUG
while(input(PIN_B1))
{
medida();
printf(lcd_putc,"\n%4.0fhPa cor:%u ",ph, offset) ;
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
while( !input(PIN_B2) )
;
offset++;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
while( !input(PIN_B3) )
;
offset--;
}
}
}
while( !input(PIN_B1) )
;
#else
while(input(PIN_C0))
{
medida();
printf(lcd_putc,"\n%4.0fhPa cor:%u ",temp, offset) ;
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
while( !input(PIN_C1) )
;
offset++;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
while( !input(PIN_C2) )
;
offset--;
}
}
}
while( !input(PIN_C0) )
;
#endif
write_eeprom(EE_OFFSET, offset);
}
/**************************************************************************/
/* */
/**************************************************************************/
void intermedida(void)
{
printf(lcd_putc,"\fINTERVALO MEDIDA");
#ifdef DEBUG
while(input(PIN_B1))
{
printf(lcd_putc,"\n%u sec ",time);
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
while( !input(PIN_B2) )
;
time++;
if(time == 0)
time = 1;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
while( !input(PIN_B3) )
;
time--;
if(time == 0)
time = 255;
}
}
}
while( !input(PIN_B1) )
;
#else
while(input(PIN_C0))
{
printf(lcd_putc,"\n%u sec ",time);
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
while( !input(PIN_C1) )
;
time++;
if(time == 0)
time = 1;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
while( !input(PIN_C2) )
;
time--;
if(time == 0)
time = 255;
}
}
}
while( !input(PIN_C0) )
;
#endif
write_eeprom(EE_DT, time);
}
/**************************************************************************/
/* */
/**************************************************************************/
void readTemperatur(void)
{
i2c_Start(); // Set a START condition I2C Bus
i2c_Write(0x90); // Address and Write Flag
i2c_Write(0xaa); // Pointer Byte TEMP Register selection
i2c_Start();
i2c_Write(0x91); // Address and Read Flag
temperaturMSB = i2c_Read(); // Read High Byte Teperature
temperaturLSB = i2c_Read(0);// Read Low Byte Teperature send no ACK
i2c_stop();
if((temperaturLSB & 0x80) == 0x80)
temperaturLSB = 5;
else
temperaturLSB = 0;
}
/**************************************************************************/
/* */
/**************************************************************************/
void writeEEp0(void)
{
int i;
for (i = 0; i < 4; i++)
write_eeprom(i, *(&p0 + i) ) ;
}
/**************************************************************************/
/* */
/**************************************************************************/
void readEEp0(void)
{
int i;
for (i = 0; i < 4; i++)
*(&p0 + i) = read_eeprom(i);
}
/**************************************************************************/
/* */
/**************************************************************************/
byte read_ext_eeprom(long int address) {
byte data;
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_start();
i2c_write((0xa0|(byte)(address>>7))|1);
data=i2c_read(0);
i2c_stop();
return(data);
}
/**************************************************************************/
/* */
/**************************************************************************/
void write_ext_eeprom(long int address, byte data) {
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(11);
}
/**************************************************************************/
/* */
/**************************************************************************/
void readEEProm(void)
{
long int i;
signed long h;
i=0;
while(TRUE)
{
h = read_ext_eeprom(i);
i++;
h = h << 8;
h = h | read_ext_eeprom(i);
printf("%lu:0x%2x\n\r",i, read_ext_eeprom(i));
printf("%ld,\r", h);
if(i == 2047)
{
printf("\n");
break;
}
i++;
}
}
/**************************************************************************/
/* */
/**************************************************************************/
void initEEProm(void)
{
long int i;
printf(lcd_putc,"\fInit EEProm...\nespere 20sec");
i=0;
while(TRUE)
{
write_ext_eeprom(i,0x00);
if(i == 2047)
break;
i++;
}
} |
|
|
gustavo
Joined: 01 Oct 2003 Posts: 4 Location: estudiante
|
Re: TCN75 temperature jumping |
Posted: Tue Oct 07, 2003 4:43 am |
|
|
mark r. hahn wrote: | I had some problems using i2c interfacing to talk to a tcn75. You should check the ACK bit returned from the TCN75 when reading from it. When I got no ACK back, I often read 0's (or at least that's what the CCS i2c function returned).
mark
___________________________
This message was ported from CCS's old forum
Original Post ID: 10315 |
Hello everybody.
My name is Gustavo Adolfo, please help me, I wanted to build an altimeter, but my problem is centered in that cannot operate the TCN75, this it is my code, please help me, they will be very grateful for everything it.
#include <16f876.h>
#device ADC=10 // A/D Result format
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOCPD,NOWRT
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3)
//SE DEFINE EL FORMATO PARA LA Tx a 9600 BAUDS VIA RS-232 STANDAR, DADO QUE SON LAS
//PROPIAS LIBRERIAS DEL COMPILADOR CCS, (VER EL LIBRO DE GARDER "PIC C")
//CON UN OSC. 4MHZ Vtx=1200 BAUDS , PARA UN OSC. 10MHZ Vtx=9600
#use delay (CLOCK=10000000)
#use rs232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
// SE DEFINE LA DIRECCION DEL PUERTO B COMO ELEMENTO DE ENTRADA SALIDA.
// ASI COMO LA DIRECCION DE MEMORIA DE CADA UNO DE LOS DEMAS PUERTOS A,B,C.
// DICHA INFORMACION SE ENCUENTRA ESPECIFICADA EN EL REGISTRO DE MEMORIA DEL PIC.
// (MAYOR INFORMACIÓN DATA SHEET DE MICROCHIP WWW.MICROCHIP.COM
// SE INCLUYE EL ENCABEZADO DE LA LIBRERIA PARA LA OPERACION DEL LCD
// POR EL PUERTO B,OBSERVAR PROGRAMA lcd_ptob.c
#use fast_io (b)
#byte porta = 5
#byte portb = 6
#byte portc = 7
#include <lcd_b.c>
#include <math.c>
// SON LAS LIBRERIAS QUE SE HACEN USO EN EL MENU PRINCIPAL PARA PODER
// DESPLEGAR LOS DATOS, ASI COMO EL MANEJOR DEL LCD POR EL PUERTO B.
// PROPIAS DE CCS
/************************************************************************************/
void algoritmo(void);
void setp0(void);
void writeEEp0(void);
void readEEp0(void);
void medida(void);
void calibrar(void);
void intermedida(void);
void readTemperatur(void);
void readEEProm(void);
byte read_ext_eeprom(long int address);
void write_ext_eeprom(long int address, byte data);
void initEEProm(void);
/************************************************************************************/
#define PortBConfig 0b11111111 /* Configure port B 0 = output */
#define PortCConfig 0b10000111 /* Configure port C 0 = output */
#define EE_P0 0x00 // Addr. im EE-Prom + 3 Byte !!!!
#define EE_OFFSET 0x04
#define EE_DT 0x05 // Intervalo de medida.
/*************************************************************************************/
/************************************************************************************/
#bit ADFM=0X9F.7
float dh,temp,p0,ph,valmed;
char offset, temperaturMSB, temperaturLSB, time;
short store;
long index;
Void main (void)
{
signed long h;
int ch;
ch=1;
lcd_init();
set_tris_b( PortBConfig );
set_tris_c( PortCConfig );
//Configuración del convertidor A/D a 10 Bits pto B o C
setup_adc_ports(ANALOG_RA3_REF); // Entrada RA3 es la referencia 5 Volts
setup_adc(ADC_CLOCK_DIV_32); // Especificación del reloj
ADFM=TRUE;
store=FALSE;
/**************************************************************************/
lcd_init(); // Habilita al LCD
readEEp0(); // Lee el Valor de p0
offset = read_eeprom(EE_OFFSET); // Lee el valor de Offset.
time = read_eeprom(EE_DT); // Lee el Intervalo de Medida.
printf(lcd_putc,"\fDISENO POR\n(c) GAMCH. 2003");
delay_ms(2000);
do
{
output_high(PIN_C5); // Pin de funcionamiento para el LCD.
medida();
algoritmo();
lcd_gotoxy(1,1);
printf(lcd_putc,"%4.0fkPa p0:%4.0f \n",ph, p0) ;
printf(lcd_putc,"dh:%3.0fm", dh);
if(store)
printf(lcd_putc,"*");
readTemperatur();
printf(lcd_putc,"%D.%U",temperaturMSB, temperaturLSB) ;
lcd_putc(0xDF); lcd_putc('C');
printf(lcd_putc," ");
output_low(PIN_C5);
// Pin de funcionamiento de la EEPROM 24LC16
if(store)
{
h = temp;
write_ext_eeprom(index,h>>8); // MSB
index++;
write_ext_eeprom(index,h); // LSB
index++;
}
// Pin de funcionamiento para la EEPROM EXTERNA 24LC16.
if(index == 2048)
store = FALSE;
setp0();
if(kbhit())
{
getc();
readEEProm();
}
}
While (1);
}
/*************************************************************************************/
/************************************************************************************/
void medida(void)
{
char i;
float valmed,m,x,k1,k2;
k1=10.844;
k2=14.3531;
x = 0;
for(i= 0; i<16; i++)
{
set_adc_channel (0);
valmed = read_adc();
x+= valmed;
}
valmed = x/16;
x = 0;
for(i= 0; i<16; i++)
{
set_adc_channel (0);
valmed = read_adc();
x+= valmed;
}
x = x/16;
valmed += x;
valmed /= 2;
valmed+=offset;
ph=((valmed/k1)+(k2)); // Medida en el sensor MPX4100 cuyas unidades son Kpascales
m = 0.00897571 * (float)valmed; // Coeficiente de error de presion.
temp=145.25+m; // Valor de referencia en Kpascales.
}
/**************************************************************************/
/* */
/**************************************************************************/
void algoritmo(void)
{
float b;
b = 101.325/ph;
b = log(b);
dh = b*8000.0;
}
/**************************************************************************/
/* */
/**************************************************************************/
void setp0(void)
{
long i;
char x;
for(x= 0; x < time; x++)
{
#ifdef DEBUG
for(i= 0; i<1000;i++)
{
if( !input(PIN_B1) )
{
delay_ms(10);
if( !input(PIN_B1) )
{
printf(lcd_putc,"\f<calibrar>");
while( !input(PIN_B1) )
;
calibrar();
intermedida();
goto ENDE;
}
}
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
printf(lcd_putc,"\f");
while( !input(PIN_B2) )
;
initEEProm();
store = TRUE;
index = 0;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
printf(lcd_putc,"\f");
while( !input(PIN_B3) )
;
p0 = ph;
writeEEp0();
}
}
delay_ms(1);
}
#else
for(i=0; i<1000;i++)
{
if( !input(PIN_C0) )
{
delay_ms(10);
if( !input(PIN_C0) )
{
printf(lcd_putc,"\f<calibrar>");
while( !input(PIN_C0) )
;
calibrar();
intermedida();
goto ENDE;
}
}
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
printf(lcd_putc,"\f");
while( !input(PIN_C1) )
;
initEEProm();
store = TRUE;
index = 0;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
printf(lcd_putc,"\f");
while( !input(PIN_C2) )
;
p0 = temp;
writeEEp0();
}
}
delay_ms(1);
}
#endif // DEBUG
}
ENDE:;
}
/**************************************************************************/
/* */
/**************************************************************************/
void calibrar(void)
{
#ifdef DEBUG
while(input(PIN_B1))
{
medida();
printf(lcd_putc,"\n%4.0fhPa cor:%u ",ph, offset) ;
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
while( !input(PIN_B2) )
;
offset++;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
while( !input(PIN_B3) )
;
offset--;
}
}
}
while( !input(PIN_B1) )
;
#else
while(input(PIN_C0))
{
medida();
printf(lcd_putc,"\n%4.0fhPa cor:%u ",temp, offset) ;
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
while( !input(PIN_C1) )
;
offset++;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
while( !input(PIN_C2) )
;
offset--;
}
}
}
while( !input(PIN_C0) )
;
#endif
write_eeprom(EE_OFFSET, offset);
}
/**************************************************************************/
/* */
/**************************************************************************/
void intermedida(void)
{
printf(lcd_putc,"\fINTERVALO MEDIDA");
#ifdef DEBUG
while(input(PIN_B1))
{
printf(lcd_putc,"\n%u sec ",time);
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
while( !input(PIN_B2) )
;
time++;
if(time == 0)
time = 1;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
while( !input(PIN_B3) )
;
time--;
if(time == 0)
time = 255;
}
}
}
while( !input(PIN_B1) )
;
#else
while(input(PIN_C0))
{
printf(lcd_putc,"\n%u sec ",time);
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
while( !input(PIN_C1) )
;
time++;
if(time == 0)
time = 1;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
while( !input(PIN_C2) )
;
time--;
if(time == 0)
time = 255;
}
}
}
while( !input(PIN_C0) )
;
#endif
write_eeprom(EE_DT, time);
}
/**************************************************************************/
/* */
/**************************************************************************/
void readTemperatur(void)
{
i2c_Start(); // Set a START condition I2C Bus
i2c_Write(0x90); // Address and Write Flag
i2c_Write(0xaa); // Pointer Byte TEMP Register selection
i2c_Start();
i2c_Write(0x91); // Address and Read Flag
temperaturMSB = i2c_Read(); // Read High Byte Teperature
temperaturLSB = i2c_Read(0);// Read Low Byte Teperature send no ACK
i2c_stop();
if((temperaturLSB & 0x80) == 0x80)
temperaturLSB = 5;
else
temperaturLSB = 0;
}
/**************************************************************************/
/* */
/**************************************************************************/
void writeEEp0(void)
{
int i;
for (i = 0; i < 4; i++)
write_eeprom(i, *(&p0 + i) ) ;
}
/**************************************************************************/
/* */
/**************************************************************************/
void readEEp0(void)
{
int i;
for (i = 0; i < 4; i++)
*(&p0 + i) = read_eeprom(i);
}
/**************************************************************************/
/* */
/**************************************************************************/
byte read_ext_eeprom(long int address) {
byte data;
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_start();
i2c_write((0xa0|(byte)(address>>7))|1);
data=i2c_read(0);
i2c_stop();
return(data);
}
/**************************************************************************/
/* */
/**************************************************************************/
void write_ext_eeprom(long int address, byte data) {
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(11);
}
/**************************************************************************/
/* */
/**************************************************************************/
void readEEProm(void)
{
long int i;
signed long h;
i=0;
while(TRUE)
{
h = read_ext_eeprom(i);
i++;
h = h << 8;
h = h | read_ext_eeprom(i);
printf("%lu:0x%2x\n\r",i, read_ext_eeprom(i));
printf("%ld,\r", h);
if(i == 2047)
{
printf("\n");
break;
}
i++;
}
}
/**************************************************************************/
/* */
/**************************************************************************/
void initEEProm(void)
{
long int i;
printf(lcd_putc,"\fInit EEProm...\nespere 20sec");
i=0;
while(TRUE)
{
write_ext_eeprom(i,0x00);
if(i == 2047)
break;
i++;
}
} |
|
|
gustavo
Joined: 01 Oct 2003 Posts: 4 Location: estudiante
|
Re: TCN75 temperature jumping |
Posted: Tue Oct 07, 2003 4:54 am |
|
|
xvi.lajos wrote: | :=With a PIC16F877 controler I2c is writen the communication with TCN75 temperature sensor.
:=It is done with hardware and software both.
:=And the temperature is jumping [0-5 deegre], please help me!!!
May be two reasons.
Do you give enough time to the sensor between two readings?
TNC75 accuracy is around 2-3 deegre mey be you get a less accuracy one
George
___________________________
This message was ported from CCS's old forum
Original Post ID: 10312 |
Helloˇ
My name is gustavo adolfo, please help me, I wanted to build an altimeter, but my problem is centered in that cannot operate the TCN75, this it is my code, please help me, they will be very grateful for everything it.
#include <16f876.h>
#device ADC=10 // A/D Result format
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOCPD,NOWRT
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3)
//SE DEFINE EL FORMATO PARA LA Tx a 9600 BAUDS VIA RS-232 STANDAR, DADO QUE SON LAS
//PROPIAS LIBRERIAS DEL COMPILADOR CCS, (VER EL LIBRO DE GARDER "PIC C")
//CON UN OSC. 4MHZ Vtx=1200 BAUDS , PARA UN OSC. 10MHZ Vtx=9600
#use delay (CLOCK=10000000)
#use rs232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
// SE DEFINE LA DIRECCION DEL PUERTO B COMO ELEMENTO DE ENTRADA SALIDA.
// ASI COMO LA DIRECCION DE MEMORIA DE CADA UNO DE LOS DEMAS PUERTOS A,B,C.
// DICHA INFORMACION SE ENCUENTRA ESPECIFICADA EN EL REGISTRO DE MEMORIA DEL PIC.
// (MAYOR INFORMACIÓN DATA SHEET DE MICROCHIP WWW.MICROCHIP.COM
// SE INCLUYE EL ENCABEZADO DE LA LIBRERIA PARA LA OPERACION DEL LCD
// POR EL PUERTO B,OBSERVAR PROGRAMA lcd_ptob.c
#use fast_io (b)
#byte porta = 5
#byte portb = 6
#byte portc = 7
#include <lcd_b.c>
#include <math.c>
// SON LAS LIBRERIAS QUE SE HACEN USO EN EL MENU PRINCIPAL PARA PODER
// DESPLEGAR LOS DATOS, ASI COMO EL MANEJOR DEL LCD POR EL PUERTO B.
// PROPIAS DE CCS
/************************************************************************************/
void algoritmo(void);
void setp0(void);
void writeEEp0(void);
void readEEp0(void);
void medida(void);
void calibrar(void);
void intermedida(void);
void readTemperatur(void);
void readEEProm(void);
byte read_ext_eeprom(long int address);
void write_ext_eeprom(long int address, byte data);
void initEEProm(void);
/************************************************************************************/
#define PortBConfig 0b11111111 /* Configure port B 0 = output */
#define PortCConfig 0b10000111 /* Configure port C 0 = output */
#define EE_P0 0x00 // Addr. im EE-Prom + 3 Byte !!!!
#define EE_OFFSET 0x04
#define EE_DT 0x05 // Intervalo de medida.
/*************************************************************************************/
/************************************************************************************/
#bit ADFM=0X9F.7
float dh,temp,p0,ph,valmed;
char offset, temperaturMSB, temperaturLSB, time;
short store;
long index;
Void main (void)
{
signed long h;
int ch;
ch=1;
lcd_init();
set_tris_b( PortBConfig );
set_tris_c( PortCConfig );
//Configuración del convertidor A/D a 10 Bits pto B o C
setup_adc_ports(ANALOG_RA3_REF); // Entrada RA3 es la referencia 5 Volts
setup_adc(ADC_CLOCK_DIV_32); // Especificación del reloj
ADFM=TRUE;
store=FALSE;
/**************************************************************************/
lcd_init(); // Habilita al LCD
readEEp0(); // Lee el Valor de p0
offset = read_eeprom(EE_OFFSET); // Lee el valor de Offset.
time = read_eeprom(EE_DT); // Lee el Intervalo de Medida.
printf(lcd_putc,"\fDISENO POR\n(c) GAMCH. 2003");
delay_ms(2000);
do
{
output_high(PIN_C5); // Pin de funcionamiento para el LCD.
medida();
algoritmo();
lcd_gotoxy(1,1);
printf(lcd_putc,"%4.0fkPa p0:%4.0f \n",ph, p0) ;
printf(lcd_putc,"dh:%3.0fm", dh);
if(store)
printf(lcd_putc,"*");
readTemperatur();
printf(lcd_putc,"%D.%U",temperaturMSB, temperaturLSB) ;
lcd_putc(0xDF); lcd_putc('C');
printf(lcd_putc," ");
output_low(PIN_C5);
// Pin de funcionamiento de la EEPROM 24LC16
if(store)
{
h = temp;
write_ext_eeprom(index,h>>8); // MSB
index++;
write_ext_eeprom(index,h); // LSB
index++;
}
// Pin de funcionamiento para la EEPROM EXTERNA 24LC16.
if(index == 2048)
store = FALSE;
setp0();
if(kbhit())
{
getc();
readEEProm();
}
}
While (1);
}
/*************************************************************************************/
/************************************************************************************/
void medida(void)
{
char i;
float valmed,m,x,k1,k2;
k1=10.844;
k2=14.3531;
x = 0;
for(i= 0; i<16; i++)
{
set_adc_channel (0);
valmed = read_adc();
x+= valmed;
}
valmed = x/16;
x = 0;
for(i= 0; i<16; i++)
{
set_adc_channel (0);
valmed = read_adc();
x+= valmed;
}
x = x/16;
valmed += x;
valmed /= 2;
valmed+=offset;
ph=((valmed/k1)+(k2)); // Medida en el sensor MPX4100 cuyas unidades son Kpascales
m = 0.00897571 * (float)valmed; // Coeficiente de error de presion.
temp=145.25+m; // Valor de referencia en Kpascales.
}
/**************************************************************************/
/* */
/**************************************************************************/
void algoritmo(void)
{
float b;
b = 101.325/ph;
b = log(b);
dh = b*8000.0;
}
/**************************************************************************/
/* */
/**************************************************************************/
void setp0(void)
{
long i;
char x;
for(x= 0; x < time; x++)
{
#ifdef DEBUG
for(i= 0; i<1000;i++)
{
if( !input(PIN_B1) )
{
delay_ms(10);
if( !input(PIN_B1) )
{
printf(lcd_putc,"\f<calibrar>");
while( !input(PIN_B1) )
;
calibrar();
intermedida();
goto ENDE;
}
}
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
printf(lcd_putc,"\f");
while( !input(PIN_B2) )
;
initEEProm();
store = TRUE;
index = 0;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
printf(lcd_putc,"\f");
while( !input(PIN_B3) )
;
p0 = ph;
writeEEp0();
}
}
delay_ms(1);
}
#else
for(i=0; i<1000;i++)
{
if( !input(PIN_C0) )
{
delay_ms(10);
if( !input(PIN_C0) )
{
printf(lcd_putc,"\f<calibrar>");
while( !input(PIN_C0) )
;
calibrar();
intermedida();
goto ENDE;
}
}
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
printf(lcd_putc,"\f");
while( !input(PIN_C1) )
;
initEEProm();
store = TRUE;
index = 0;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
printf(lcd_putc,"\f");
while( !input(PIN_C2) )
;
p0 = temp;
writeEEp0();
}
}
delay_ms(1);
}
#endif // DEBUG
}
ENDE:;
}
/**************************************************************************/
/* */
/**************************************************************************/
void calibrar(void)
{
#ifdef DEBUG
while(input(PIN_B1))
{
medida();
printf(lcd_putc,"\n%4.0fhPa cor:%u ",ph, offset) ;
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
while( !input(PIN_B2) )
;
offset++;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
while( !input(PIN_B3) )
;
offset--;
}
}
}
while( !input(PIN_B1) )
;
#else
while(input(PIN_C0))
{
medida();
printf(lcd_putc,"\n%4.0fhPa cor:%u ",temp, offset) ;
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
while( !input(PIN_C1) )
;
offset++;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
while( !input(PIN_C2) )
;
offset--;
}
}
}
while( !input(PIN_C0) )
;
#endif
write_eeprom(EE_OFFSET, offset);
}
/**************************************************************************/
/* */
/**************************************************************************/
void intermedida(void)
{
printf(lcd_putc,"\fINTERVALO MEDIDA");
#ifdef DEBUG
while(input(PIN_B1))
{
printf(lcd_putc,"\n%u sec ",time);
if( !input(PIN_B2) )
{
delay_ms(10);
if( !input(PIN_B2) )
{
while( !input(PIN_B2) )
;
time++;
if(time == 0)
time = 1;
}
}
if( !input(PIN_B3) )
{
delay_ms(10);
if( !input(PIN_B3) )
{
while( !input(PIN_B3) )
;
time--;
if(time == 0)
time = 255;
}
}
}
while( !input(PIN_B1) )
;
#else
while(input(PIN_C0))
{
printf(lcd_putc,"\n%u sec ",time);
if( !input(PIN_C1) )
{
delay_ms(10);
if( !input(PIN_C1) )
{
while( !input(PIN_C1) )
;
time++;
if(time == 0)
time = 1;
}
}
if( !input(PIN_C2) )
{
delay_ms(10);
if( !input(PIN_C2) )
{
while( !input(PIN_C2) )
;
time--;
if(time == 0)
time = 255;
}
}
}
while( !input(PIN_C0) )
;
#endif
write_eeprom(EE_DT, time);
}
/**************************************************************************/
/* */
/**************************************************************************/
void readTemperatur(void)
{
i2c_Start(); // Set a START condition I2C Bus
i2c_Write(0x90); // Address and Write Flag
i2c_Write(0xaa); // Pointer Byte TEMP Register selection
i2c_Start();
i2c_Write(0x91); // Address and Read Flag
temperaturMSB = i2c_Read(); // Read High Byte Teperature
temperaturLSB = i2c_Read(0);// Read Low Byte Teperature send no ACK
i2c_stop();
if((temperaturLSB & 0x80) == 0x80)
temperaturLSB = 5;
else
temperaturLSB = 0;
}
/**************************************************************************/
/* */
/**************************************************************************/
void writeEEp0(void)
{
int i;
for (i = 0; i < 4; i++)
write_eeprom(i, *(&p0 + i) ) ;
}
/**************************************************************************/
/* */
/**************************************************************************/
void readEEp0(void)
{
int i;
for (i = 0; i < 4; i++)
*(&p0 + i) = read_eeprom(i);
}
/**************************************************************************/
/* */
/**************************************************************************/
byte read_ext_eeprom(long int address) {
byte data;
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_start();
i2c_write((0xa0|(byte)(address>>7))|1);
data=i2c_read(0);
i2c_stop();
return(data);
}
/**************************************************************************/
/* */
/**************************************************************************/
void write_ext_eeprom(long int address, byte data) {
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(11);
}
/**************************************************************************/
/* */
/**************************************************************************/
void readEEProm(void)
{
long int i;
signed long h;
i=0;
while(TRUE)
{
h = read_ext_eeprom(i);
i++;
h = h << 8;
h = h | read_ext_eeprom(i);
printf("%lu:0x%2x\n\r",i, read_ext_eeprom(i));
printf("%ld,\r", h);
if(i == 2047)
{
printf("\n");
break;
}
i++;
}
}
/**************************************************************************/
/* */
/**************************************************************************/
void initEEProm(void)
{
long int i;
printf(lcd_putc,"\fInit EEProm...\nespere 20sec");
i=0;
while(TRUE)
{
write_ext_eeprom(i,0x00);
if(i == 2047)
break;
i++;
}
} |
|
|
|
|
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
|