For Hepta-Sat Lite
HeptaTemp.cpp@3:96c3dd85be15, 2017-09-05 (annotated)
- Committer:
- HEPTA
- Date:
- Tue Sep 05 12:47:05 2017 +0000
- Revision:
- 3:96c3dd85be15
- Parent:
- 2:de2e2a625a3b
- Child:
- 4:845cda80eaf0
- Child:
- 5:c15240318217
Hepta Temperature sensor;
Who changed what in which revision?
User | Revision | Line number | New 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; |
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 | } |