For Hepta-Sat Lite

Committer:
HEPTA
Date:
Fri Sep 08 07:23:27 2017 +0000
Revision:
4:845cda80eaf0
Parent:
3:96c3dd85be15
Hepta Temperature(revision)

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
HEPTA 4:845cda80eaf0 12 R1 = 2500;//[Ω]
HEPTA 4:845cda80eaf0 13 R2 = 2500;//[Ω]
HEPTA 4:845cda80eaf0 14 R3 = 110;//[Ω]
HEPTA 4:845cda80eaf0 15 R4 = 1000;//[Ω]
HEPTA 4:845cda80eaf0 16 R5 = 68000;//[Ω]
HEPTA 4:845cda80eaf0 17 Pt = 100;//[Ω]
HEPTA 4:845cda80eaf0 18 R_1 = 3;//[kΩ]
HEPTA 4:845cda80eaf0 19 R_2 = 2;//[kΩ]
hepta2ume 0:f74735cb01bc 20
hepta2ume 0:f74735cb01bc 21 //current
HEPTA 4:845cda80eaf0 22 I = 0.001;//[A]
hepta2ume 0:f74735cb01bc 23
hepta2ume 0:f74735cb01bc 24 //voltage
HEPTA 4:845cda80eaf0 25 Vref = 2.5;//[V]
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;
HEPTA 2:de2e2a625a3b 30
hepta2ume 0:f74735cb01bc 31 //temperature coefficient
hepta2ume 0:f74735cb01bc 32 ce = 0.003851;
hepta2ume 0:f74735cb01bc 33 float volt = (_pin.read())*3.3*(R_1 + R_2)/R_1;
hepta2ume 0:f74735cb01bc 34 float Rth = (volt-off)/gain+R3;
hepta2ume 0:f74735cb01bc 35 *temp = (Rth-Pt)/(ce*Pt);
HEPTA 2:de2e2a625a3b 36
HEPTA 2:de2e2a625a3b 37 // delay some time before reading again
hepta2ume 0:f74735cb01bc 38 wait(0.5);
hepta2ume 0:f74735cb01bc 39
hepta2ume 0:f74735cb01bc 40 }
hepta2ume 0:f74735cb01bc 41
HEPTA 3:96c3dd85be15 42 void HeptaTemp::temp_sense_u16(char* temp_u16)
hepta2ume 0:f74735cb01bc 43 {
hepta2ume 0:f74735cb01bc 44 unsigned short temp_datas;
hepta2ume 0:f74735cb01bc 45 char temp1[8]= {0x00},temp2[8]= {0x00};
hepta2ume 0:f74735cb01bc 46 temp_datas=_pin.read_u16()>>4;
hepta2ume 0:f74735cb01bc 47 sprintf( temp1, "%02X", (temp_datas >> 8) & 0x0F);
hepta2ume 0:f74735cb01bc 48 sprintf( temp2, "%02X", (temp_datas) & 0xFF);
hepta2ume 0:f74735cb01bc 49 temp_u16[0]=temp1[0];
hepta2ume 0:f74735cb01bc 50 temp_u16[1]=temp1[1];
hepta2ume 0:f74735cb01bc 51 temp_u16[2]=temp2[0];
hepta2ume 0:f74735cb01bc 52 temp_u16[3]=temp2[1];
HEPTA 3:96c3dd85be15 53 //*dsize = 4;
hepta2ume 1:a23c2cd65379 54 }
hepta2ume 1:a23c2cd65379 55
hepta2ume 1:a23c2cd65379 56 void HeptaTemp::temp_sensing_vol(float* voltage)
hepta2ume 1:a23c2cd65379 57 {
hepta2ume 1:a23c2cd65379 58 R_1 = 3;
hepta2ume 1:a23c2cd65379 59 R_2 = 2;
hepta2ume 1:a23c2cd65379 60 *voltage = (_pin.read())*3.3*(R_1 + R_2)/R_1;
hepta2ume 1:a23c2cd65379 61
hepta2ume 0:f74735cb01bc 62 }