For Hepta-Sat Lite

Committer:
hepta2ume
Date:
Thu Jul 20 02:15:14 2017 +0000
Revision:
0:f74735cb01bc
Child:
1:a23c2cd65379
Hepta??????;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hepta2ume 0:f74735cb01bc 1 #include"HeptaTemp.h"
hepta2ume 0:f74735cb01bc 2 #include"mbed.h"
hepta2ume 0:f74735cb01bc 3
hepta2ume 0:f74735cb01bc 4 HeptaTemp::HeptaTemp(PinName pin) : _pin(pin)
hepta2ume 0:f74735cb01bc 5 {
hepta2ume 0:f74735cb01bc 6
hepta2ume 0:f74735cb01bc 7 }
hepta2ume 0:f74735cb01bc 8
hepta2ume 0:f74735cb01bc 9 void HeptaTemp::temp_sense(float* temp)
hepta2ume 0:f74735cb01bc 10 {
hepta2ume 0:f74735cb01bc 11 //resistance
hepta2ume 0:f74735cb01bc 12 R1 = 2500;
hepta2ume 0:f74735cb01bc 13 R2 = 2500;
hepta2ume 0:f74735cb01bc 14 R3 = 110;
hepta2ume 0:f74735cb01bc 15 R4 = 1000;
hepta2ume 0:f74735cb01bc 16 R5 = 68000;
hepta2ume 0:f74735cb01bc 17 Pt = 100;
hepta2ume 0:f74735cb01bc 18 R_1 = 3;
hepta2ume 0:f74735cb01bc 19 R_2 = 2;
hepta2ume 0:f74735cb01bc 20
hepta2ume 0:f74735cb01bc 21 //current
hepta2ume 0:f74735cb01bc 22 I = 0.001;
hepta2ume 0:f74735cb01bc 23
hepta2ume 0:f74735cb01bc 24 //voltage
hepta2ume 0:f74735cb01bc 25 Vref = 2.5;
hepta2ume 0:f74735cb01bc 26
hepta2ume 0:f74735cb01bc 27 //Gain&Offset
hepta2ume 0:f74735cb01bc 28 float gain = -R5*I/R4;
hepta2ume 0:f74735cb01bc 29 float off = Vref+I*R3;
hepta2ume 0:f74735cb01bc 30 //printf("%f\r\n",gain);
hepta2ume 0:f74735cb01bc 31 //printf("%f\r\n",off);
hepta2ume 0:f74735cb01bc 32 //temperature coefficient
hepta2ume 0:f74735cb01bc 33 ce = 0.003851;
hepta2ume 0:f74735cb01bc 34
hepta2ume 0:f74735cb01bc 35 float volt = (_pin.read())*3.3*(R_1 + R_2)/R_1;
hepta2ume 0:f74735cb01bc 36 float Rth = (volt-off)/gain+R3;
hepta2ume 0:f74735cb01bc 37 *temp = (Rth-Pt)/(ce*Pt);
hepta2ume 0:f74735cb01bc 38 /* printf("%f\r\n",volt);
hepta2ume 0:f74735cb01bc 39 printf("%f\r\n",Rth);
hepta2ume 0:f74735cb01bc 40 printf("%f\r\n",*temp);*/
hepta2ume 0:f74735cb01bc 41 // delay some time before reading again
hepta2ume 0:f74735cb01bc 42 wait(0.5);
hepta2ume 0:f74735cb01bc 43
hepta2ume 0:f74735cb01bc 44 }
hepta2ume 0:f74735cb01bc 45
hepta2ume 0:f74735cb01bc 46 void HeptaTemp::temp_sense_u16(char* temp_u16, int *dsize)
hepta2ume 0:f74735cb01bc 47 {
hepta2ume 0:f74735cb01bc 48 unsigned short temp_datas;
hepta2ume 0:f74735cb01bc 49 char temp1[8]= {0x00},temp2[8]= {0x00};
hepta2ume 0:f74735cb01bc 50 temp_datas=_pin.read_u16()>>4;
hepta2ume 0:f74735cb01bc 51 sprintf( temp1, "%02X", (temp_datas >> 8) & 0x0F);
hepta2ume 0:f74735cb01bc 52 sprintf( temp2, "%02X", (temp_datas) & 0xFF);
hepta2ume 0:f74735cb01bc 53 temp_u16[0]=temp1[0];
hepta2ume 0:f74735cb01bc 54 temp_u16[1]=temp1[1];
hepta2ume 0:f74735cb01bc 55 temp_u16[2]=temp2[0];
hepta2ume 0:f74735cb01bc 56 temp_u16[3]=temp2[1];
hepta2ume 0:f74735cb01bc 57 *dsize = 4;
hepta2ume 0:f74735cb01bc 58 }