Hepta温度センサー

Dependents:   HEPTA_Temp HEPTA2_assembly_0720 HEPTA2_ALL HEPTA2_ALL_ver0803_02 ... more

Committer:
hepta2ume
Date:
Fri Jul 21 10:36:09 2017 +0000
Revision:
1:a23c2cd65379
Parent:
0:f74735cb01bc
HeptaTemp

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 1:a23c2cd65379 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 float volt = (_pin.read())*3.3*(R_1 + R_2)/R_1;
hepta2ume 0:f74735cb01bc 35 float Rth = (volt-off)/gain+R3;
hepta2ume 0:f74735cb01bc 36 *temp = (Rth-Pt)/(ce*Pt);
hepta2ume 1:a23c2cd65379 37 /* printf("%f\r\n",volt);
hepta2ume 1:a23c2cd65379 38 printf("%f\r\n",Rth);
hepta2ume 1:a23c2cd65379 39 printf("%f\r\n",*temp);*/
hepta2ume 0:f74735cb01bc 40 // delay some time before reading again
hepta2ume 0:f74735cb01bc 41 wait(0.5);
hepta2ume 0:f74735cb01bc 42
hepta2ume 0:f74735cb01bc 43 }
hepta2ume 0:f74735cb01bc 44
hepta2ume 0:f74735cb01bc 45 void HeptaTemp::temp_sense_u16(char* temp_u16, int *dsize)
hepta2ume 0:f74735cb01bc 46 {
hepta2ume 0:f74735cb01bc 47 unsigned short temp_datas;
hepta2ume 0:f74735cb01bc 48 char temp1[8]= {0x00},temp2[8]= {0x00};
hepta2ume 0:f74735cb01bc 49 temp_datas=_pin.read_u16()>>4;
hepta2ume 0:f74735cb01bc 50 sprintf( temp1, "%02X", (temp_datas >> 8) & 0x0F);
hepta2ume 0:f74735cb01bc 51 sprintf( temp2, "%02X", (temp_datas) & 0xFF);
hepta2ume 0:f74735cb01bc 52 temp_u16[0]=temp1[0];
hepta2ume 0:f74735cb01bc 53 temp_u16[1]=temp1[1];
hepta2ume 0:f74735cb01bc 54 temp_u16[2]=temp2[0];
hepta2ume 0:f74735cb01bc 55 temp_u16[3]=temp2[1];
hepta2ume 0:f74735cb01bc 56 *dsize = 4;
hepta2ume 1:a23c2cd65379 57 }
hepta2ume 1:a23c2cd65379 58
hepta2ume 1:a23c2cd65379 59 void HeptaTemp::temp_sensing_vol(float* voltage)
hepta2ume 1:a23c2cd65379 60 {
hepta2ume 1:a23c2cd65379 61 R_1 = 3;
hepta2ume 1:a23c2cd65379 62 R_2 = 2;
hepta2ume 1:a23c2cd65379 63 *voltage = (_pin.read())*3.3*(R_1 + R_2)/R_1;
hepta2ume 1:a23c2cd65379 64
hepta2ume 0:f74735cb01bc 65 }