|
|
@@ -49,10 +49,11 @@ void InitPWM(void)
|
|
|
/*******************************************************************************
|
|
|
* 函数名称:SetPWM
|
|
|
*******************************************************************************/
|
|
|
-void SetPWM(unsigned char ucChannel , long uiDuty)
|
|
|
+void SetPWM(unsigned char ucChannel , float pwmvalue)
|
|
|
{
|
|
|
- if(uiDuty > 0){
|
|
|
- uiDuty =(long)((float)uiDuty * TempPara[ucChannel].fPowerCoef) ;
|
|
|
+ long uiDuty;
|
|
|
+ if(pwmvalue > 0){
|
|
|
+ uiDuty =(long)(pwmvalue * TempPara[ucChannel].fPowerCoef) ;
|
|
|
switch(ucChannel){
|
|
|
case 0:
|
|
|
PDC1 = uiDuty;
|
|
|
@@ -83,37 +84,7 @@ void SetPWM(unsigned char ucChannel , long uiDuty)
|
|
|
|
|
|
}
|
|
|
}else{
|
|
|
- if((TempChn[ucChannel].cOverTempCnter == 0)&&(TempChn[ucChannel].cHeatOrRefrig == 1)){
|
|
|
- switch(ucChannel){
|
|
|
- case 0:
|
|
|
- SDC1 = 0;
|
|
|
- PDC1 = 0;
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- SDC2 = 0;
|
|
|
- PDC2 = 0;//加热
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- SDC3 = 0;
|
|
|
- PDC3 = 0;//加热
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- SDC4 = 0;
|
|
|
- PDC4 = 0;//加热
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- SDC5 = 0;
|
|
|
- PDC5 = 0;//加热
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- SDC6 = 0;
|
|
|
- PDC6 = 0;//加热
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }else{
|
|
|
- uiDuty =(long)((float)uiDuty * TempPara[ucChannel].fPowerCoefdown) ;
|
|
|
+ uiDuty =(long)(pwmvalue * TempPara[ucChannel].fPowerCoefdown) ;
|
|
|
switch(ucChannel){
|
|
|
case 0:
|
|
|
SDC1 = -uiDuty;
|
|
|
@@ -143,7 +114,6 @@ void SetPWM(unsigned char ucChannel , long uiDuty)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -190,6 +160,9 @@ void CAPPeltierCtrler(void){
|
|
|
void PeltierCtrler(void)
|
|
|
{
|
|
|
unsigned char i;
|
|
|
+ float tempOutP;
|
|
|
+ float errOutP;
|
|
|
+ float divOutP;
|
|
|
for(i=0;i<6;i++)
|
|
|
{
|
|
|
|
|
|
@@ -202,11 +175,13 @@ void PeltierCtrler(void)
|
|
|
/*采用第一路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].fVlOut = TempPara[i].iKp[1] * TempPara[i].fErr;
|
|
|
+ if(abs(TempPara[i].fVlOutP) < 100){
|
|
|
+ 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;
|
|
|
+ divOutP = TempPara[i].iKd[1]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
+ TempPara[i].fVlOutP = TempPara[i].fVlOut + TempPara[i].fVlSum + divOutP;
|
|
|
if(TempChn[i].cHeatOrRefrig == 1){
|
|
|
if(TempChn[i].fCurrentTemperature >(TempChn[i].fTubeTargetTemp + TempChn[i].OverTempthreshold)){
|
|
|
TempChn[i].pidst= PID_OVERHEATLAST;
|
|
|
@@ -231,7 +206,8 @@ void PeltierCtrler(void)
|
|
|
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];
|
|
|
+ TempPara[i].fSum = (TempChn[i].fCurrentTemperature - TempChn[i].fBlockTargetTemp)*TempPara[i].iKp[1]/TempPara[i].iKi[1];
|
|
|
+ TempPara[i].fSum += TempPara[i].fVlOutP/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;
|
|
|
@@ -241,11 +217,13 @@ void PeltierCtrler(void)
|
|
|
/*采用第一路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].fVlOut = TempPara[i].iKp[1] * TempPara[i].fErr;
|
|
|
+// if(abs(TempPara[i].fVlOutP) < 100){
|
|
|
+// }
|
|
|
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;
|
|
|
+ divOutP = TempPara[i].iKd[1]*(TempPara[i].fErr - TempPara[i].fErrLast);
|
|
|
+ TempPara[i].fVlOutP = TempPara[i].fVlOut + TempPara[i].fVlSum + divOutP;
|
|
|
if(((TempChn[i].fBlockTargetTemp - 0.5)<TempChn[i].fCurrentTemperature)&&((TempChn[i].fBlockTargetTemp + 0.5)>TempChn[i].fCurrentTemperature)){
|
|
|
TempChn[i].pidRumtime++;
|
|
|
}else{
|
|
|
@@ -265,13 +243,15 @@ void PeltierCtrler(void)
|
|
|
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;
|
|
|
- }
|
|
|
- SetPWM (i,TempPara[i].fVlOutP);
|
|
|
- Van_Device_Printf(2,"ch%d: %3f %3f\n\r",i,TempChn[i].fCurrentTemperature,TempPara[i].fVlOutP);
|
|
|
+ TempPara[i].fVlOutP = TempChn[i].MAXPWM;
|
|
|
+ }
|
|
|
+ else if(TempPara[i].fVlOutP < -TempChn[i].MAXPWM){
|
|
|
+ TempPara[i].fVlOutP = -TempChn[i].MAXPWM;
|
|
|
+ }
|
|
|
+ SetPWM (i,TempPara[i].fVlOutP);
|
|
|
+// if(i==2){
|
|
|
+// Van_Device_Printf(2,"ch%d: %3f %3f=%3f+%3f+%3f\n\r",i,TempChn[i].fCurrentTemperature,TempPara[i].fVlOutP, TempPara[i].fVlOut,TempPara[i].fVlSum,divOutP);
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -305,8 +285,8 @@ 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);
|
|
|
+ Van_Device_Printf(2,"\n\rch%d go to st:%d H T:%f O:%f A%f C:%d %f\n\r",chn,TempChn[chn].pidst,
|
|
|
+ TempChn[chn].fBlockTargetTemp,TempChn[chn].fTubeTargetTemp,TempChn[chn].HOTtemp,TempChn[chn].cOverTempCnter,TempChn[chn].OverTempthreshold);
|
|
|
}
|
|
|
|
|
|
else if(TempChn[chn].fBlockTargetTemp < TempChn[chn].fCurrentTemperature + TempChn[chn].CODEtemp)
|
|
|
@@ -314,8 +294,8 @@ unsigned char ScheduleOperate(unsigned char chn)
|
|
|
TempChn[chn].cHeatOrRefrig = 0;
|
|
|
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);
|
|
|
+ Van_Device_Printf(2,"go to st:%d C T:%f O:%f A%f C:%d %f\n\r",TempChn[chn].pidst,
|
|
|
+ TempChn[chn].fBlockTargetTemp,TempChn[chn].fTubeTargetTemp,TempChn[chn].CODEtemp,TempChn[chn].cOverTempCnter,TempChn[chn].OverTempCoolthreshold);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -387,9 +367,9 @@ void InitTempCtlr(){
|
|
|
}
|
|
|
|
|
|
for(i=0;i<6;i++){
|
|
|
- TempPara[i].iKp[0]=TempPara[i].iKp[1]=TempPara[i].iKp[2]=5000;
|
|
|
- TempPara[i].iKi[0]=TempPara[i].iKi[1]=TempPara[i].iKi[2]=20;
|
|
|
- TempPara[i].iKd[0]=TempPara[i].iKd[1]=TempPara[i].iKd[2]=8000;
|
|
|
+ TempPara[i].iKp[0]=TempPara[i].iKp[1]=TempPara[i].iKp[2]=12.5;
|
|
|
+ TempPara[i].iKi[0]=TempPara[i].iKi[1]=TempPara[i].iKi[2]=0.05;
|
|
|
+ TempPara[i].iKd[0]=TempPara[i].iKd[1]=TempPara[i].iKd[2]=0;
|
|
|
|
|
|
TempPara[i].HoldPWMa = 0.9197;
|
|
|
TempPara[i].HoldPWMb = 60.465;
|