CLTP 8 / HeptaTemp

Fork of HeptaTemp by Hepta 2

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HeptaTemp.cpp Source File

HeptaTemp.cpp

00001 #include"HeptaTemp.h"
00002 #include"mbed.h"
00003 
00004 HeptaTemp::HeptaTemp(PinName pin) : _pin(pin)
00005 {
00006 
00007 }
00008 
00009 void HeptaTemp::temp_sense(float* temp)
00010 {
00011 //resistance
00012     R1 = 2500;
00013     R2 = 2500;
00014     R3 = 110;
00015     R4 = 1000;
00016     R5 = 68000;
00017     Pt = 100;
00018     R_1 = 3;
00019     R_2 = 2;
00020 
00021 //current
00022     I = 0.001;
00023 
00024 //voltage
00025     Vref = 2.5;
00026 
00027 //Gain&Offset
00028     float gain = -R5*I/R4;
00029     float off = Vref+I*R3;
00030     //printf("%f\r\n",gain);
00031     //printf("%f\r\n",off);
00032 //temperature coefficient
00033     ce = 0.003851;
00034     float volt = (_pin.read())*3.3*(R_1 + R_2)/R_1;
00035     float Rth = (volt-off)/gain+R3;
00036     *temp = (Rth-Pt)/(ce*Pt);
00037     /* printf("%f\r\n",volt);
00038      printf("%f\r\n",Rth);
00039      printf("%f\r\n",*temp);*/
00040     // delay some time before reading again
00041     wait(0.5);
00042 
00043 }
00044 
00045 void HeptaTemp::temp_sense_u16(char* temp_u16, int *dsize)
00046 {
00047     unsigned short temp_datas;
00048     char temp1[8]= {0x00},temp2[8]= {0x00};
00049     temp_datas=_pin.read_u16()>>4;
00050     sprintf( temp1, "%02X", (temp_datas >> 8) & 0x0F);
00051     sprintf( temp2, "%02X", (temp_datas) & 0xFF);
00052     temp_u16[0]=temp1[0];
00053     temp_u16[1]=temp1[1];
00054     temp_u16[2]=temp2[0];
00055     temp_u16[3]=temp2[1];
00056     *dsize = 4;
00057 }
00058 
00059 void HeptaTemp::temp_sensing_vol(float* voltage)
00060 {
00061     R_1 = 3;
00062     R_2 = 2;
00063     *voltage = (_pin.read())*3.3*(R_1 + R_2)/R_1;
00064 
00065 }