|
|
@@ -1,8 +1,8 @@
|
|
|
#define __TEMPCTRL_DEF
|
|
|
#include "ABIS_User.h"
|
|
|
-//float PWMKB[6]={1.47797,-8.96345,533.7256};
|
|
|
-//float PWMKB[6]={1.029277,63.010346,-1594.777178};
|
|
|
-//float PWMKB[3]={1.47797,-8.96345,1533.7256};
|
|
|
+
|
|
|
+#define TEMP_HOLD_TIME 30
|
|
|
+
|
|
|
unsigned char FallingTempCter;
|
|
|
unsigned TubeBlockMode;
|
|
|
void InitPWM(void)
|
|
|
@@ -197,167 +197,81 @@ void PeltierCtrler(void)
|
|
|
SetPWM (i,0);
|
|
|
continue;
|
|
|
}
|
|
|
- if(TempChn[i].cOverTempCnter){//
|
|
|
- TempPara[i].fErr=TempChn[i].fTubeTargetTemp - TempChn[i].fCurrentTemperature;
|
|
|
- TempChn[i].fHoldPWM = TempPara[i].HoldPWMa * TempChn[i].fTubeTargetTemp * TempChn[i].fTubeTargetTemp + TempPara[i].HoldPWMb * TempChn[i].fTubeTargetTemp + TempPara[i].HoldPWMc;
|
|
|
- }
|
|
|
- else{// block mode
|
|
|
- TempPara[i].fErr = TempChn[i].fBlockTargetTemp - TempChn[i].fCurrentTemperature;
|
|
|
- TempChn[i].fHoldPWM = TempPara[i].HoldPWMa * TempChn[i].fBlockTargetTemp * TempChn[i].fBlockTargetTemp + TempPara[i].HoldPWMb * TempChn[i].fBlockTargetTemp + TempPara[i].HoldPWMc;
|
|
|
- }
|
|
|
- if((TempChn[i].cCtrlMode !=1)&&(TempChn[i].cCtrlMode !=3)){
|
|
|
- if (fabs(TempPara[i].fErr) < 0.05) {
|
|
|
-// TempChn[i].cBlockTempAriv = 1;
|
|
|
- TempChn[i].FallingTempCter = 0;
|
|
|
- TempPara[i].fVlOutP = TempPara[i].iKp[2] * TempPara[i].fErr;
|
|
|
- TempPara[i].fSum += TempPara[i].fErr;
|
|
|
- TempPara[i].fVlSum = TempPara[i].iKi[2] * TempPara[i].fSum;
|
|
|
- TempPara[i].fVlOut = TempPara[i].iKd[2]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
- TempPara[i].fVlOutP += TempPara[i].fVlOut + TempPara[i].fVlSum;
|
|
|
- } else if (fabs(TempPara[i].fErr) < 0.1) {
|
|
|
-// TempChn[i].cBlockTempAriv = 1;
|
|
|
- TempChn[i].FallingTempCter = 0;
|
|
|
- TempPara[i].fVlOutP = TempPara[i].iKp[2] * TempPara[i].fErr;
|
|
|
- TempPara[i].fSum += TempPara[i].fErr;
|
|
|
- TempPara[i].fVlSum = TempPara[i].iKi[2] * TempPara[i].fSum;
|
|
|
- TempPara[i].fVlOut = TempPara[i].iKd[2]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
- TempPara[i].fVlOutP += TempPara[i].fVlOut + TempPara[i].fVlSum;
|
|
|
- } else if (fabs(TempPara[i].fErr) < 0.5) {
|
|
|
-// TempChn[i].cBlockTempAriv = 1;
|
|
|
- TempChn[i].FallingTempCter = 0;
|
|
|
- TempPara[i].fVlOutP = TempPara[i].iKp[2] * TempPara[i].fErr;
|
|
|
+ switch(TempChn[i].pidst){
|
|
|
+ case PID_OVERHEAT:{
|
|
|
+ /*采用第一路PID配置*/
|
|
|
+ TempPara[i].fErrLast = TempPara[i].fErr;
|
|
|
+ TempPara[i].fErr=TempChn[i].fTubeTargetTemp - TempChn[i].fCurrentTemperature;
|
|
|
+ TempPara[i].fVlOutP = TempPara[i].iKp[1] * TempPara[i].fErr;
|
|
|
TempPara[i].fSum += TempPara[i].fErr;
|
|
|
- TempPara[i].fVlSum = TempPara[i].iKi[2] * TempPara[i].fSum;
|
|
|
- TempPara[i].fVlOut = TempPara[i].iKd[2]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
+ TempPara[i].fVlSum = TempPara[i].iKi[1] * TempPara[i].fSum;
|
|
|
+ TempPara[i].fVlOut = TempPara[i].iKd[1]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
TempPara[i].fVlOutP += TempPara[i].fVlOut + TempPara[i].fVlSum;
|
|
|
- } else if (fabs(TempPara[i].fErr) < 1) {
|
|
|
-// TempChn[i].cBlockTempAriv = 1;
|
|
|
- TempChn[i].FallingTempCter = 0;
|
|
|
+ if(TempChn[i].cHeatOrRefrig == 1){
|
|
|
+ if(TempChn[i].fCurrentTemperature >(TempChn[i].fTubeTargetTemp + TempChn[i].OverTempthreshold)){
|
|
|
+ TempChn[i].pidst= PID_OVERHEATLAST;
|
|
|
+ TempChn[i].pidRumtime = 0;
|
|
|
+ TempChn[i].cHeatOrRefrig = 2;
|
|
|
+ Van_Device_Printf(2," ch%d go to st:%d cur:%f,at:%f + :%f\n\r",i,TempChn[i].pidst,TempChn[i].fCurrentTemperature,
|
|
|
+ TempChn[i].fTubeTargetTemp,TempChn[i].OverTempthreshold);
|
|
|
+ }
|
|
|
+ }else if(TempChn[i].cHeatOrRefrig == 0){
|
|
|
+ if(TempChn[i].fCurrentTemperature <(TempChn[i].fTubeTargetTemp + TempChn[i].OverTempCoolthreshold)){
|
|
|
+ TempChn[i].pidst= PID_OVERHEATLAST;
|
|
|
+ TempChn[i].pidRumtime = 0;
|
|
|
+ TempChn[i].cHeatOrRefrig = 2;
|
|
|
+ Van_Device_Printf(2," ch%d go to st:%d cur:%f,at:%f + :%f \n\r",i,TempChn[i].pidst,TempChn[i].fCurrentTemperature,
|
|
|
+ TempChn[i].fTubeTargetTemp,TempChn[i].OverTempCoolthreshold);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }break;
|
|
|
+ case PID_OVERHEATLAST:{
|
|
|
+ /*过充维持阶段,加热功率不变*/
|
|
|
+ TempChn[i].pidRumtime++;
|
|
|
+ if(TempChn[i].pidRumtime>= TempChn[i].timer0){
|
|
|
+ TempChn[i].pidst= PID_NORMAL;
|
|
|
+ /*维持功率不变,*/
|
|
|
+ TempPara[i].fSum += (TempChn[i].fCurrentTemperature - TempChn[i].fBlockTargetTemp)*TempPara[i].iKp[1]/TempPara[i].iKi[1];
|
|
|
+ Van_Device_Printf(2," ch%d go to st:%d cur:%f,time:%d \n\r",i,TempChn[i].pidst,TempChn[i].fCurrentTemperature,TempChn[i].pidRumtime);
|
|
|
+ TempChn[i].pidRumtime = 0;
|
|
|
+ TempChn[i].fistAriv = 0;
|
|
|
+ }
|
|
|
+ }break;
|
|
|
+ case PID_NORMAL:{
|
|
|
+ /*采用第一路PID配置*/
|
|
|
+ TempPara[i].fErrLast = TempPara[i].fErr;
|
|
|
+ TempPara[i].fErr=TempChn[i].fBlockTargetTemp - TempChn[i].fCurrentTemperature;
|
|
|
TempPara[i].fVlOutP = TempPara[i].iKp[1] * TempPara[i].fErr;
|
|
|
- TempPara[i].fSum += TempPara[i].fErr;
|
|
|
- TempPara[i].fVlSum = TempPara[i].iKi[1] * TempPara[i].fSum;
|
|
|
- TempPara[i].fVlOut = TempPara[i].iKd[1]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
- TempPara[i].fVlOutP += TempPara[i].fVlOut + TempPara[i].fVlSum;
|
|
|
- } else if (fabs(TempPara[i].fErr) <= MODEMRANGE) {
|
|
|
-// TempChn[i].cBlockTempAriv = 1;
|
|
|
- TempChn[i].FallingTempCter = 0;
|
|
|
- TempPara[i].fVlOutP = TempPara[i].iKp[0] * TempPara[i].fErr;
|
|
|
TempPara[i].fSum += TempPara[i].fErr;
|
|
|
- TempPara[i].fVlSum = TempPara[i].iKi[0] * TempPara[i].fSum;
|
|
|
- TempPara[i].fVlOut = TempPara[i].iKd[0]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
- TempPara[i].fVlOutP += TempPara[i].fVlOut + TempPara[i].fVlSum;
|
|
|
- }
|
|
|
- else {
|
|
|
- TempPara[i].fSum = 0;
|
|
|
- if ((TempPara[i].fErr > MODEMRANGE)){
|
|
|
- TempPara[i].fVlOutP = 100000;
|
|
|
- }
|
|
|
- else if ((TempPara[i].fErr < -MODEMRANGE)){
|
|
|
- TempPara[i].fVlOutP = -100000;
|
|
|
- }
|
|
|
- }
|
|
|
- TempPara[i].fDerr=TempPara[i].fErr - TempPara[i].fErrLast;
|
|
|
-
|
|
|
-// TempChn[i].fHoldPWM = 0;
|
|
|
-// TempPara[i].fVlOutP += TempChn[i].fHoldPWM;
|
|
|
-// TempPara[i].fErrLast = TempPara[i].fErr;
|
|
|
-//
|
|
|
-// if(TempPara[i].fVlOutP > TempChn[i].MAXPWM){
|
|
|
-// TempPara[i].fVlOutP = TempChn[i].MAXPWM;
|
|
|
-// }
|
|
|
-// else if(TempPara[i].fVlOutP < -TempChn[i].MAXPWM){
|
|
|
-// TempPara[i].fVlOutP = -TempChn[i].MAXPWM;
|
|
|
-// }
|
|
|
-
|
|
|
- if((TempChn[i].cOverTempCnter == 0)&&(TempChn[i].cHeatOrRefrig == 0)&&(g_uiOverTempCnter[i] <= g_tEE.uiOverTempCnter)){
|
|
|
- TempPara[i].fVlOutP = TempChn[i].fHoldPWM;
|
|
|
- TempPara[i].fErrLast = TempPara[i].fErr;
|
|
|
- g_uiOverTempCnter[i]++;
|
|
|
- }else{
|
|
|
- TempPara[i].fVlOutP += TempChn[i].fHoldPWM;
|
|
|
- TempPara[i].fErrLast = TempPara[i].fErr;
|
|
|
- }
|
|
|
-
|
|
|
- if(TempChn[i].cHeatOrRefrig == 1){
|
|
|
- if(TempChn[i].fBlockTargetTemp < TempChn[i].fCurrentTemperature){
|
|
|
- TempChn[i].cBlockTempAriv = 1;
|
|
|
- }
|
|
|
- }else if(TempChn[i].cHeatOrRefrig == 0){
|
|
|
- if(TempChn[i].fBlockTargetTemp > TempChn[i].fCurrentTemperature){
|
|
|
- TempChn[i].cBlockTempAriv = 1;
|
|
|
- }
|
|
|
- }else if(TempChn[i].cHeatOrRefrig == 2){
|
|
|
- TempChn[i].cBlockTempAriv = 1;
|
|
|
- }else{
|
|
|
- }
|
|
|
-
|
|
|
- if(TempPara[i].fVlOutP > TempChn[i].MAXPWM){
|
|
|
+ TempPara[i].fVlSum = TempPara[i].iKi[1] * TempPara[i].fSum;
|
|
|
+ TempPara[i].fVlOut = TempPara[i].iKd[1]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
+ TempPara[i].fVlOutP += TempPara[i].fVlOut + TempPara[i].fVlSum;
|
|
|
+ if(((TempChn[i].fBlockTargetTemp - 0.5)<TempChn[i].fCurrentTemperature)&&((TempChn[i].fBlockTargetTemp + 0.5)>TempChn[i].fCurrentTemperature)){
|
|
|
+ TempChn[i].pidRumtime++;
|
|
|
+ }else{
|
|
|
+ TempChn[i].pidRumtime = 0;
|
|
|
+ }
|
|
|
+ if(TempChn[i].pidRumtime > TEMP_HOLD_TIME){
|
|
|
+ TempChn[i].cTubeTempAriv = 1;
|
|
|
+ if(TempChn[i].fistAriv == 0){
|
|
|
+ Van_Device_Printf(2," ch%d go to st:%d cur:%f,time:%d\n\r",i,TempChn[i].pidst,TempChn[i].fCurrentTemperature,TempChn[i].pidRumtime);
|
|
|
+ TempChn[i].fistAriv = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }break;
|
|
|
+ default:
|
|
|
+ TempChn[i].pidst = PID_IDL;
|
|
|
+ TempPara[i].fVlOutP = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(TempPara[i].fVlOutP > TempChn[i].MAXPWM){
|
|
|
TempPara[i].fVlOutP = TempChn[i].MAXPWM;
|
|
|
}
|
|
|
else if(TempPara[i].fVlOutP < -TempChn[i].MAXPWM){
|
|
|
TempPara[i].fVlOutP = -TempChn[i].MAXPWM;
|
|
|
}
|
|
|
-
|
|
|
- if(TempPara[i].fVlOutP >=TempChn[i].MAXPWM){
|
|
|
- TempPara[i].fVlOutR +=4000;
|
|
|
- }
|
|
|
- else if(TempPara[i].fVlOutP <= -TempChn[i].MAXPWM){
|
|
|
- TempPara[i].fVlOutR -=4000;
|
|
|
- }
|
|
|
- if((TempPara[i].fVlOutR < 0)&&(TempPara[i].fVlOutP > 0)){
|
|
|
- TempPara[i].fVlOutR =0;
|
|
|
- }
|
|
|
- else {
|
|
|
- TempPara[i].fVlOutR =TempPara[i].fVlOutP;
|
|
|
- }
|
|
|
- if(TempPara[i].fVlOutR > TempChn[i].MAXPWM){
|
|
|
- TempPara[i].fVlOutR = TempChn[i].MAXPWM;
|
|
|
- }
|
|
|
- else if(TempPara[i].fVlOutR < -TempChn[i].MAXPWM){
|
|
|
- TempPara[i].fVlOutR = -TempChn[i].MAXPWM;
|
|
|
- }
|
|
|
-
|
|
|
- SetPWM (i,TempPara[i].fVlOutR);
|
|
|
- if(TempPara[i].fVlOutR > 0){
|
|
|
- g_uiGetPWM[i] = (unsigned int)TempPara[i].fVlOutR;
|
|
|
- }else{
|
|
|
- g_uiGetPWM[i] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(TempChn[i].cCtrlMode ==1){
|
|
|
- }
|
|
|
- else if(TempChn[i].cCtrlMode ==3){
|
|
|
- }
|
|
|
-
|
|
|
- if(TempChn[i].fCurrentTemperature > 120.0) {
|
|
|
- TempChn[i].PeltierOvertempCnter++;
|
|
|
- if(TempChn[i].PeltierOvertempCnter >= 10){
|
|
|
- SetPWM (i,0);
|
|
|
- }
|
|
|
- }
|
|
|
- else if(TempChn[i].fCurrentTemperature < -1){
|
|
|
- TempChn[i].PeltierOvertempCnter++;
|
|
|
- if(TempChn[i].PeltierOvertempCnter >= 10){
|
|
|
- SetPWM (i,0);
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- TempChn[i].PeltierOvertempCnter=0;
|
|
|
- }
|
|
|
-
|
|
|
- TempChn[i].TimerForPeltier++;
|
|
|
- if(TempChn[i].TimerForPeltier >= TempChn[i].timer0 ){
|
|
|
- TempChn[i].TimerForPeltier = 0;
|
|
|
- if(FallingTempCter!=0) FallingTempCter--;
|
|
|
- if((TempChn[i].cPeltierRun != 0)&&(TempChn[i].cCtrlMode !=1)){
|
|
|
- if(TempChn[i].cBlockTempAriv && TempChn[i].cOverTempCnter){
|
|
|
- TempChn[i].cOverTempCnter--;
|
|
|
- }
|
|
|
- if(!TempChn[i].cOverTempCnter && !TempChn[i].cTubeTempAriv){
|
|
|
- TempChn[i].cTubeTempAriv = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ SetPWM (i,TempPara[i].fVlOutP);
|
|
|
+ Van_Device_Printf(2,"ch%d: %3f %3f\n\r",i,TempChn[i].fCurrentTemperature,TempPara[i].fVlOutP);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -390,19 +304,25 @@ unsigned char ScheduleOperate(unsigned char chn)
|
|
|
{
|
|
|
TempChn[chn].cHeatOrRefrig = 1;
|
|
|
TempChn[chn].fTubeTargetTemp = TempChn[chn].fBlockTargetTemp + TempChn[chn].HOTtemp;
|
|
|
+ TempChn[chn].pidst = PID_OVERHEAT;
|
|
|
+ Van_Device_Printf(2,"\n\rch%d go to st:%d H T:%f O:%f A%f C:%d\n\r",chn,TempChn[chn].pidst,
|
|
|
+ TempChn[chn].fBlockTargetTemp,TempChn[chn].fTubeTargetTemp,TempChn[chn].HOTtemp,TempChn[chn].cOverTempCnter);
|
|
|
}
|
|
|
|
|
|
- else if(TempChn[chn].fBlockTargetTemp < TempChn[chn].fCurrentTemperature - TempChn[chn].CODEtemp)
|
|
|
+ else if(TempChn[chn].fBlockTargetTemp < TempChn[chn].fCurrentTemperature + TempChn[chn].CODEtemp)
|
|
|
{
|
|
|
TempChn[chn].cHeatOrRefrig = 0;
|
|
|
- TempChn[chn].fTubeTargetTemp = TempChn[chn].fBlockTargetTemp - TempChn[chn].CODEtemp;
|
|
|
+ TempChn[chn].fTubeTargetTemp = TempChn[chn].fBlockTargetTemp + TempChn[chn].CODEtemp;
|
|
|
+ TempChn[chn].pidst = PID_OVERHEAT;
|
|
|
+ Van_Device_Printf(2,"go to st:%d H T:%f O:%f A%f C:%d\n\r",TempChn[chn].pidst,
|
|
|
+ TempChn[chn].fBlockTargetTemp,TempChn[chn].fTubeTargetTemp,TempChn[chn].CODEtemp,TempChn[chn].cOverTempCnter);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- TempChn[chn].cHeatOrRefrig = 2;
|
|
|
-// TempChn[chn].cBlockTempAriv = 1;
|
|
|
-// Run.TubeAriv = 1;
|
|
|
+ TempChn[chn].cHeatOrRefrig = 2;
|
|
|
+ Van_Device_Printf(2,"heat ch%d with over:goal:%f\n\r",chn,TempChn[chn].fBlockTargetTemp);
|
|
|
TempChn[chn].fTubeTargetTemp = TempChn[chn].fBlockTargetTemp;
|
|
|
+ TempChn[chn].pidst = PID_NORMAL;
|
|
|
|
|
|
if(fabs(TempChn[chn].fBlockTargetTemp - TempChn[chn].fCurrentTemperature) < 2)
|
|
|
TempChn[chn].cOverTempCnter = 1;//5
|
|
|
@@ -423,6 +343,8 @@ unsigned char ScheduleOperate(unsigned char chn)
|
|
|
TempChn[chn].cHeatOrRefrig = 0;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ Van_Device_Printf(2,"heat with over:goal:%f overtime:%d\n\r",TempChn[chn].fBlockTargetTemp,TempChn[chn].cOverTempCnter);
|
|
|
}
|
|
|
return 0;
|
|
|
}
|