u8 err = 0,last_err = 0,err_add = 0,err_weifen = 0;
void Timer1Interrupt(void) interrupt 3
{
static u16 value1,cnt_10ms=0;
TH1 = 0x3C; //10ms
TL1 = 0xB0;
value1++;
cnt_10ms = 0;
if(tDisp < Set_Num) //实际温度较低 升温
{
err = (Set_Num - tDisp)/10.0; //误差
err_add += err; //累计误差
err_weifen = err - last_err; //误差变化率
last_err = err; //更新误差
PWM_SW = PID_P * err + PID_I * err_add + PID_D * err_weifen;
if(PWM_SW == 1)PWM_SW = 2;
Shengwen_IN1 = 1;
Shengwen_IN2 = 0;
Jiangwen_IN1 = 0;
Jiangwen_IN2 = 0;
PWM_JW = 0;
}
else if(tDisp > Set_Num) //实际温度较高 降温
{
err = (tDisp - Set_Num)/10.0; //误差
err_add += err; //累计误差
err_weifen = err - last_err; //误差变化率
last_err = err; //更新误差
PWM_JW = PID_P * err + PID_I * err_add + PID_D * err_weifen;
if(PWM_JW == 1)PWM_JW = 2;
Shengwen_IN1 = 0;
Shengwen_IN2 = 0;
Jiangwen_IN1 = 1;
Jiangwen_IN2 = 0;
PWM_SW = 0;
}
else
{
PWM_SW = 0;
PWM_JW = 0;
}
if(value1<PWM_SW)
{
ENSW = 1;
}
else
{
ENSW = 0;
}
if(value1<PWM_JW) //
{
ENJW = 1;
}
else
{
ENJW = 0;
}
if(value1>10)
{
value1 = 0;
}
}
|