from: https://eroro.tistory.com/591
NTC의 특성 값이나 회로 부분은 변경하여 사용하여야 합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#define REF_RESIST 10000 #define VREF 3.3f /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : 3.3 : 4096 = x : ADC Vout= (x/(x+10000)) * 3.3 *******************************************************************************/ float Calculation_Vout(u16 a_nhADCValue, u8 a_chComp) { float Vout, Resistor; a_nhADCValue += a_chComp; Vout = (a_nhADCValue * VREF); Vout /= 4095; // DEBUGPRINT("ADC Vout %f, ", Vout); Resistor = Vout *(REF_RESIST/(VREF-Vout)); // DEBUGPRINT("Resistor %f\r\n", Resistor); return Resistor; } #define REF_LDTEMP_BETA 3477 #define REF_LDTEMP_BETA_REVERSE 0.000288 //1/REF_LDTEMP_BETA #define REF_LDTEMP_25 298.15f #define REF_LDTEMP_K 273.15f #define REF_LDTEMP_UPPERRESIS 10000 /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None 0 Degree Resistor = 10000*exp((REF_LDTEMP_BETA*((1/REF_LDTEMP_K)-(1/REF_LDTEMP_25)))); Resistor = 290776.77 Ohm *******************************************************************************/ u16 ADC_LDTemperature_Calc(u16 ADC_Batt, u8 ADC_Compensation) { float Resistor, Celsius; Resistor = Calculation_Vout(ADC_Batt, 0); Celsius = (REF_LDTEMP_BETA_REVERSE*log(Resistor/REF_LDTEMP_UPPERRESIS)); // DEBUGPRINT("Celsius %f\r\n", Celsius); Celsius += (1/REF_LDTEMP_25); // DEBUGPRINT("Celsius %f\r\n", Celsius); Celsius = pow(Celsius, -1); // DEBUGPRINT("Celsius %f\r\n", Celsius); Celsius -= 273.15f; // DEBUGPRINT("Celsius %f\r\n", Celsius); if(Celsius < 0) Celsius = 0; return (u16)Celsius; } |