/********************************************************************************************************* * Module : Temprature.c * Abstract : Temprature module * Version : 1.0.0 * Author : Leopul(COPYRIGHT 2025 - 2027 Leopul. All rights reserved.) * Complete : 2025-02-16 * Content : None * Note : None *********************************************************************************************************/ #include "Temprature.h" #include "Adc.h" #include "main.h" #include "math.h" /**************************************************************** * * NXFT15XH103 * * T(K) = (662.666 -45.389*ln(R)+0.069*(ln(R))^3) * T(C) = T(K) - 273.15 * *****************************************************************/ static float get_temp(void); #define GATHER_MAX 200 #define VREF 33 #define V_HOT(ad) (((ad * 1000)>>12) * VREF / 10.0 /1000.0) #define R_HOT(ad) ((V_HOT(ad)*10000.0) / ((VREF/10.0)-(2.0*V_HOT(ad)))) #define T_TEMP(res) ((662.666 - (45.389 * log10(res)) + (0.069 * log10(res)*log10(res)*log10(res))) - 273.15) static uint32_t gather_count = 0; static uint32_t all_get_ad = 0; static float get_temp(void) { sts_data_t *data = get_sts(); uint32_t all_get_ad = 0; float temprature = 0.0; if(gather_count < GATHER_MAX) { all_get_ad += get_adc(); gather_count++; }else { all_get_ad /= GATHER_MAX; float v_hot = V_HOT(all_get_ad); if((uint32_t)((v_hot)*100) < 165) { float res = ((v_hot)*10000) / (3.3 - 2 * v_hot); if(res>=598 && res <= 197000) { temprature = T_TEMP(res); data->temp_online_flag = TEMP_ONLINE; }else { data->temp_online_flag = TEMP_INLINE; } }else { temprature = 0.0; data->temp_online_flag = TEMP_INLINE; } gather_count = 0; all_get_ad = 0; } data->temprature = temprature; return temprature; } void temp_init(void) { adc_init(); sts_data_t *data = get_sts(); data->read_temp = get_temp; }