//-------------------------------------------------------// // Project Code : V2H6K01-23-ENEMAN // File Name : Relay.cpp // Created on : 2023. 8. 8. // Description : // Author : KimJeongWoo // Last modified Date : //-------------------------------------------------------// #include "Cpu1DeviceDefine.h" //----Main-AcRelay(ALZ51B12)--------// // Operate time : Max. 15ms // // Release time : Max. 5ms // //----------------------------------// //---AcPreCharge-Relay(ALDP112W)----// // Operate Time : Max. 10ms // // Release time : Max. 10ms // //----------------------------------// //---DcPreCharge-Relay()------------// unsigned int FlagAcPreCharge = 0; unsigned int FlagBatPreCharge = 0; float AcRelaySetVolt = 20;//250 float BatRelaySetVolt = 250.;//130; void InitRelay() { InitRelayTime(); InitCntAcPreCharge(); InitCntBatPreCharge(); InitAcRelay(); InitBatRelay(); DigitalOutput(); delay_ms(100L); } void InitAcRelay() { // Dout.Data.bit.RelayGridPreCharge = 0; // Dout.Data.bit.RelayGridUN = 0; // Dout.Data.bit.RelayGridNW = 0; // // Dout.Data.bit.RelayLoadUN = 0; // Dout.Data.bit.RelayLoadNW = 0; } void InitBatRelay() { // Dout.Data.bit.RelayBatPreCharge = 0; // Dout.Data.bit.RelayBatP = 0; // Dout.Data.bit.RelayBatN = 0; } void InitRelayTime() { SetAcPreChargeWait = (int) (0.5 * INV_T2ms); SetBatPreChargeWait = (int) (0.5 * INV_T2ms); SetPreAcPreRelayWait = (int) (0.5 * INV_T2ms); SetPreAcRelayWait = (int) (5. * INV_T2ms); SetPreAcRelayDetect = (int) (0.5 * INV_T2ms); SetPreAcPreRelayDetect = (int) (0.5 * INV_T2ms); SetPreAcRelayDelay = (int) (0.5 * INV_T2ms); SetPreBatPreRelayWait = (int) (0.5 * INV_T2ms); SetPreBatRelayWait = (int) (3. * INV_T2ms); SetPreBatRelayDetect = (int) (0.5 * INV_T2ms); SetPreBatPreRelayDetect = (int) (0.5 * INV_T2ms); SetPreBatRelayDelay = (int) (0.5 * INV_T2ms); } void InitCntAcPreCharge() { CntPreAcPreRelayWait = SetPreAcPreRelayWait; CntPreAcRelayWait = SetPreAcRelayWait; CntPreAcPreRelayDetect = SetPreAcPreRelayDetect; CntPreAcRelayDetect = SetPreAcRelayDetect; CntPreAcRelayDelay = SetPreAcRelayDelay; CntAcPreChargeWait = 0; } void InitCntBatPreCharge() { CntPreBatPreRelayWait = SetPreBatPreRelayWait; CntPreBatRelayWait = SetPreBatRelayWait; CntPreBatRelayDetect = SetPreBatRelayDetect; CntPreBatPreRelayDetect = SetPreBatPreRelayDetect; CntPreBatRelayDelay = SetPreBatRelayDelay; CntBatPreChargeWait = 0; } int CntBatPreChargeWait = 0, SetBatPreChargeWait = 0; int CntPreBatPreRelayWait = 0, SetPreBatPreRelayWait = 0; int CntPreBatPreRelayDetect = 0, SetPreBatPreRelayDetect = 0; int CntPreBatRelayWait = 0, SetPreBatRelayWait = 0; int CntPreBatRelayDetect = 0, SetPreBatRelayDetect = 0; int CntPreBatRelayDelay = 0, SetPreBatRelayDelay = 0; int StatusBatPreCharge = 0; void PreChargeBatRelay(float BatRelaySetVolt) { // if ((FlagRunBoost == 1) || (ModeSystem == 1)) FlagBatPreCharge = FlagBatPreCharge; // else FlagBatPreCharge = 0, StatusBatPreCharge = 0; // // if ((FlagBatPreCharge == 1) && (SystemFault == 0)) // { // if (StatusBatPreCharge == 0) // { // if (--CntPreBatPreRelayWait <= 0) // { // Dout.Data.bit.RelayBatPreCharge = 1; // Dout.Data.bit.RelayBatN = 1; // CntPreBatPreRelayWait = SetPreBatPreRelayWait; // } // // if ((Dout.Data.bit.RelayBatPreCharge == 1) && (Dout.Data.bit.RelayBatN == 1)) // { // if (--CntPreBatRelayWait <= 0) // { // CntPreBatRelayWait = SetPreBatRelayWait; // // if (CH1_IR_Flt > BatRelaySetVolt) // { // Dout.Data.bit.RelayBatP = 1; // } // else Fault.Sw1.bit.DcPreCharge |= 1; // } // } // if ((Dout.Data.bit.RelayBatP == 1) && (Dout.Data.bit.RelayBatN == 1)) // { // if (--CntPreBatRelayDelay <= 0) // { // if (++CntBatPreChargeWait > SetBatPreChargeWait) // { // InitCntBatPreCharge(); // Dout.Data.bit.RelayBatPreCharge = 0; // CntBatPreChargeWait = 0; // StatusBatPreCharge = 1; // } // } // } // } // if (StatusBatPreCharge == 1) FlagBatPreCharge = 0; // } // else // { // FlagBatPreCharge = 0; // InitCntBatPreCharge(); // } } int CntAcPreChargeWait = 0, SetAcPreChargeWait = 0; int CntPreAcPreRelayWait = 0, SetPreAcPreRelayWait = 0; int CntPreAcPreRelayDetect = 0, SetPreAcPreRelayDetect = 0; int CntPreAcRelayWait = 0, SetPreAcRelayWait = 0; int CntPreAcRelayDetect = 0, SetPreAcRelayDetect = 0; int CntPreAcRelayDelay = 0, SetPreAcRelayDelay = 0; int StatusAcPreCharge = 0; float RelayAcOntimeMin = -2.82; float RelayAcOntimeMax = -2.50; void PreChargeAcRelay(float AcRelaySetVolt) { // if ((FlagRunInv == 1) || (ModeSystem == 1)) FlagAcPreCharge = FlagAcPreCharge; // else FlagAcPreCharge = 0, StatusAcPreCharge = 0; // // if ((FlagAcPreCharge == 1) && (SystemFault == 0)) // { // if (StatusAcPreCharge == 0) // { // if (--CntPreAcPreRelayWait <= 0) // { //// if ((Theta >= RelayAcOntimeMin) && (Theta <= RelayAcOntimeMax)) //// { // Dout.Data.bit.RelayGridPreCharge = 1; // CntPreAcPreRelayWait = SetPreAcPreRelayWait; //// } // } // if (Dout.Data.bit.RelayGridPreCharge == 1) // { // if (--CntPreAcRelayWait <= 0) // { // CntPreAcRelayWait = SetPreAcRelayWait; // // if (CH3_UV_Flt > AcRelaySetVolt) // { //// if ((Theta >= RelayAcOntimeMin) && (Theta >= RelayAcOntimeMax)) //// { // Dout.Data.bit.RelayGridUN = 1; // Dout.Data.bit.RelayGridNW = 1; //// } // } // else Fault.Sw1.bit.AcPreCharge = 1; // } // } // // if ((Dout.Data.bit.RelayGridUN == 1) && (Dout.Data.bit.RelayGridNW == 1)) // { // if (--CntPreAcRelayDelay <= 0) // { // if (++CntAcPreChargeWait > SetAcPreChargeWait) // { // InitCntAcPreCharge(); // Dout.Data.bit.RelayGridPreCharge = 0; // // CntAcPreChargeWait = 0; // StatusAcPreCharge = 1; // } // } // } // } // if (StatusAcPreCharge == 1) FlagAcPreCharge = 0; // } // else // { // FlagAcPreCharge = 0; // InitCntAcPreCharge(); // } //todo 동작시 접점 확인 및 폴트 추가 할 것 } unsigned int FlagLoadRelayOn = 0; void LoadRelay() { // if(FlagLoadRelayOn == 1) // { // Dout.Data.bit.RelayLoadUN = 1; // Dout.Data.bit.RelayLoadNW = 1; // } // else // { // Dout.Data.bit.RelayLoadUN = 0; // Dout.Data.bit.RelayLoadNW = 0; // } }