
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
//-------------------------------------------------------//
// Project Code : V2H6K01-23-ENEMAN
// File Name : FaultProcess.cpp
// Created on : 2023. 07. 26.
// Description :
// Author : KimJeongWoo
// Last modified Date :
//-------------------------------------------------------//
#include "Cpu1DeviceDefine.h"
void InitFaultSet()
{
memset(&Fault, 0, (sizeof(Fault) / sizeof(int)));
InitProtectionSet();
}
void InitInstFaultLevelSet()
{
//Bat 순시 과전압
FT_UV_OV.Ratio = 1.00; // 100%
FT_UV_OV.SetLevel = FT_UV_OV.Ratio * SET_FT_UV_Level;
//Bat 순시 저전압
FT_VIS_OV.Ratio = 1.0; // 100%
FT_VIS_OV.SetLevel = FT_VIS_OV.Ratio * SET_FT_VIS_Level;
//Bat 순시 과전류
FT_IR_OV.Ratio = 1.00;// 100%
FT_IR_OV.SetLevel = FT_IR_OV.Ratio * SET_FT_IR_Level;
}
void InitOverTempLevelSet()
{
//AC Switch Inverter Over Temperature
OtNtc5.SetLevel = 85.;
//AC Switch Inverter Over Temperature
OtNtc6.SetLevel = 85.;
}
void InitProtectionSet()
{
InitInstFaultLevelSet();
// InitOverTempLevelSet();
// InitFaultFreq();
// InitFaultVac();
}
void FaultInstType()
{
// if (CH4_UV_Flt > FT_UV_OV.SetLevel) Fault.Sw1.bit.CH4_UV_OV |= 1;
// if (CH4_VIS_Flt > FT_VIS_OV.SetLevel) Fault.Sw1.bit.CH4_VIS_OV |= 1;
// if (CH4_IR_Flt > FT_IR_OV.SetLevel) Fault.Sw1.bit.CH4_IR_OV |= 1;
if ((CH4_UV_Flt > FT_UV_OV.SetLevel)
&&(CH4_VIS_Flt > FT_VIS_OV.SetLevel)) Fault.Sw1.bit.CH4_UV_OV |= 1;
if ((CH4_UV_Flt > FT_UV_OV.SetLevel)
&&(CH4_VIS_Flt > FT_IR_OV.SetLevel)) Fault.Sw1.bit.CH4_IR_OV |= 1;
}
void OverTempFault()
{
// if (VntcBoost > OtDcSwBoost.SetLevel) Fault.Sw1.bit.OtDcSwBoost |= 1;
// if (VntcLvDab > OtDcSwLvDab.SetLevel) Fault.Sw1.bit.OtDcSwLvDab |= 1;
// if (VntcHvDab > OtAcSwHvDab.SetLevel) Fault.Sw1.bit.OtAcSwHvDab |= 1;
// if (VntcInv > OtAcSwInv.SetLevel) Fault.Sw1.bit.OtAcSwInv |= 1;
//
// if (Vntc5 > OtNtc5.SetLevel) Fault.Sw1.bit.OtNtc5 |= 1;
// if (Vntc6 > OtNtc6.SetLevel) Fault.Sw1.bit.OtNtc6 |= 1;
}
void InitFaultVac(void)
{
// FT_Combo_1.Ratio = 1.1;
// FT_Combo_1.SetLevel = FT_Combo_1.Ratio * VacRatePeak;
// FT_Combo_1.SetTime = 0.16;
// FT_Combo_1.SetCnt = FT_Combo_1.SetTime * INV_T10ms;
// FT_Combo_1.ChkCnt = 0;
// FT_Combo_1.SetStableCnt = FT_Combo_1.SetCnt;
// FT_Combo_1.StableCnt = 0;
//
// UvVgrid.Ratio = 0.9;
// UvVgrid.SetLevel = UvVgrid.Ratio * VacRatePeak;
// UvVgrid.SetTime = 0.16;
// UvVgrid.SetCnt = UvVgrid.SetTime * INV_T10ms;
// UvVgrid.ChkCnt = 0;
// UvVgrid.SetStableCnt = UvVgrid.SetCnt;
// UvVgrid.StableCnt = 0;
}
void FaultVac() //10ms
{
// if (FlagOffset == 3)
// {
// if (VqeGridFlt < UvVgrid.SetLevel)
// {
// if (++UvVgrid.ChkCnt > UvVgrid.SetCnt)
// {
// Fault.Sw1.bit.CH1_VIS_OV |= 1;
// UvVgrid.ChkCnt = 0;
// }
//
// UvVgrid.StableCnt = 0;
// }
// else if (VqeGridFlt > FT_Combo_1.SetLevel)
// {
// if (++FT_Combo_1.ChkCnt > FT_Combo_1.SetCnt)
// {
// Fault.Sw1.bit.CH1_UV_OV |= 1;
// FT_Combo_1.ChkCnt = 0;
// }
//
// FT_Combo_1.StableCnt = 0;
// }
// else
// {
// if ((++FT_Combo_1.StableCnt > FT_Combo_1.SetStableCnt) && (++UvVgrid.StableCnt > UvVgrid.SetStableCnt))
// {
// FT_Combo_1.ChkCnt = 0;
// FT_Combo_1.StableCnt = 0;
// UvVgrid.ChkCnt = 0;
// UvVgrid.StableCnt = 0;
// }
// }
// }
// else
// {
// UvVgrid.ChkCnt = 0;
// UvVgrid.StableCnt = 0;
// FT_Combo_1.ChkCnt = 0;
// FT_Combo_1.StableCnt = 0;
// }
}
void InitFaultFreq(void)
{
// OfVac.SetLevel = 60.5;
// OfVac.SetTime = 0.1;
// OfVac.SetCnt = OfVac.SetTime * INV_T10ms;
// OfVac.ChkCnt = 0;
// OfVac.SetStableCnt = OfVac.SetCnt;
// OfVac.StableCnt = 0;
//
// UfVac.SetLevel = 59.3;
// UfVac.SetTime = 0.1;
// UfVac.SetCnt = UfVac.SetTime * INV_T10ms;
// UfVac.ChkCnt = 0;
// UfVac.SetStableCnt = UfVac.SetCnt;
// UfVac.StableCnt = 0;
}
void FaultFreq(void) //10ms
{
// if (FlagOffset == 3)
// {
// if (FreqOutFlt > OfVac.SetLevel)
// {
// if (++OfVac.ChkCnt > OfVac.SetCnt)
// {
// Fault.Sw1.bit.CH1_IR_OV |= 1;
// OfVac.ChkCnt = 0;
// }
//
// OfVac.StableCnt = 0;
// }
// else if (FreqOutFlt < UfVac.SetLevel)
// {
// if (++UfVac.ChkCnt > UfVac.SetCnt)
// {
// Fault.Sw1.bit.CH2_UV_OV |= 1;
// UfVac.ChkCnt = 0;
// }
//
// UfVac.StableCnt = 0;
// }
// else
// {
// if ((++OfVac.StableCnt > OfVac.SetStableCnt) && (++UfVac.StableCnt > UfVac.SetStableCnt))
// {
// OfVac.ChkCnt = 0;
// OfVac.StableCnt = 0;
// UfVac.ChkCnt = 0;
// UfVac.StableCnt = 0;
// }
// }
// }
}
void ContectTypeFault()
{
//Emergency Stop
// Fault.Sw2.bit.Switch_EmergencyStop |= Din.Data.bit.ButtonEstop;
}
void DisconnectTempFault()
{
if (FlagOffset == 3)
{
}
}
//unsigned int SetCanMeWait = 5;
//unsigned int CntCanMeWait = 0;
//unsigned int CanMeRxIsrCntOld = 0;
//
//unsigned int SetCanBeWait = 5;
//unsigned int CntCanBeWait = 0;
//unsigned int CanBeRxIsrCntOld = 0;
//
//unsigned int CanMeOff = 0;
//unsigned int CanBeOff = 0;
unsigned int TraceWaitCnt = 0;
unsigned int TraceWaitSet = 800;
void FaultProcess()
{
SystemFault = 1;
// SystemReady = 0;
Dout.Data.bit.Ch00 = 1;
Dout.Data.bit.Ch01 = 1;
if(FT_uv_vis_correlation == 0)
{
FT_uv_vis_correlation = uv_vis_correlation;
FT_uv_ir_correlation = uv_ir_correlation;
FT_vis_ir_correlation = vis_ir_correlation;
FT_uv_vis_change_correlation = uv_vis_change_correlation;
FT_uv_ir_change_correlation = uv_ir_change_correlation;
FT_vis_ir_change_correlation = vis_ir_change_correlation;
FT_stddev = stddev;
FT_adaptive_threshold = adaptive_threshold;
FT_latest_change = latest_change;
}
// GateOutDisable();
// FlagInvGating = 0;
// FlagInvGatingInput = 0;
//
// FlagBoostGating = 0;
// FlagBoostGatingInput = 0;
//
// FlagDabGating = 0;
// FlagDabGatingInput = 0;
//
// CmdChargeStart = 0;
// CmdDischargeStart = 0;
//
// FlagRunInv = 0;
// CmdInvStart = 0;
// CmdInvOPset = 99;
//
// FlagRunBoost = 0;
// CmdBoostStart = 0;
// CmdBoostOPset = 99;
//
// FlagRunDab = 0;
// CmdDabStart = 0;
// CmdDabOPset = 99;
//
// InvReady = 0;
//
// IbatRef = 0.;
//
//// IqeRef = 0.;
//// IdeRef = 0.;
//
//// VbatRef = 0.;
//// VdabRef = 0.;
//
//// InitCntAcPreCharge();
//// FlagAcPreCharge = 0;
//// StatusAcPreCharge = 0;
//
// DigitalInput();
// InitAcRelay();
// DigitalOutput();
//
// TinvA = 0;
// TinvB = 0;
// TinvACnt = 0;
// TinvBCnt = 0;
//
// Tboost = 0;
// TboostCnt = 0;
//
// TdabA = 0;
// TdabB = 0;
// TdabC = 0;
// TdabD = 0;
// TdabPh = 0;
//
// TdabACnt = 0;
// TdabBCnt = 0;
// TdabCCnt = 0;
// TdabDCnt = 0;
// TdabPhCnt = 0;
FaultLatchData();
// if(FlagTrace == 1)
// {
// if(TraceWaitCnt++ > TraceWaitSet)
// {
// FlagTrace = 0;
// }
// }
// else
// {
// TraceWaitCnt = TraceWaitSet;
// }
}
unsigned int FlagLatch = 0;
void FaultLatchData()
{
// if (FlagLatch == 0)
// {
// FaultLatch.Vbat = Vbat;
// FaultLatch.Ibat = Ibat;
//
// FaultLatch.Vboost = Vboost;
// FaultLatch.Vdab = Vdab;
// FaultLatch.GFD = GFD;
// FaultLatch.VdcH = VdcH;
// FaultLatch.VdcL = VdcL;
// FaultLatch.VunGrid = VunGrid;
// FaultLatch.VnwGrid = VnwGrid;
// FaultLatch.IuInv = IuInv;
// FaultLatch.IwInv = IwInv;
//
// FaultLatch.Izct = Izct;
// FaultLatch.IuGridExt = IuGridExt;
// FaultLatch.IwGridExt = IwGridExt;
//
// FaultLatch.VntcBoost = VntcBoost;
// FaultLatch.VntcLvDab = VntcLvDab;
// FaultLatch.VntcHvDab = VntcHvDab;
// FaultLatch.VntcInv = VntcInv;
// FaultLatch.Vntc5 =
//
// FaultLatch.VunInv = VunInv;
// FaultLatch.VnwInv = VnwInv;
// FaultLatch.IuGrid = IuGrid;
// FaultLatch.IwGrid = IwGrid;
//
// FlagLatch = 1;
//
// }
}
void FaultChecker()
{
FaultInstType();
ContectTypeFault();
OverTempFault();
if ((Fault.Sw1.all != 0) || (Fault.Sw2.all != 0) || (Fault.Sw3.all != 0))
{
FaultProcess();
}
if (SystemFault == 1)
{
if (CmdFaultReset == 33)
{
FaultReset = 1;
CmdFaultReset = 99;
}
}
else CmdFaultReset = 99, FaultReset = 0;
if (SystemFault == 0) FaultReset = 0;
else if ((SystemFault == 1) && (FaultReset == 1)) SystemRestart();
}
void SystemRestart()
{
SystemFault = 0;
Dout.Data.bit.Ch00 = 0;
Dout.Data.bit.Ch01 = 0;
Dout.Data.bit.Ch02 = 0;
Dout.Data.bit.Ch03 = 0;
Dout.Data.bit.Ch04 = 0;
Fault.Sw1.all = 0;
Fault.Sw2.all = 0;
Fault.Sw3.all = 0;
FlagOffset = 0;
SystemReady = 0;
FaultReset = 0;
InitAcRelay();
memset(&FaultLatch, 0, (sizeof(FaultLatch) / sizeof(int)));
FlagLatch = 0;
CH4_UV_max = 0;
CH4_VIS_max = 0;
CH4_IR_max = 0;
FT_uv_vis_correlation = 0;
FT_uv_ir_correlation = 0;
FT_vis_ir_correlation = 0;
FT_uv_vis_change_correlation = 0;
FT_uv_ir_change_correlation = 0;
FT_vis_ir_change_correlation = 0;
FT_stddev = 0;
FT_adaptive_threshold = 0;
FT_latest_change = 0;
}