计算式:PWM_Out=100-(75-50)/0.223=10;//50–>正常温度 75–当前温度 通过计算75°时,PWM调整为10%
/*热敏管理任务*/
xdata uint8_t CoefficientVaue = 100; //温度调节值%
HeatValue = AD_to_TEMP(Config_GMTemp_CH); //读取温度值
Temperture_Management(HeatValue, &CoefficientVaue); //温度管理
#include "GM_Temp.h"
#include "math.h"
xdata uint8_t CoefficientVaue = 100; //温度调节值%
xdata float Management_old = 0; //上次温度值
xdata float HeatValue = 30; //温度控制
/*********************************************
函数名:Temperture_Management
功 能:温度管理 根据对应温度控制PWM总体百分比
形 参:Management--当前温度 CoefficientVaue--温度调整值
返回值:
备 注:
作 者:薛建强
时 间:2019/06/06
**********************************************/
void Temperture_Management(const float Management, uint8_t *pCoefficientVaue)
{
static uint8_t tiaozheng = 0;
if (Management >= MAX_Temp_AD || Management <= RT_Temp_AD) //温度到80°极限了 || 热敏电阻开路
{
*pCoefficientVaue = 5; //占空比*0.05
Management_old = Management;
return;
}
if (Management <= Normal_Temp_AD) //<50°恢复正常
{
*pCoefficientVaue = 100;
Management_old = Management;
return;
}
else if (Management > High_Temp_AD) //>75°
{
*pCoefficientVaue = 10; //占空比*0.1
Management_old = Management;
}
else if (Management >= Median_Temp_AD) //判断是否达到50°
{
if (Management_old == 0) //第一次上电,温度过高
{
*pCoefficientVaue = 100 - (fabs(Management - Median_Temp_AD) / 0.223);
Management_old = Management;
return;
}
else if (Management_old != Management && fabs(Management - Management_old) >= 0.2)
{
tiaozheng = 1; //开始动态调节温度
}
}
/*动态调整温度 100-(75-50)/0.278*/
if (tiaozheng == 1)
{
if (Management <= High_Temp_AD && Management >= Normal_Temp_AD) //假设在50-75度之间
{
*pCoefficientVaue = 100 - (fabs(Management - Median_Temp_AD) / 0.223);
// printf("T-%2.2f° Co-%d old-%2.2f\n", HeatValue, (uint16_t)CoefficientVaue, Management_old);
Management_old = Management;
tiaozheng = 0;
}
}
}
#ifndef __TEMPGM_H
#define __TEMPGM_H
/* -----------------------------------------头文件-----------------------------------------*/
#include "main.h"
/* -----------------------------------------宏定义-----------------------------------------*/
// <o> 极限高温值(单位:℃)
#define MAX_Temp_AD 80
// <o> 高温临界值(单位:℃)
#define High_Temp_AD (75)
// <o> 高温中间值(单位:℃)触发值
#define Median_Temp_AD 55
// <o> 正常临界值(单位:℃)
#define Normal_Temp_AD 54
// <s.3> 热敏电阻开路值(单位:℃)
#define RT_Temp_AD atoi("-40")
/* -----------------------------------------结构体定义-------------------------------------*/
/* -----------------------------------------全局变量定义-----------------------------------*/
extern xdata uint8_t CoefficientVaue;
extern xdata float Management_old;
extern xdata float HeatValue;
/* -----------------------------------------应用程序---------------------------------------*/
void Temperture_Management(const float Management,uint8_t *pCoefficientVaue);
#endif