- #include "definitions.h" // SYS function prototypes
- #include "temperature.h"
- #include "sapmle_pow.h"
- static float f_int1_h; // 基准电压
- static float f_int1_r;
- static float f_temp_h; // 高温
- static float f_temp_r; // 室温
- static uint16_t u16_adc_h; // 校准过的ADC值
- static uint16_t u16_adc_r; // 校准过的ADC值
- void Device_Temp_Init(void) {
- // 基准电压换算
- f_int1_h = ((int8_t) HOT_TEMP_VAL_INT) * 0.001 + 1;
- f_int1_r = ((int8_t) ROOM_INT1V_VAL) * 0.001 + 1;
- // 温度换算
- f_temp_h = HOT_TEMP_VAL_INT + HOT_TEMP_VAL_DEC * 0.1;
- f_temp_r = ROOM_TEMP_VAL_INT + ROOM_TEMP_VAL_DEC * 0.1;
- // 校准ADC值
- u16_adc_h = HOT_ADC_VAL * f_int1_h + 0.5;
- u16_adc_r = ROOM_ADC_VAL * f_int1_r + 0.5;
- }
- int8_t Get_Device_Temp(void) {
- float f_temp_c; // 粗略温度值
- float f_temp_f; // 实际温度值
- float f_int1_m; // 基准电压
- uint16_t u16_adc_m;
-
- u16_adc_m = Get_ADC_Val(ADC_TEMP_CH) * 3.3; // 基准使用 3.3 V 所以放大3.3倍
- f_temp_c = f_temp_r + ((u16_adc_m - u16_adc_r)*(f_temp_h - f_temp_r) / (u16_adc_h - u16_adc_r)); // 温度粗值计算
- f_int1_m = f_int1_r + ((f_int1_h - f_int1_r)*(f_temp_c - f_temp_r) / (f_temp_h - f_temp_r)); // 基准电压计算
- u16_adc_m = u16_adc_m * f_int1_m + 0.5;
- f_temp_f = f_temp_r + ((u16_adc_m - u16_adc_r)*(f_temp_h - f_temp_r) / (u16_adc_h - u16_adc_r));
- return (int8_t) f_temp_f;
- }
|