📄 main.c
字号:
ACT_CMPCNT; //Switch on compressor contactor
stepCtrl=sysStartWait; //Set stepctrl for next step
cntSysTimer=0; //Initiate step control timer
EnableStepWait; //trig the Waiting Timer
}
/**********************************************************/
void StartupWaitDrain(void)
{
if(cntSysTimer>4)
{
DisableStepWait; //Stop waiting timer
stepCtrl=sysWaitReady; //Set stepctrl for check startup ready
SPIDAInit(); //Initiate SPIDA CHIP
flgDAINI=1;
Ncp=IniValNcp; //Note if the compressor changed the initial value will also change
cntSysTimer=0; //Reset step contol waiting timer
EnableStepWait; //trig the Waiting Timer
STP_DRAIN_HYDROGEN; //Stop drain hydrogen
perHVTimer=iniPerHVTimer; //Set auto drain hydrogen period to be initial value
EnableHDrain; //Enable automatic drain hydrogen
}
}
/**********************************************************/
void StartupCheckReady(void)
{
if(ReayCondOK)
{
stepCtrl =sysReday; //Set stepctrl to note system being ready
PLmt =IniPLmt; //Set system output ability to be initial limiting value
ACT_STCNT; //Switch on stack contactor
SysStatus =ECU_Enabled; //Set basic status used for VSM to inform vehicle FCE aviliable
stepCtrl =sysRunning; //Set stepctrl to note system being ready
}
}
/**********************************************************/
void StopEnable(void)
{
SysSetStop; //Set system status symbol
SysStateUpdate; //Update system status flags
DisableHDrain; //Stop automatic hydrogen drain
PLmt=0; //Limit Power output to zero
stepCtrl=sysStopDrain; //Set step control flag to be stop drainning
STP_STCNT; //Switch off stack contactor
ACT_SUPPLY_HYDROGEN; //Open hydrogen supply valve to begin purge
ACT_DRAIN_HYDROGEN; //Open hydrogen supply valve to begin drain
Ncp=0; //Low down compressor rotation
cntSysTimer=0; //Reset step control timer
EnableStepWait; //trig the Waiting Timer
}
/**********************************************************/
void StopWaitDrain(void)
{
if(cntSysTimer>4) //When stop drain has last for more than 2s
{
DisableStepWait; //Stop step control timer
STP_CMPCNT; //Switch off compressor contactor
STP_SUPPLY_HYDROGEN; //Stop hydrogen supply
STP_CWP; //Stop coolant pump
STP_FAN1; //Stop FAN1
STP_FAN2; //Stop FAN2
STP_DRAIN_WATER; //动力12V断电
stepCtrl=sysStoping; //Set step control flag to be sysStoping for next step
cntSysTimer=0; //Reset step control timer
EnableStepWait; //trig the Waiting Timer
}
}
/**********************************************************/
void StopWaitReady(void)
{
if((cntSysTimer>8)||(StopCondOK))
{
STP_DRAIN_HYDROGEN; //Stop hydrogen drain
stepCtrl=sysECUReady; //Reset step control flag to be idle
SysSetStop; //Reset system action status to be ECU ready
SysStateUpdate; //Update system status
SysStatus=ECU_Ready; //Reset system status to be ECU ready
cntSysTimer=0; //Reset step control timer
DisableStepWait; //Stop step control timer
STP_DRAIN_WATER; //动力12V断电
DriverDisable; //Inhibit system action
modeCtrl=ModeIdle; //Set control mode to be idle
}
}
void SysEmgEnable(void)
{
/************If system go into emgency mode dynamically respond it***/
/*disconnect contactor and close hydrogen valve*/
/*close all the other devices*/
SysSetStop;
SysStateUpdate;
PLmt=0;
STP_STCNT;
DisableHDrain;
STP_SUPPLY_HYDROGEN; //Stop hydrogen supply
STP_DRAIN_HYDROGEN; //Stop hydrogen DRAIN
STP_CMPCNT; //Switch off compressor contactor
STP_CWP; //Stop coolant pump
STP_FAN1; //Stop FAN1
STP_FAN2; //Stop FAN2
STP_DRAIN_WATER; //动力12V断电
Ncp=0;
DriverDisable;
SysStatus =ECU_Ready;
stepCtrl =sysECUReady;
}
void SysBeingEmg(void)
{
/*static condition verify actuators*/
SysSetStop;
SysStateUpdate;
STP_DRAIN_WATER; //动力12V断电
DriverDisable;
stepCtrl =sysECUReady;
SysStatus =ECU_Ready;
}
void SysRunningCtrl(void)
{
/**********************************************************/
if((SysPsetChange==1))
{
if(Pset>6000)Pset=6000; //limit the net output less than 7000
PLmtTarget=PsetToPlmt[Pset/200]; //Search the Plmt target according the table
TC4=TC4+0X7A12; //delay 500ms for Plmt Increase
EnablePlmtCtrl; //Enable auto increase Plmt
SysPsetChange=0; //Reset new setting flag
}
/* Calculate the Ncp from set table provided by xulin*/
/* if(Pset<840) Ncp=(unsigned char)(Pset*3/100); //0.5V
else if(Pset<2700)Ncp=(unsigned char)(25+(Pset-840)/93); //0.9V
else if(Pset<4600)Ncp=(unsigned char)(45+(Pset-2700)/95); //1.3V
else if(Pset<5300)Ncp=(unsigned char)(65+(Pset-4600)/70); //1.3V
else Ncp=75;
if((Icp>200)&&(Ncp>65))Ncp=65; */
//if(Pset<840) Ncp=(unsigned char)(Pset*3/100); //0.5V
//else if(Pset<2700)Ncp=(unsigned char)(25+(Pset-840)/93); //0.9V
//else if(Pset<4600)Ncp=(unsigned char)(45+(Pset-2700)/95); //1.3V
//else if(Pset<5300)Ncp=(unsigned char)(65+(Pset-4600)/70); //1.3V
//else Ncp=75;
//if((Icp>200)&&(Ncp>65))Ncp=65;
/* High voltage compressor */
if (Pset < 1239) Ncp = 15;/* 9月16日增加转速*/
else if (Pset < 2455) Ncp = 3 * Pset / 200 - 3; //9.19修改1k电阻
else if (Pset < 3050) Ncp = 33;
else if (Pset < 5532) Ncp = Pset / 111 + 6; //
else if (Pset < 6200) Ncp = 3 * Pset / 400 + 14;
else Ncp = 60;
//if (Pset < 1239) Ncp = 10;/* 9月16日增加转速*/
//else if (Pset < 2455) Ncp = Pset / 80 -4;
//else if (Pset < 4205) Ncp = 50;
//else if (Pset < 5650) Ncp = 35 + Pset / 276;
//else Ncp = 57;
/**********************************************************/
if(TWout<=8800) { ACT_CWP;STP_FAN1; STP_FAN2;} //48C
else if((TWout<=9800)&&(TWout>=9000)) { ACT_CWP;ACT_FAN1; STP_FAN2;} //50C-58C
else if(TWout>=10000) { ACT_CWP;ACT_FAN1; ACT_FAN2;} //60C-
/**********************************************************/
if(TWout<1150) PLmtPatch=0;
else if((TWout>11500)&&(TWout<12000)&&(PLmt>5000))PLmtPatch=PLmt-5000;
else if(TWout>12000) PLmtPatch=PLmt;
/**********************************************************/
if(CVmin>70) {perHVTimer=30;dtyHVTimer=1;PLmtPatch=0;} //adjust the hydrogen drain frenquency according the miniumal cell voltage
else if(CVmin>62) {perHVTimer=15;dtyHVTimer=1;PLmtPatch=0;} //根据徐麟要求从25s修改为15s排放
else if(CVmin>50) {perHVTimer=15;dtyHVTimer=3;PLmtPatch=0;}
else if(CVmin>45) {perHVTimer=10;dtyHVTimer=3;PLmtPatch=0;}
/**********************************************************/
if(CVmin<45) PLmtPatch=PLmt;
else if((CVmin<50)&&(PLmt>4000))PLmtPatch=PLmt-4000;
if((Vst<530)&&(PLmt>4000)&&((PLmt-PLmtPatch)>4000))PLmtPatch=PLmt-4000;
/**calculate Plmt patch by min the cell voltage **/
//Because of the water drain valve is used for supplement relay so disable auto control
//if(Pst<3000) {STP_DRAIN_WATER;DisableWDrain;}
//else if(Pst<5000) {EnableWDrain;perWDTimer=15;dtyWDTimer=1;}
//else {EnableWDrain;perWDTimer=10;dtyWDTimer=2;}
//if((ErrCVCd==NoFault)&&(ErrTsysCd==NoFault)&&(ErrPsysCd==NoFault)){SysStatus =ECU_Enabled;SysErrRank=ECU_Normal;}
//else if((ErrCVCd==DangerousFault)||(ErrTsysCd==DangerousFault)&&(ErrPsysCd==DangerousFault)){SysStatus =ECU_Error;SysErrRank=ECU_HighError;}
//else if((ErrCVCd==SeriousFault)||(ErrTsysCd==SeriousFault)&&(ErrPsysCd==SeriousFault)){SysStatus =ECU_Error;SysErrRank=ECU_LowError;}
//if((SysErrRank==ECU_Normal)&&(ErrFlgWPS||ErrFlgCMP)){SysStatus =ECU_Error;SysErrRank=ECU_MinorFault;}
}
/************************************************************************/
void main(void) {
/*system start from here */
DisableInterrupts;
/*System Initial process*/
PORTIOIni();
RTIInit();
ECTInit();
CHIPADInit();
SPIDAInit();
CANBUSInit();
ProcessIni();
/*When Initiation completed enable interrupts*/
EnableInterrupts;
for(;;) {
/******************Periodically Action************************/
/******************Controlled by RTI conunter*****************/
/*********************************************************/
if(TaskCHIPAD) //Task of Parameters update
{
RdCHIPAD(); //Read analog signals
ErrFlgWPS=!WPSIN; //Read digital signals water tank level
//ErrFlgCMP=CMPFt; //Read compressor fault signal
TaskCHIPAD=0; //Clear task flag
}
/*********************************************************/
if(TaskFCECmd==1) //Task of FCECAN got
{
FCECmdDeal(); //FCE CAN cmd deal routine
TaskFCECmd=0; //Clear task flag
}
/*********************************************************/
if(TaskVMSCmd==1) //Task of VMSCAN got
{
VMSCmdDeal(); //CANVMS cmd predeal routine
TaskVMSCmd=0; //Clear task flag
}
/*********************************************************/
if(TaskSPIDA)
{
DAupdate(Ncp);
//DAupdate(69);
TaskSPIDA=0;
}
/*********************************************************/
if(TaskCANVMS)
{
CANVMS_Load();
CANVMSTrans();
TaskCANVMS=0;
}
/*********************************************************/
if(TaskCANFCE)
{
CANFCE_Load();
CANFCETrans();
TaskCANFCE=0;
}
/*********************************************************/
if(stepCtrl==sysIdle)CheckforECUReady(); //Check for ready
/*****************In VMS auto control mode******************/
/*****************includes 4 static status******************/
/*****************and 6 change action execution*************/
if(IsVMSAutoCtrl)
{
if(SysFallEmg)SysEmgEnable();
/*********************************************************/
else if(IsSysEmg)SysBeingEmg();
/*********************************************************/
else if(SysEnable)StartupEnable();
/*********************************************************/
else if(stepCtrl==sysStartWait)StartupWaitDrain();
/*********************************************************/
else if(stepCtrl==sysWaitReady)StartupCheckReady();
/*********************************************************/
else if(IsSysRunning)SysRunningCtrl();
/*********************************************************/
else if(SysDisable)StopEnable();
/*********************************************************/
else if(stepCtrl==sysStopDrain)StopWaitDrain();
/*********************************************************/
else if(stepCtrl==sysStoping)StopWaitReady();
/*********************************************************/
}
SysStateUpdate;
} /* for loop*/
}/* main */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -