1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753 |
- /************************************************************************
- Project: Welling Motor Control Paltform
- Filename: alarm.c
- Partner Filename: alarm.h
- Description: System fault detection and diagnosis
- Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
- CPU TYPE : GD32F3x0
- *************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- *************************************************************************
- Revising History (ECL of this file):
- ************************************************************************/
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
- *************************************************************************/
- #ifndef _ALARM_C_
- #define _ALARM_C_
- #endif
- /************************************************************************
- Included File:
- *************************************************************************/
- #include "syspar.h"
- #include "user.h"
- #include "FSM_1st.h"
- #include "FSM_2nd.h"
- #include "spdctrFSM.h"
- #include "power.h"
- #include "emcdeal.h"
- #include "canAppl.h"
- #include "hwsetup.h"
- #include "UserGpio_Config.h"
- /************************************************************************
- Private Variables:
- ************************************************************************/
- UWORD alm_pvt_uwResPwrWt = 0;
- _Bool alm_pvt_blIPMOTReCheckFlg = FALSE;
- _Bool alm_pvt_blMotorOTReCheckFlg = FALSE;
- SWORD alm_pvt_swSpdRefAbsPu = 0;
- SWORD alm_pvt_swSpdFbAbsPu = 0;
- SLONG alm_pvt_slSpdFbLpfAbsPu = 0;
- SWORD alm_pvt_swSpdFbLpfAbsPu = 0;
- SWORD alm_pvt_swIqRefAbsPu = 0;
- SLONG alm_pvt_slIqRefLpfAbsPu = 0;
- SWORD alm_pvt_swIqRefLpfAbsPu = 0;
- _Bool alm_pvt_blTbcFirstFlg = FALSE;
- _Bool alm_pvt_blTbsFirstFlg = FALSE;
- SWORD alm_pvt_swRtLockPwrRatio = 0;
- static ULONG alm_pvt_ulWarn2ErrorCount = 0;
- _Bool alm_pvt_blCadFltPowerUpFlg = FALSE;
- IABCSTRUCT alm_I_Filter;
- /************************************************************************
- Constant Table:
- *************************************************************************/
- /************************************************************************
- Exported Functions:
- *************************************************************************/
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voInit(void)
- {
- /* Alarm code and flag init */
- alm_unCode.all = 0;
- alm_unBikeCode.all = 0;
- alm_blAlmOccrFlg = FALSE;
- alm_blWarnOccrFlg = FALSE;
- /* Alarm action init */
- alm_unAction.all = 0;
- /* Alarm handle fsm init */
- alm_enFSMStatus = Alm_Stop;
- alm_enBikeFSMStatus = Alm_Stop;
- /* Clear stop count */
- alm_stStopCt.ulThrPhsShrtFrc = 0;
- alm_stStopCt.ulPWMOff = 0;
- alm_stStopCt.ulThrPhsShrt = 0;
- alm_stStopCt.uwRotorStopCnt = 0;
- alm_stStopCt.ulPWMOffShrtSw = 0;
- alm_stStopCt.ulShrtPWMOffSw = 0;
- alm_stStopCt.ulBikePWMOff = 0;
- /* Alarm recover count init */
- alm_stRecCt.ulGlbl = 0;
- alm_stRecCt.ulOvrVlt = 0;
- alm_stRecCt.ulOvrVlt1 = 0;
- alm_stRecCt.ulUndrVlt = 0;
- alm_stRecCt.ulUndrVlt1 = 0;
- alm_stRecCt.ulIPMOvrHeat = 0;
- alm_stRecCt.ulIPMOvrHeat1 = 0;
- alm_stRecCt.ulIPMOC = 0;
- alm_stRecCt.ulBikeGlbl = 0;
- alm_stRecCt.ulBikeSpdFlt = 0;
- alm_stRecCt.ulCadenceFlt = 0;
- alm_stRecCt.ulTorqFlt = 0;
- alm_stRecCt.ulThrottleFlt = 0;
- alm_stRecCt.ulPCBNTCFlt = 0;
- alm_stRecCt.ulMotorNTCFlt = 0;
- /* Alarm detect count init */
- alm_stDecCt.ulIPMOvrHeat = 0;
- alm_stDecCt.ulIPMOvrHeat1 = 0;
- alm_stDecCt.ulOvrCur = 0;
- alm_stDecCt.ulOvrSpd = 0;
- alm_stDecCt.ulOvrVltLvl1 = 0;
- alm_stDecCt.ulPhsALoss = 0;
- alm_stDecCt.ulPhsBLoss = 0;
- alm_stDecCt.ulPhsCLoss = 0;
- alm_stDecCt.slRotorLock = 0;
- alm_stDecCt.ulUndrVltLvl1 = 0;
- alm_stDecCt.uwBikeSpdFlt = 0;
- alm_stDecCt.uwCadenceFlt = 0;
- alm_stDecCt.uwTorqFlt = 0;
- alm_stDecCt.uwThrottleFlt = 0;
- alm_stDecCt.uwPCBNTCFlt = 0;
- alm_stDecCt.uwMotorNTCFlt = 0;
- /* Private variables init */
- alm_pvt_blIPMOTReCheckFlg = FALSE;
- alm_pvt_blMotorOTReCheckFlg = FALSE;
- alm_I_Filter.ulIa_Filter=0;
- alm_I_Filter.ulIb_Filter=0;
- alm_I_Filter.ulIc_Filter=0;
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voCoef(void)
- {
- alm_stDetectTbcCoefIn.uwIbAp = IBASE;
- alm_stDetectTbcCoefIn.uwUbVt = VBASE;
- alm_stDetectTbcCoefIn.uwFTbcHz = FTBC_HZ;
- alm_stDetectTbcCoefIn.uwPairs = cp_stMotorPara.swMotrPolePairs;
- alm_stDetectTbcCoefIn.uwMtRsOm = cp_stMotorPara.swRsOhm;
- alm_stDetectTbcCoefIn.uwFbHz = FBASE;
- alm_stDetectTbcCoefIn.uwOvrCurIa = cp_stControlPara.swAlmOverCurrentVal;
- alm_stDetectTbcCoefIn.uwOvrCurTu = cp_stControlPara.swAlmOverCurrentTM;
- alm_stDetectTbcCoefIn.uwAdcDetHigVt = cp_stControlPara.swAlmAdcDetectHighVal;
- alm_stDetectTbcCoefIn.uwAdcDetLowVt = cp_stControlPara.swAlmAdcDetectLowVal;
- alm_stDetectTbcCoefIn.uwPhsLossVt = cp_stControlPara.swAlmPhsLossVal;
- alm_stDetectTbcCoefIn.uwPhsLossTs = cp_stControlPara.swAlmPhsLossTM;
- alm_stDetectTbcCoefIn.uwRotorLockSpdK = cp_stControlPara.swAlmRotorLockK;
- alm_stDetectTbcCoefIn.uwRotorLockTs = cp_stControlPara.swAlmRotorLockTM;
- alm_stDetectTbcCoefIn.swIqRefLpfAbsAp = cp_stControlPara.swAlmRotorLockCurVal;
- alm_stDetectTbcCoefIn.swSpdFbLpfAbsRpm = cp_stControlPara.swAlmRotorLockSpdVal;
- alm_voDetecTBCCoef(&alm_stDetectTbcCoefIn, &alm_stDetectTbcCoef);
- alm_stDetectTbsCoefIn.uwPairs = cp_stMotorPara.swMotrPolePairs;
- alm_stDetectTbsCoefIn.uwFbHz = FBASE;
- alm_stDetectTbsCoefIn.uwFTbsHz = FTBS_HZ;
- alm_stDetectTbsCoefIn.uwUbVt = VBASE;
- alm_stDetectTbsCoefIn.uwOvrVlt1Vt = cp_stControlPara.swAlmOverVolVal1;
- alm_stDetectTbsCoefIn.uwOvrVlt1Tm = cp_stControlPara.swAlmOverVolTM1;
- alm_stDetectTbsCoefIn.uwUndrVlt1Vt = cp_stControlPara.swAlmUnderVolVal1;
- alm_stDetectTbsCoefIn.uwUndrVlt1Tm = cp_stControlPara.swAlmUnderVolTM1;
- alm_stDetectTbsCoefIn.uwOvrSpdRpm = cp_stControlPara.swAlmOverSpdVal;
- alm_stDetectTbsCoefIn.uwOvrSpdTm = cp_stControlPara.swAlmOverSpdTM;
- alm_stDetectTbsCoefIn.uwIpmOvrHeatRecCe = cp_stControlPara.swAlmRecOHeatVal;
- alm_stDetectTbsCoefIn.uwIpmOvrHeatTs = cp_stControlPara.swAlmOverHeatTM;
- alm_stDetectTbsCoefIn.uwIpmOvrHeatCe = cp_stControlPara.swAlmOverHeatCeVal;
- alm_stDetectTbsCoefIn.uwMotorOvrHeatRecCe = cp_stControlPara.swAlmMotorRecOHeatVal;
- alm_stDetectTbsCoefIn.uwMotorOvrHeatTs = ALM_MOTOR_OVR_TM;
- alm_stDetectTbsCoefIn.uwMotorOvrHeatCe = cp_stControlPara.swAlmMotorOverHeatCeVal;
- alm_voDetecTBSCoef(&alm_stDetectTbsCoefIn, &alm_stDetectTbsCoef);
- alm_stStopTbcCoefIn.uwIbAp = IBASE;
- alm_stStopTbcCoefIn.uwUbVt = VBASE;
- alm_stStopTbcCoefIn.uwFTbcHz = FTBC_HZ;
- alm_stStopTbcCoefIn.uwThrPhsShrtFrcTs = cp_stControlPara.swAlmThrPhsShrtFrcTM;
- alm_stStopTbcCoefIn.uwIPMOverCurStopTs = cp_stControlPara.swAlmIPMOverCurStopTM;
- alm_stStopTbcCoefIn.uwPwmoffShrt1SwTs = cp_stControlPara.swAlmPWMOffShrtsw1TM;
- alm_stStopTbcCoefIn.uwShrtPwmoffSwTs = cp_stControlPara.swAlmShrtPWMOffswTM;
- alm_stStopTbcCoefIn.uwPwmOffTs = cp_stControlPara.swAlmPWMOffTM;
- alm_stStopTbcCoefIn.uwThrPhsShrtTs = cp_stControlPara.swAlmThrPhsShrtNormTM;
- alm_stStopTbcCoefIn.uwOvrVlt1Vt = cp_stControlPara.swAlmOverVolVal1;
- alm_voStopTBCCoef(&alm_stStopTbcCoefIn, &alm_stStopTbcCoef);
- alm_stResetCoefIn.uwUbVt = VBASE;
- alm_stResetCoefIn.uwFTbcHz = FTBC_HZ;
- alm_stResetCoefIn.uwRecAllTs = cp_stControlPara.swAlmRecAllTM;
- alm_stResetCoefIn.uwIpmOcRecTs = cp_stControlPara.swAlmRecOCTM;
- alm_stResetCoefIn.uwOvrVltRecVt = cp_stControlPara.swAlmRecOVVal;
- alm_stResetCoefIn.uwOvrVltRecTs = cp_stControlPara.swAlmRecOVTM;
- alm_stResetCoefIn.uwUndrVltRecVt = cp_stControlPara.swAlmRecUVVal;
- alm_stResetCoefIn.uwUndrVltRecTs = cp_stControlPara.swAlmRecUVTM;
- alm_stResetCoefIn.uwIpmOvrHeatRecCe = cp_stControlPara.swAlmRecOHeatVal;
- alm_stResetCoefIn.uwIpmOvrHeatRecTs = cp_stControlPara.swAlmRecOHeatTM;
- alm_stResetCoefIn.uwIpmOvrHeatRec1Ts = cp_stControlPara.swAlmRecOHeatTM1;
- alm_stResetCoefIn.uwMotorOvrHeatRecCe = cp_stControlPara.swAlmMotorRecOHeatVal;
- alm_stResetCoefIn.uwMotorOvrHeatRecTs = cp_stControlPara.swAlmRecOHeatTM;
- alm_stResetCoefIn.uwMotorOvrHeatRec1Ts = cp_stControlPara.swAlmRecOHeatTM1;
- alm_voResetCoef(&alm_stResetCoefIn, &alm_stResetCoef);
- alm_stDetect200MSCoefIn.swMotorSpdMinRpm = ALM_MOTORSPD_MIN_RPM;
- alm_stDetect200MSCoefIn.uwTorqMinNm = ALM_TROQ_MIN_Nm;
- alm_stDetect200MSCoefIn.uwBikeSpdFltTs = ALM_BIKESPD_FLT_TS;
- alm_stDetect200MSCoefIn.uwCadenceFltTs = ALM_CADENCE_FLT_TS;
- alm_stDetect200MSCoefIn.uwFbHz = FBASE;
- alm_stDetect200MSCoefIn.uwFT200MSHz = 5 ;
- alm_stDetect200MSCoefIn.uwMotorNTCFltTs = ALM_MOTORNTC_FLT_TS;
- alm_stDetect200MSCoefIn.uwPairs = cp_stMotorPara.swMotrPolePairs;
- alm_stDetect200MSCoefIn.uwPCBNTCFltTs = ALM_PCBNTC_FLT_TS;
- alm_stDetect200MSCoefIn.uwThrottleFltTs = ALM_THROTTLE_FLT_TS;
- alm_stDetect200MSCoefIn.uwTorqFltTs = ALM_TORQ_FLT_TS;
- alm_stDetect200MSCoefIn.uwTorqMaxVol = ALM_TORQ_MAX_VOL;
- alm_stDetect200MSCoefIn.uwTorqMinVol = ALM_TORQ_MIN_VOL;
- alm_stDetect200MSCoefIn.uwThrottleMaxVol = ALM_THROTTLE_MAX_VOL;
- alm_stDetect200MSCoefIn.uwThrottleMinVol =ALM_THROTTLE_MIN_VOL;
- alm_stDetect200MSCoefIn.uwNTCMaxVol = ALM_NTC_MAX_VOL;
- alm_stDetect200MSCoefIn.uwNTCMinVol = ALM_NTC_MIN_VOL;
- alm_voDetec200MSCoef(&alm_stDetect200MSCoefIn, &alm_stDetect200MSCoef);
-
- alm_stReset1MSCoefIn.uwBikeGlblTm = ALM_BIKE_REC_ALL_TM;
- alm_stReset1MSCoefIn.uwBikeSpdFltTm = ALM_BIKESPD_REC_TM;
- alm_stReset1MSCoefIn.uwCadenceFltTm = ALM_CADENCE_REC_TM;
- alm_stReset1MSCoefIn.uwFT1MSHz = 1000;
- alm_stReset1MSCoefIn.uwMotorNTCFltTm = ALM_MOTORNTC_REC_TM;
- alm_stReset1MSCoefIn.uwPCBNTCFltTm = ALM_PCBNTC_REC_TM;
- alm_stReset1MSCoefIn.uwThrottleFltTm = ALM_THROTTLE_REC_TM;
- alm_stReset1MSCoefIn.uwTorqFltTm = ALM_TORQ_REC_TM;
- alm_voReset1MSCoef(&alm_stReset1MSCoefIn, &alm_stReset1MSCoef);
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voDetecTBCCoef(ALM_DETECTBC_COFIN *in, ALM_DETECTBC_COF *out)
- {
- UWORD uwRbOm;
- if (in->uwIbAp < 1)
- {
- in->uwIbAp = 1;
- }
- if (in->uwFbHz < 1)
- {
- in->uwFbHz = 1;
- }
- uwRbOm = (ULONG)in->uwUbVt * 100000 / in->uwIbAp; /* unit: 0.01Ohm, Resistance base */
- out->uwRsPu = ((ULONG)in->uwMtRsOm << 15) / uwRbOm; /* Q15, Phase resistance */
- out->uwPbWt = (ULONG)in->uwUbVt * in->uwIbAp * 3 / 100 >> 1; /* unit: 0.1w, Power base */
- out->ulOvrCurValPu = ((ULONG)in->uwOvrCurIa << 14) / in->uwIbAp; // CUR_AP2PU(x) (((ULONG)(x)<<14)/IBASE) Q14
- out->ulOvrCurValCt = ((ULONG)in->uwOvrCurTu * in->uwFTbcHz / 1000000) >> 1; // TBC_US2CT(x) ((ULONG)(x)*FTBC_HZ/1000000)
- out->slAdcDetHigValPu = ((SLONG)in->uwAdcDetHigVt * 4096 / 330); //_IQ12(A) (SLONG)(A * 4096L)
- out->slAdcDetLowValPu = ((SLONG)in->uwAdcDetLowVt * 4096 / 330);
- out->ulPhsLossValPu = ((ULONG)in->uwPhsLossVt << 14) / in->uwIbAp;
- out->ulPhsLossValCt = ((ULONG)in->uwPhsLossTs * in->uwFTbcHz) >> 1; // TBC_S2CT(x) ((ULONG)(x)*FTBC_HZ)
- out->slRotorLockSpdK = ((SLONG)in->uwRotorLockSpdK * 1024 / 100); //_IQ10(0.5) (SLONG)(A * 1024L)
- out->slRotorLockValCt = ((ULONG)in->uwRotorLockTs * in->uwFTbcHz) >> 1;
- out->slIqRefLpfAbsValPu = ((SLONG)in->swIqRefLpfAbsAp << 14) / in->uwIbAp; // CUR_AP2PU(x) (((ULONG)(x)<<14)/IBASE)
- out->slSpdFbLpfAbsValPu = ((SLONG)in->swSpdFbLpfAbsRpm << 15) / 60 * in->uwPairs / in->uwFbHz;
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef)
- {
- SWORD swTmp1, swTmp2;
-
- /* MicroFault Handle */
- // if(clasB_unFaultCode.all != 0)
- // {
- // alm_unAction.bit.PWMOff = TRUE;
- // //alm_unCode.bit.MCUErr = TRUE;
- // }
- /*=======================================================================
- IPM fault
- =======================================================================*/
- if(alm_unCode.bit.IPMFlt==TRUE)// if (MCU_BRKIN_FLG) //
- {
- alm_unAction.bit.ThrPhsShrtFrc = TRUE;
- // alm_unCode.bit.IPMFlt = TRUE;
- }
- if (alm_pvt_blTbcFirstFlg == TRUE)
- {
- /*=======================================================================
- Software Over current
- =======================================================================*/
- #if 0//(EMCDEAL_EN!=0)
- if(EcmDeal.EmcModeFlag==TRUE)
- {
- alm_stDecCt.ulOvrCur=0;
- }
- else
- #endif
- // {
- // if (in->blADCInitOvrFlg)
- // {
- // if (curSpeed_state.state != Stop)
- // {
- // if (in->uwIpeakPu > coef->ulOvrCurValPu) //
- // {
- // alm_stDecCt.ulOvrCur++;
- // if (alm_stDecCt.ulOvrCur >= coef->ulOvrCurValCt) // 500us
- // {
- // alm_stDecCt.ulOvrCur = coef->ulOvrCurValCt;
- // alm_unAction.bit.PWMOff = TRUE;
- // alm_unCode.bit.OvrCur = TRUE;
- // }
- // }
- // else
- // {
- // alm_stDecCt.ulOvrCur = 0;
- // }
- // }
- // else
- // {
- // alm_stDecCt.ulOvrCur = 0;
- // }
- // }
- // }
- /*=======================================================================
- ADC Self Detecting Fault
- =======================================================================*/
- // if (in->blADCInitOvrFlg)
- // {
- // if((in->uwIdcOffset >= coef->slAdcDetHigValPu)||(in->uwIdcOffset <= coef->slAdcDetLowValPu))
- // {
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- // alm_unCode.bit.ADCOffsetFlt = TRUE;
- // }
- // }
- /*=======================================================================
- Over load
- =======================================================================*/
- /*=======================================================================
- Phase loss
- =======================================================================*/
- if (curSpeed_state.state != Stop)
- {
- alm_I_Filter.ulIa_Filter=(in->uwIaAbsPu +alm_I_Filter.ulIa_Filter*7)>>3;
- alm_I_Filter.ulIb_Filter=(in->uwIbAbsPu +alm_I_Filter.ulIb_Filter*7)>>3;
- alm_I_Filter.ulIc_Filter=(in->uwIcAbsPu +alm_I_Filter.ulIc_Filter*7)>>3;
- // if (scm_swIqRefPu > 150 || scm_swIqRefPu < -150)
- // {
- if((cp_stBikeRunInfoPara.BikeSpeedKmH>70) &&(MC_RunInfo.BusCurrent>5000))//70-7km/h
- {
- if (alm_I_Filter.ulIa_Filter < coef->ulPhsLossValPu) // 1A
- {
- alm_stDecCt.ulPhsALoss++;
- }
- else
- {
- alm_stDecCt.ulPhsALoss = 0;
- }
- if (alm_I_Filter.ulIb_Filter < coef->ulPhsLossValPu)
- {
- alm_stDecCt.ulPhsBLoss++;
- }
- else
- {
- alm_stDecCt.ulPhsBLoss = 0;
- }
- if (alm_I_Filter.ulIc_Filter < coef->ulPhsLossValPu)
- {
- alm_stDecCt.ulPhsCLoss++;
- }
- else
- {
- alm_stDecCt.ulPhsCLoss = 0;
- }
- }
- else
- {
- alm_stDecCt.ulPhsALoss = 0;
- alm_stDecCt.ulPhsBLoss = 0;
- alm_stDecCt.ulPhsCLoss = 0;
- }
- // }
- if (alm_stDecCt.ulPhsALoss >= coef->ulPhsLossValCt || alm_stDecCt.ulPhsBLoss >= coef->ulPhsLossValCt ||
- alm_stDecCt.ulPhsCLoss >= coef->ulPhsLossValCt) // 5s
- {
- alm_stDecCt.ulPhsALoss = coef->ulPhsLossValCt;
- alm_stDecCt.ulPhsBLoss = coef->ulPhsLossValCt;
- alm_stDecCt.ulPhsCLoss = coef->ulPhsLossValCt;
- //alm_unAction.bit.PWMOff = TRUE;
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- alm_unCode.bit.PhsLoss = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulPhsALoss = 0;
- alm_stDecCt.ulPhsBLoss = 0;
- alm_stDecCt.ulPhsCLoss = 0;
- }
- /*=======================================================================
- Set AlmTbcDetectFlg
- =======================================================================*/
- alm_pvt_blTbcFirstFlg = FALSE;
- }
- else
- {
- /*=======================================================================
- Rotor lock for position sensor: switchhall
- =======================================================================*/
- if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
- {
- if (curSpeed_state.state == ClzLoop)
- {
- if(abs(in->swIqRefPu) > coef->slIqRefLpfAbsValPu && in->uwSpdFbkLpfAbsPu < coef->slSpdFbLpfAbsValPu)
- {
- alm_stDecCt.slRotorLock++;
- if (alm_stDecCt.slRotorLock >= coef->slRotorLockValCt)
- {
- alm_stDecCt.slRotorLock = coef->slRotorLockValCt;
- //alm_unAction.bit.PWMOff = TRUE;
- alm_unCode.bit.RotorLock = TRUE;
- }
- }
- else
- {
- alm_stDecCt.slRotorLock = 0;
- }
- }
- }
- // else if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
- // {
- // /*=======================================================================
- // Rotor lock for sensorless
- // =======================================================================*/
- // alm_pvt_swSpdRefAbsPu = in->uwSpdRefAbsPu; // Q15
- //
- // alm_pvt_swIqRefAbsPu = abs(in->swIqRefPu);
- // alm_pvt_slIqRefLpfAbsPu = (SLONG)0x0010 * (alm_pvt_swIqRefAbsPu - alm_pvt_swIqRefLpfAbsPu) + alm_pvt_slIqRefLpfAbsPu; // Q30
- // alm_pvt_swIqRefLpfAbsPu = alm_pvt_slIqRefLpfAbsPu >> 15;
- //
- // alm_pvt_swSpdFbAbsPu = in->uwSpdFbkLpfAbsPu; // Q15
- // alm_pvt_slSpdFbLpfAbsPu = (SLONG)0x0010 * (alm_pvt_swSpdFbAbsPu - alm_pvt_swSpdFbLpfAbsPu) + alm_pvt_slSpdFbLpfAbsPu; // Q30
- // alm_pvt_swSpdFbLpfAbsPu = alm_pvt_slSpdFbLpfAbsPu >> 15; // Q15
- //
- // if (((curSpeed_state.state == ClzLoop) || (curSpeed_state.state == StartUp)) && (in->uwSpdRefAbsPu > 0))
- // {
- // swTmp1 = (in->swIalhpaPu * in->swIalhpaPu + in->swIbetaPu * in->swIbetaPu) >> 14; // Q14=Q14+Q14-Q14
- // swTmp2 = swTmp1 * coef->uwRsPu >> 14; // Q15=Q14+Q15-Q14
- // alm_pvt_uwResPwrWt = swTmp2 * coef->uwPbWt >> 15; // unit: 0.1w
- // if ((in->swMotorPwrInWt > 0) && (alm_pvt_swIqRefLpfAbsPu > coef->slIqRefLpfAbsValPu) &&
- // (alm_pvt_swSpdFbLpfAbsPu < coef->slSpdFbLpfAbsValPu))
- // {
- // alm_pvt_swRtLockPwrRatio = (SWORD)((SLONG)alm_pvt_uwResPwrWt * 100 / in->swMotorPwrInWt);
- // if (alm_pvt_uwResPwrWt > (coef->slRotorLockSpdK * in->swMotorPwrInWt >> 10)) // k = 0.5
- // {
- // alm_stDecCt.slRotorLock++;
- // if (alm_stDecCt.slRotorLock >= coef->slRotorLockValCt) // 4s
- // {
- // alm_stDecCt.slRotorLock = coef->slRotorLockValCt;
- // // alm_unAction.bit.ThrPhsShrt = TRUE;
- // alm_unAction.bit.PWMOff = TRUE;
- // alm_unCode.bit.RotorLock = TRUE;
- // }
- // }
- // else
- // {
- // alm_stDecCt.slRotorLock--;
- // if (alm_stDecCt.slRotorLock < 0)
- // {
- // alm_stDecCt.slRotorLock = 0;
- // }
- // }
- // }
- // else
- // {
- // alm_stDecCt.slRotorLock = 0;
- // }
- // }
- // else
- // {
- // alm_stDecCt.slRotorLock = 0;
- // }
- //
- // }
- /*=======================================================================
- Set AlmTbcDetectFlg
- =======================================================================*/
- alm_pvt_blTbcFirstFlg = TRUE;
- }
- /*========================== Alarm flag set ===========================*/
- if((alm_unCode.bit.OvrCur == 1) || (alm_unCode.bit.IPMFlt == 1))
- {
- alm_blAlmOccrFlg = TRUE;
- }
- else if ((alm_unCode.all != 0) || (alm_unBikeCode.all != 0))
- {
- alm_blWarnOccrFlg = TRUE;
- if(alm_pvt_ulWarn2ErrorCount > 24000)
- {
- alm_blAlmOccrFlg = TRUE;
- }
- else
- {
- alm_pvt_ulWarn2ErrorCount++;
- }
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voDetecTBSCoef(ALM_DETECTBS_COFIN *in, ALM_DETECTBS_COF *out)
- {
- if (in->uwFbHz < 1)
- {
- in->uwFbHz = 1;
- }
- if (in->uwUbVt < 1)
- {
- in->uwUbVt = 1;
- }
- out->ulOvrVltLvl1ValPu = ((ULONG)in->uwOvrVlt1Vt << 14) / in->uwUbVt;
- out->ulOvrVltLvl1ValCt = ((ULONG)in->uwOvrVlt1Tm * in->uwFTbsHz / 1000) >> 1;// TBS_S2CT(x) ((ULONG)(x)*FTBS_HZ)
- out->ulUndrVltLvl1ValPu = ((ULONG)in->uwUndrVlt1Vt << 14) / in->uwUbVt;
- out->ulUndrVltLvl1ValCt = ((ULONG)in->uwUndrVlt1Tm * in->uwFTbsHz / 1000) >> 1; // TBS_MS2CT(x) ((ULONG)(x)*FTBS_HZ/1000)
- out->slOvrSpdValPu = ((SLONG)in->uwOvrSpdRpm << 15) / 60 * in->uwPairs /
- in->uwFbHz; // SPD_RPM2PU(x) (((SLONG)(x)<<15)/60*MOTOR_PAIRS/FBASE) /* rpm to Pu(Q15) */
- out->ulOvrSpdValCt = ((ULONG)in->uwOvrSpdTm * in->uwFTbsHz / 1000) >> 1;
- out->uwIPMOvrHeatRecValCe = in->uwIpmOvrHeatRecCe;
- out->ulIPMOvrHeatValCt = ((ULONG)in->uwIpmOvrHeatTs * in->uwFTbsHz) >> 1;
- out->uwIPMOvrHeatValCe = in->uwIpmOvrHeatCe;
- out->uwMotorOvrHeatRecValCe = in->uwMotorOvrHeatRecCe;
- out->ulMotorOvrHeatValCt = ((ULONG)in->uwMotorOvrHeatTs * in->uwFTbsHz) >> 1;
- out->uwMotorOvrHeatValCe = in->uwMotorOvrHeatCe;
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
- {
- if (alm_pvt_blTbsFirstFlg == FALSE)
- {
- /*=======================================================================
- Over voltage
- =======================================================================*/
- if (in->uwVdcPu > coef->ulOvrVltLvl1ValPu) // 45V
- {
- alm_stDecCt.ulOvrVltLvl1++;
- if (alm_stDecCt.ulOvrVltLvl1 >= coef->ulOvrVltLvl1ValCt) // 1ms
- {
- alm_stDecCt.ulOvrVltLvl1 = coef->ulOvrVltLvl1ValCt;
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- alm_unCode.bit.OvrVlt = TRUE;
- //alm_unAction.bit.PWMOff = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulOvrVltLvl1 = 0;
- }
-
- /*=======================================================================
- Under voltage
- =======================================================================*/
- if (in->uwVdcCompPu < coef->ulUndrVltLvl1ValPu) // 160v
- {
- alm_stDecCt.ulUndrVltLvl1++;
- if (alm_stDecCt.ulUndrVltLvl1 >= coef->ulUndrVltLvl1ValCt) // 1000ms
- {
- alm_stDecCt.ulUndrVltLvl1 = coef->ulUndrVltLvl1ValCt;
- // alm_unAction.bit.PWMOff = TRUE;
- alm_unCode.bit.UndrVlt = TRUE;
- //alm_unAction.bit.PWMOff = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulUndrVltLvl1 = 0;
- }
- alm_pvt_blTbsFirstFlg = TRUE;
- }
- else
- {
- /*=======================================================================
- Over speed
- =======================================================================*/
- if (in->uwSpdFbkLpfAbsPu > coef->slOvrSpdValPu) // 6000rpm
- {
- alm_stDecCt.ulOvrSpd++;
- if (alm_stDecCt.ulOvrSpd >= coef->ulOvrSpdValCt) // 100ms
- {
- alm_stDecCt.ulOvrSpd = coef->ulOvrSpdValCt;
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- alm_unCode.bit.OvrSpd = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulOvrSpd = 0;
- }
- /*=======================================================================
- over heat
- =======================================================================*/
- if (alm_pvt_blIPMOTReCheckFlg == TRUE)
- {
- if (in->swIPMTempCe > coef->uwIPMOvrHeatRecValCe) // 70
- {
- alm_stDecCt.ulIPMOvrHeat1++;
- if (alm_stDecCt.ulIPMOvrHeat1 >= coef->ulIPMOvrHeatValCt) // 2s
- {
- alm_stDecCt.ulIPMOvrHeat1 = coef->ulIPMOvrHeatValCt;
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- //alm_unAction.bit.PWMOff = TRUE;
- alm_unCode.bit.IPMOvrHeat = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulIPMOvrHeat1 = 0;
- }
- }
- else
- {
- if (in->swIPMTempCe > coef->uwIPMOvrHeatValCe) // 85
- {
- alm_stDecCt.ulIPMOvrHeat++;
- if (alm_stDecCt.ulIPMOvrHeat >= coef->ulIPMOvrHeatValCt) // 2s
- {
- alm_stDecCt.ulIPMOvrHeat = coef->ulIPMOvrHeatValCt;
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- //alm_unAction.bit.PWMOff = TRUE;
- alm_unCode.bit.IPMOvrHeat = TRUE;
- alm_pvt_blIPMOTReCheckFlg = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulIPMOvrHeat = 0;
- }
- }
-
- /*=======================================================================
- Motor over heat
- =======================================================================*/
- if (alm_pvt_blMotorOTReCheckFlg == TRUE)
- {
- if (in->uwMotorTempCe > coef->uwMotorOvrHeatRecValCe) // 70
- {
- alm_stDecCt.ulMotorOvrHeat1++;
- if (alm_stDecCt.ulMotorOvrHeat1 >= coef->ulMotorOvrHeatValCt) // 2s
- {
- alm_stDecCt.ulMotorOvrHeat1 = coef->ulMotorOvrHeatValCt;
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- //alm_unAction.bit.PWMOff = TRUE;
- alm_unCode.bit.MotorOvrHeat = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulMotorOvrHeat1 = 0;
- }
- }
- else
- {
- if (in->uwMotorTempCe > coef->uwMotorOvrHeatValCe) // 85
- {
- alm_stDecCt.ulMotorOvrHeat++;
- if (alm_stDecCt.ulMotorOvrHeat >= coef->ulMotorOvrHeatValCt) // 2s
- {
- alm_stDecCt.ulMotorOvrHeat = coef->ulMotorOvrHeatValCt;
- // alm_unAction.bit.ThrPhsShrt = TRUE;
- //alm_unAction.bit.PWMOff = TRUE;
- alm_unCode.bit.MotorOvrHeat = TRUE;
- alm_pvt_blMotorOTReCheckFlg = TRUE;
- }
- }
- else
- {
- alm_stDecCt.ulMotorOvrHeat = 0;
- }
- }
- /*=======================================================================
- Hall loss // MPS position loss
- =======================================================================*/
- if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
- {
- if(((in->uwSectorNum == 0)||(in->uwSectorNum == 7)))
- {
- alm_stDecCt.ulHallLoss ++;
- }
- else
- {
- alm_stDecCt.ulHallLoss = 0;
- }
- }
- else
- {
- alm_stDecCt.ulHallLoss = 0;
- }
- #if 0//(EMCDEAL_EN != 0)
- if(EcmDeal.EmcModeFlag==TRUE)
- {
- alm_stDecCt.ulHallLoss=0;
- }
- else
- #endif
- {
- #if(EMCDEAL_EN!=0)
- if(alm_stDecCt.ulHallLoss >= 2)
- #else
- if(alm_stDecCt.ulHallLoss >= 50) //250ms
- #endif
- {
- alm_stDecCt.ulHallLoss = 0;
- //alm_unAction.bit.PWMOff = TRUE;
- alm_unCode.bit.HallLoss = TRUE;
- }
- }
- // cp_stHistoryPara.uwPosSensorAlamTimes++;
-
- /*=======================================================================
- Communication over time
- =======================================================================*/
- // if (uart_bCommOvrTmFlg)
- // {
- // alm_unAction.bit.PWMOff = TRUE;
- // // alm_unAction.bit.ThrPhsShrt = TRUE;
- // alm_unCode.bit.CommOvrTm = TRUE;
- // }
- alm_pvt_blTbsFirstFlg = FALSE;
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voHandleTBC(ALM_IN *in)
- {
- /* Alarm occur */
- if (alm_blAlmOccrFlg)
- {
- /* mircfault */
- // if(clasB_unFaultCode.all)
- // {
- // if(scm_stSpdFbkLpf.slY.sw.hi < SPD_RPM2PU(10))//puֵ Լ10rpm
- // {
- // NVIC_SystemReset();
- // }
- // }
- /* Alarm handle FSM */
- switch (alm_enFSMStatus)
- {
- case Alm_Stop:
- alm_voStopTBC(in, &alm_stStopTbcCoef); /* Stop in TBC */
- if (cmfsm_stFlg.blMotorStopFlg)
- {
- sysfsm_stFlg.blFSMRstOvrFlg = FALSE; /* Enable control mode FSM reset */
- sysfsm_stFlg.blCtrlMdVarClcOvrFlg = FALSE; /* Enable control mode variable clear */
- alm_enFSMStatus = Alm_VarClc;
- }
- break;
- case Alm_VarClc:
- if (sysfsm_stFlg.blFSMRstOvrFlg && sysfsm_stFlg.blCtrlMdVarClcOvrFlg)
- {
- alm_enFSMStatus = Alm_Reset;
- }
- break;
- case Alm_Reset:
- alm_voReset(in, &alm_stResetCoef);
- break;
- default:
- break;
- }
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voHandleTBS(ALM_IN *in)
- {
- /* Alarm occur */
- if (alm_blAlmOccrFlg)
- {
- /* Alarm handle FSM */
- switch (alm_enFSMStatus)
- {
- case Alm_Stop:
- // alm_voStopTBS(); /* Stop in TBS */
- break;
- case Alm_VarClc:
- break;
- case Alm_Reset:
- // alm_voReset(in,&alm_stResetCoef);
- break;
- default:
- break;
- }
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voStopTBCCoef(ALM_STOPTBC_COFIN *in, ALM_STOPTBC_COF *out)
- {
- if (in->uwIbAp < 1)
- {
- in->uwIbAp = 1;
- }
- if (in->uwUbVt < 1)
- {
- in->uwUbVt = 1;
- }
- out->ulThrPhsShrtFrcValCt = ((ULONG)in->uwThrPhsShrtFrcTs * in->uwFTbcHz) / 1000; // TBC_S2CT(x) ((ULONG)(x)*FTBC_HZ)
- out->ulStopCurValCt = ((ULONG)in->uwIPMOverCurStopTs * in->uwFTbcHz) / 1000;
- out->ulPWMOffShrt1SwValCt = ((ULONG)in->uwPwmoffShrt1SwTs * in->uwFTbcHz) / 1000;
- out->ulShrtPWMOffSwValCt = ((ULONG)in->uwShrtPwmoffSwTs * in->uwFTbcHz) / 1000;
- out->ulPWMOffValCt = ((ULONG)in->uwPwmOffTs * in->uwFTbcHz) / 1000;
- out->ulThrPhsShrtNormValCt = ((ULONG)in->uwThrPhsShrtTs * in->uwFTbcHz) / 1000;
- out->ulOvrVltLvl1ValPu = (((ULONG)in->uwOvrVlt1Vt << 14) / in->uwUbVt) / 1000;
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voStopTBC(ALM_IN *in, ALM_STOPTBC_COF *coef)
- {
- if (alm_unAction.bit.ThrPhsShrtFrc)
- {
- if (MCU_BRKIN_FLG)
- {
- hw_voPWMOff(); /* PWM off */
- MCU_BRKIN_FLG_CLR; /* Clear TIME0 break flag */
- MCU_POEN_FLG_EN; /* Enable TIME0 Channel outputs */
- alm_stStopCt.ulThrPhsShrtFrc++;
- if (alm_stStopCt.ulThrPhsShrtFrc > coef->ulThrPhsShrtFrcValCt) // 200ms
- {
- alm_stStopCt.uwRotorStopCnt++;
- if (alm_stStopCt.uwRotorStopCnt >= coef->ulStopCurValCt) // 100ms
- {
- hw_voPWMOff(); /* PWM off */
- cmfsm_stFlg.blMotorStopFlg = TRUE;
- alm_stStopCt.uwRotorStopCnt = coef->ulStopCurValCt;
- }
- }
- alm_stStopCt.ulShrtPWMOffSw = 0;
- }
- else
- {}
- }
- else if (alm_unAction.bit.PWMOff)
- {
- alm_stStopCt.ulPWMOffShrtSw++;
- alm_stStopCt.ulPWMOff++;
- if (alm_stStopCt.ulPWMOffShrtSw < coef->ulPWMOffShrt1SwValCt) // 100ms
- {
- hw_voPWMOff();
- alm_stStopCt.uwRotorStopCnt = 0;
- }
- // else if(alm_stStopCt.ulPWMOffShrtSw < coef->ulPWMOffShrt2SwValCt)
- // {
- // hw_voThrPhsShrt();
- // }
- else
- {
- alm_stStopCt.ulPWMOffShrtSw = 0;
- }
- if (alm_stStopCt.ulPWMOff > coef->ulPWMOffValCt) // 200ms
- {
- cmfsm_stFlg.blMotorStopFlg = TRUE;
- alm_stStopCt.ulPWMOff = 0;
- }
- alm_stStopCt.ulShrtPWMOffSw = 0;
- }
- else // if (alm_unAction.bit.ThrPhsShrt)
- {
- alm_stStopCt.ulShrtPWMOffSw++;
- alm_stStopCt.ulThrPhsShrt++;
- /* if (alm_stStopCt.ulShrtPWMOffSw < coef->ulThrPhsShrtNormValCt) // 100ms
- {
- hw_voThrPhsShrt(); // Three phase short
- }
- else*/ if (alm_stStopCt.ulShrtPWMOffSw < (coef->ulThrPhsShrtNormValCt + coef->ulShrtPWMOffSwValCt)) // 100ms + 100ms
- {
- hw_voPWMOff();
- if (in->uwVdcPu > coef->ulOvrVltLvl1ValPu) // over vol level1 43V
- {
- alm_stStopCt.ulShrtPWMOffSw = 0;
- }
- alm_stStopCt.uwRotorStopCnt = 0;
- }
- else
- {
- alm_stStopCt.ulShrtPWMOffSw = 0;
- }
- if (alm_stStopCt.ulThrPhsShrt > coef->ulThrPhsShrtFrcValCt) // 200ms
- {
- hw_voPWMOff(); /* PWM off */
- cmfsm_stFlg.blMotorStopFlg = TRUE;
- alm_stStopCt.ulThrPhsShrt = 0;
- }
- alm_stStopCt.ulPWMOffShrtSw = 0;
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voStopTBS(void)
- {
- // if (alm_unAction.bit.SlowDwn)
- // {
- // acm_voAlmCtrMdTbs();
- // }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voResetCoef(ALM_RESET_COFIN *in, ALM_RESET_COF *out)
- {
- if (in->uwUbVt < 1)
- {
- in->uwUbVt = 1;
- }
- out->ulRecAllValCt = ((ULONG)in->uwRecAllTs * in->uwFTbcHz) / 1000; // TBC_S2CT(x) ((ULONG)(x)*FTBC_HZ)
- out->ulIPMOcRecValCt = ((ULONG)in->uwIpmOcRecTs * in->uwFTbcHz) / 1000;
- out->ulOvrVltRecValPu = ((ULONG)in->uwOvrVltRecVt << 14) / in->uwUbVt;
- out->ulOvrVltRecValCt = ((ULONG)in->uwOvrVltRecTs * in->uwFTbcHz) / 1000;
- out->ulUndrVltRecValPu = ((ULONG)in->uwUndrVltRecVt << 14) / in->uwUbVt;
- out->ulUndrVltRecValCt = ((ULONG)in->uwUndrVltRecTs * in->uwFTbcHz) / 1000;
- out->uwIPMOvrHeatRecValCe = in->uwIpmOvrHeatRecCe;
- out->ulIPMOvrHeatRecValCt = ((ULONG)in->uwIpmOvrHeatRecTs * in->uwFTbcHz);
- out->ulIPMOvrHeatRec1ValCt = ((ULONG)in->uwIpmOvrHeatRec1Ts * in->uwFTbcHz);
- out->uwMotorOvrHeatRecValCe = in->uwMotorOvrHeatRecCe;
- out->ulMotorOvrHeatRecValCt = ((ULONG)in->uwMotorOvrHeatRecTs * in->uwFTbcHz);
- out->ulMotorOvrHeatRec1ValCt = ((ULONG)in->uwMotorOvrHeatRec1Ts * in->uwFTbcHz);
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voReset(ALM_IN *in, ALM_RESET_COF *coef)
- {
- /*=======================================================================
- Recover condition
- =======================================================================*/
- /* Recover time of global */
- if (alm_stRecCt.ulGlbl < coef->ulRecAllValCt) // 200ms
- {
- alm_stRecCt.ulGlbl++;
- }
- /* Recover time of IPM OC */
- if (alm_stRecCt.ulIPMOC < coef->ulIPMOcRecValCt) // 100ms
- {
- alm_stRecCt.ulIPMOC++;
- }
- /* Recover time of over voltage */
- if (in->uwVdcPu < coef->ulOvrVltRecValPu) // 450v
- {
- if (alm_stRecCt.ulOvrVlt < coef->ulOvrVltRecValCt) // 100ms
- {
- alm_stRecCt.ulOvrVlt++;
- }
- }
- /* Recover time of under voltage */
- if (in->uwVdcPu > coef->ulUndrVltRecValPu) // 30v
- {
- if (alm_stRecCt.ulUndrVlt < coef->ulUndrVltRecValCt) // 100ms
- {
- alm_stRecCt.ulUndrVlt++;
- }
- }
- /* Recover time of IPM over heat */
- if (in->swIPMTempCe < coef->uwIPMOvrHeatRecValCe) // 75
- {
- if (alm_stRecCt.ulIPMOvrHeat < coef->ulIPMOvrHeatRecValCt) // 60s
- {
- alm_stRecCt.ulIPMOvrHeat++;
- }
- alm_stRecCt.ulIPMOvrHeat1 = 0;
- }
- else
- {
- if (alm_stRecCt.ulIPMOvrHeat1 < coef->ulIPMOvrHeatRec1ValCt) // 120s
- {
- alm_stRecCt.ulIPMOvrHeat1++;
- }
- alm_stRecCt.ulIPMOvrHeat = 0;
- }
- /*=======================================================================
- Alarm code clear
- =======================================================================*/
- if (alm_stRecCt.ulGlbl >= coef->ulRecAllValCt) // 200ms
- {
- /* IPM fault */
- if ((alm_unCode.bit.IPMFlt) && (alm_stRecCt.ulIPMOC >= coef->ulIPMOcRecValCt))
- {
- MCU_BRKIN_FLG_CLR; /* Clear TIME0 break flag */
- MCU_POEN_FLG_EN; /* Enable TIME0 Channel outputs */
- // DL_GPIO_clearPins(GPIOA, DL_GPIO_PIN_31);
- alm_unCode.bit.IPMFlt = FALSE;
- // IO_FTESTLED_OFF();// DL_TimerG_setCaptureCompareValue(PWM_F_INST, 0, GPIO_PWM_F_C1_IDX); //指示 test
- }
- /* Over current */
- if (alm_unCode.bit.OvrCur)
- {
- alm_stDecCt.ulOvrCur = 0;
- alm_unCode.bit.OvrCur = FALSE;
- }
- /* Over voltage */
- if (alm_unCode.bit.OvrVlt)
- {
- if (alm_stRecCt.ulOvrVlt >= coef->ulOvrVltRecValCt) // 4s 20s
- {
- alm_stDecCt.ulOvrVltLvl1 = 0;
- alm_unCode.bit.OvrVlt = FALSE;
- }
- }
- /* Under voltage */
- if (alm_unCode.bit.UndrVlt)
- {
- if (alm_stRecCt.ulUndrVlt >= coef->ulUndrVltRecValCt) // 4s 20s
- {
- alm_stDecCt.ulUndrVltLvl1 = 0;
- alm_unCode.bit.UndrVlt = FALSE;
- }
- }
- /* IPM over heat */
- if (alm_unCode.bit.IPMOvrHeat)
- {
- if (alm_stRecCt.ulIPMOvrHeat >= coef->ulIPMOvrHeatRecValCt)
- {
- alm_stDecCt.ulIPMOvrHeat = 0;
- alm_stDecCt.ulIPMOvrHeat1 = 0;
- alm_unCode.bit.IPMOvrHeat = FALSE;
- alm_pvt_blIPMOTReCheckFlg = FALSE;
- }
- else if (alm_stRecCt.ulIPMOvrHeat1 >= coef->ulIPMOvrHeatRec1ValCt)
- {
- alm_stDecCt.ulIPMOvrHeat = 0;
- alm_stDecCt.ulIPMOvrHeat1 = 0;
- alm_unCode.bit.IPMOvrHeat = FALSE;
- alm_pvt_blIPMOTReCheckFlg = TRUE;
- }
- }
-
- /* Motor over heat */
- if (alm_unCode.bit.MotorOvrHeat)
- {
- if (alm_stRecCt.ulMotorOvrHeat >= coef->ulMotorOvrHeatRecValCt)
- {
- alm_stDecCt.ulMotorOvrHeat = 0;
- alm_stDecCt.ulMotorOvrHeat1 = 0;
- alm_unCode.bit.MotorOvrHeat = FALSE;
- alm_pvt_blMotorOTReCheckFlg = FALSE;
- }
- else if (alm_stRecCt.ulMotorOvrHeat1 >= coef->ulMotorOvrHeatRec1ValCt)
- {
- alm_stDecCt.ulMotorOvrHeat = 0;
- alm_stDecCt.ulMotorOvrHeat1 = 0;
- alm_unCode.bit.MotorOvrHeat = FALSE;
- alm_pvt_blMotorOTReCheckFlg = TRUE;
- }
- }
-
- /* Hall loss */
- if (alm_unCode.bit.HallLoss)
- {
- if(((in->uwSectorNum != 0)&&(in->uwSectorNum != 7))||(cp_stFlg.ThetaGetModelSelect != ANG_SWITCHHALL))
- {
- alm_stDecCt.ulHallLoss = 0;
- alm_unCode.bit.HallLoss = FALSE;
- }
- }
- /* Phase loss */
- if ((alm_unCode.bit.PhsLoss) && (signal_state.Assist == 0 && signal_state.Sensor == 0))
- {
- alm_stDecCt.ulPhsALoss = 0;
- alm_stDecCt.ulPhsBLoss = 0;
- alm_stDecCt.ulPhsCLoss = 0;
- alm_unCode.bit.PhsLoss = FALSE;
- }
- /* Rotor lock */
- if ((alm_unCode.bit.RotorLock) && (signal_state.Assist == 0 && signal_state.Sensor == 0))
- {
- alm_stDecCt.slRotorLock = 0;
- alm_unCode.bit.RotorLock = FALSE;
- }
-
- /* Over Speed */
- if(alm_unCode.bit.OvrSpd)
- {
- alm_stDecCt.ulOvrSpd = 0;
- alm_unCode.bit.OvrSpd = FALSE;
- }
- /* Communication over time */
- if (alm_unCode.bit.CommOvrTm)
- {
- alm_unCode.bit.CommOvrTm = FALSE;
- }
- if (alm_unCode.bit.ADCOffsetFlt)
- {
- /* ADC init */
- adc_stDownOut.ulIdcRegSum = 0;
- adc_stDownOut.ulUaRegSum = 0;
- adc_stDownOut.ulUbRegSum = 0;
- adc_stDownOut.ulUcRegSum = 0;
- adc_stDownOut.uwADCCalibCt = 0;
- adc_stDownOut.blADCCalibFlg = FALSE;
- adc_stUpOut.uwADCCalibCt = 0;
- adc_stUpOut.blADCCalibFlg = FALSE;
- sysfsm_stFlg.blADCInitOvrFlg = FALSE;
- alm_unCode.bit.ADCOffsetFlt = FALSE;
- }
- }
- /*=======================================================================
- Alarm flag clear
- =======================================================================*/
- if (!alm_unCode.all)
- {
- /* Clear alarm action */
- alm_unAction.all = 0;
- /* Clear stop count */
- alm_stStopCt.ulThrPhsShrtFrc = 0;
- alm_stStopCt.ulPWMOff = 0;
- alm_stStopCt.ulThrPhsShrt = 0;
- alm_stStopCt.uwRotorStopCnt = 0;
- alm_stStopCt.ulPWMOffShrtSw = 0;
- alm_stStopCt.ulShrtPWMOffSw = 0;
- /* Clear recover count */
- alm_stRecCt.ulGlbl = 0;
- alm_stRecCt.ulOvrVlt = 0;
- alm_stRecCt.ulOvrVlt1 = 0;
- alm_stRecCt.ulUndrVlt = 0;
- alm_stRecCt.ulUndrVlt1 = 0;
- alm_stRecCt.ulIPMOvrHeat = 0;
- alm_stRecCt.ulIPMOvrHeat1 = 0;
- alm_stRecCt.ulIPMOC = 0;
- /* Clear alarm flag */
- if(alm_unBikeCode.all == 0)
- {
- /* Clear alarm flag */
- alm_blAlmOccrFlg = FALSE;
- alm_blWarnOccrFlg = FALSE;
- alm_pvt_ulWarn2ErrorCount = 0;
- alm_blAlmSingleRecordDoneFlg = FALSE;
- }
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voHandleRst(void)
- {
- alm_enFSMStatus = Alm_Stop;
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voDetec200MSCoef(ALM_DETEC200MS_COFIN *in, ALM_DETEC200MS_COF *out)
- {
- if (in->uwFbHz < 1)
- {
- in->uwFbHz = 1;
- }
- out->swMotorSpdMinPu = (SWORD)(((SLONG)in->swMotorSpdMinRpm << 15) / (SWORD)60 * (SWORD)in->uwPairs / (SWORD)in->uwFbHz);
- out->uwTorqMinPu = (UWORD)(((ULONG)in->uwTorqMinNm << 14) / TORQUEBASE);
- out->uwBikeSpdFltCt = in->uwBikeSpdFltTs * in->uwFT200MSHz;
- out->uwCadenceFltCt = in->uwCadenceFltTs * in->uwFT200MSHz;
- out->uwTorqFltCt = in->uwTorqFltTs * in->uwFT200MSHz;
- out->uwThrottleFltCt = in->uwThrottleFltTs * in->uwFT200MSHz;
- out->uwPCBNTCFltCt = in->uwPCBNTCFltTs * in->uwFT200MSHz;
- out->uwMotorNTCFltCt = in->uwMotorNTCFltTs * in->uwFT200MSHz;
-
- out->uwTorqMaxReg = (UWORD)((ULONG)in->uwTorqMaxVol * 4096 / 33);
- out->uwTorqMinReg = (UWORD)((ULONG)in->uwTorqMinVol * 4096 / 33);
- out->uwThrottleMaxReg = (UWORD)((ULONG)in->uwThrottleMaxVol * 4096 / 33);
- out->uwThrottleMinReg = (UWORD)((ULONG)in->uwThrottleMinVol * 4096 / 33);
- out->uwNTCMaxReg = (UWORD)((ULONG)in->uwNTCMaxVol * 4096 / 33);
- out->uwNTCMinReg = (UWORD)((ULONG)in->uwNTCMinVol * 4096 / 33);
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voDetec200MS(const ALM_BIKE_IN *in, const ALM_DETEC200MS_COF *coef)
- {
- /* Bike speed sensor fault */
- if(in->uwCadenceFreqPu > 150 || in->swMotorSpdAbsPu > coef->swMotorSpdMinPu) // 0.2Hz 150
- {
- if(in->uwBikeSpdPu < 75) // 0.1hz 75
- {
- alm_stDecCt.uwBikeSpdFlt ++;
- if(alm_stDecCt.uwBikeSpdFlt >= coef->uwBikeSpdFltCt)
- {
- alm_stDecCt.uwBikeSpdFlt = coef->uwBikeSpdFltCt;
- alm_unBikeCode.bit.BikeSpdSen = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- }
- else if(in->blBikeSpdOvrFlg)
- {
- alm_unBikeCode.bit.BikeSpdSen = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- else
- {
- alm_stDecCt.uwBikeSpdFlt = 0;
- }
- }
- else
- {
- alm_stDecCt.uwBikeSpdFlt = 0;
- }
- if(power_stPowStateOut.blPowerStartupFlg == TRUE)
- {
- if(cp_stFlg.RunModelSelect == CadAssist) /* 纯踏频助力判断逻辑 */
- {
- /* Bike cadence sensor fault */
- if(in->blCadenceFreqOvrFlg)
- {
- alm_unBikeCode.bit.CadenceSen = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- }
- else if((cp_stFlg.RunModelSelect == TorqAssist) &&(power_stPowStateOut.blPowerStartupFlg == TRUE))/* 力矩中轴助力判断逻辑 */
- {
- /* Bike cadence sensor fault */
- if(in->uwBikeSpdPu > 475 && in->uwTroqPu > coef->uwTorqMinPu) //475-5km/h
- {
- if(in->uwCadenceFreqPu == 0)
- {
- alm_stDecCt.uwCadenceFlt ++;
- if(alm_stDecCt.uwCadenceFlt >= coef->uwCadenceFltCt)
- {
- alm_stDecCt.uwCadenceFlt = coef->uwCadenceFltCt;
- alm_unBikeCode.bit.CadenceSen = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- }
- else if(in->blCadenceFreqOvrFlg)
- {
- alm_unBikeCode.bit.CadenceSen = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- else
- {
- alm_stDecCt.uwCadenceFlt = 0;
- }
- }
- else
- {
- alm_stDecCt.uwCadenceFlt = 0;
- }
-
- /* Bike torque sensor fault */
- #ifdef TORSENSOR3NUM //三力距
- if((in->uwTroqReg1 < coef->uwTorqMinReg) || (in->uwTroqReg1 >= coef->uwTorqMaxReg) || \
- (in->uwTroqReg2 < coef->uwTorqMinReg) || (in->uwTroqReg2 >= coef->uwTorqMaxReg) || \
- (in->uwTroqReg3 < coef->uwTorqMinReg) || (in->uwTroqReg3 >= coef->uwTorqMaxReg)
- )
- {
- alm_stDecCt.uwTorqFlt ++;
- if(alm_stDecCt.uwTorqFlt >= coef->uwTorqFltCt)
- {
- alm_stDecCt.uwTorqFlt = coef->uwTorqFltCt;
- alm_unBikeCode.bit.TorqSen = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- }
- else
- {
- alm_stDecCt.uwTorqFlt = 0;
- }
- #else //单力矩
- if((in->uwTroqReg1 < coef->uwTorqMinReg) || (in->uwTroqReg1 >= coef->uwTorqMaxReg)) //Fault: U_Torq < 0.1V or >=3V
- {
- alm_stDecCt.uwTorqFlt ++;
- if(alm_stDecCt.uwTorqFlt >= coef->uwTorqFltCt)
- {
- alm_stDecCt.uwTorqFlt = coef->uwTorqFltCt;
- alm_unBikeCode.bit.TorqSen = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- }
- else
- {
- alm_stDecCt.uwTorqFlt = 0;
- }
- #endif
- }
- }
-
- /* Bike throttle fault */
- #if 0
- if(in->blThrottleExistFlg)
- {
- if((in->uwThrottleReg < coef->uwThrottleMinReg) || (in->uwThrottleReg >= coef->uwThrottleMaxReg)) // Fault: U_Throttle < 0.1V or >=3V
- {
- alm_stDecCt.uwThrottleFlt ++;
- if(alm_stDecCt.uwThrottleFlt >= coef->uwThrottleFltCt)
- {
- alm_stDecCt.uwThrottleFlt = coef->uwThrottleFltCt;
- alm_unBikeCode.bit.Throttle = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- }
- else
- {
- alm_stDecCt.uwThrottleFlt = 0;
- }
- }
- #endif
- /* PCB NTC fault */
- // if((in->uwPCBNTCReg < coef->uwNTCMinReg) || (in->uwPCBNTCReg > coef->uwNTCMaxReg)) // Fault: NTC>100k or <0.032k
- // {
- // alm_stDecCt.uwPCBNTCFlt ++;
- // if(alm_stDecCt.uwPCBNTCFlt >= coef->uwPCBNTCFltCt)
- // {
- // alm_stDecCt.uwPCBNTCFlt = coef->uwPCBNTCFltCt;
- // alm_unBikeCode.bit.PCBNTC = 1;
- // alm_unAction.bit.PWMOff = 1;
- // }
- // }
- // else
- // {
- // alm_stDecCt.uwPCBNTCFlt = 0;
- // }
-
- /* Motor NTC fault */
- if(in->blMotorNTCExistFlg)
- {
- if((in->uwMotorNTCReg < coef->uwNTCMinReg) || (in->uwMotorNTCReg > coef->uwNTCMaxReg)) // Fault: NTC>100k or <0.032k
- {
- alm_stDecCt.uwMotorNTCFlt ++;
- if(alm_stDecCt.uwMotorNTCFlt >= coef->uwMotorNTCFltCt)
- {
- alm_stDecCt.uwMotorNTCFlt = coef->uwMotorNTCFltCt;
- alm_unBikeCode.bit.MotorNTC = 1;
- // alm_unAction.bit.PWMOff = 1;
- }
- }
- else
- {
- alm_stDecCt.uwMotorNTCFlt = 0;
- }
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voHandle1MS(const ALM_BIKE_IN *in)
- {
- if(alm_unBikeCode.all != 0)
- {
- /* Alarm handle FSM */
- switch (alm_enBikeFSMStatus)
- {
- case Alm_Stop:
- if (alm_unAction.bit.PWMOff != 0)
- {
- alm_stStopCt.ulBikePWMOff++;
- hw_voPWMOff();
- // sysctrl_voPwmOff();
- if (alm_stStopCt.ulBikePWMOff > 200) // 200ms, SysFault_hook, Event 1ms
- {
- cmfsm_stFlg.blMotorStopFlg = TRUE;
- alm_stStopCt.ulBikePWMOff = 0;
- }
- }
-
- if (cmfsm_stFlg.blMotorStopFlg)
- {
- sysfsm_stFlg.blFSMRstOvrFlg = FALSE; // Enable control mode FSM reset
- sysfsm_stFlg.blCtrlMdVarClcOvrFlg = FALSE; // Enable control mode variable clear
- alm_enBikeFSMStatus = Alm_VarClc;
- }
- break;
- case Alm_VarClc:
- if (sysfsm_stFlg.blFSMRstOvrFlg && sysfsm_stFlg.blCtrlMdVarClcOvrFlg)
- {
- alm_enBikeFSMStatus = Alm_Reset;
- }
- break;
- case Alm_Reset:
- alm_voReset1MS(in, &alm_stReset1MSCoef, &alm_stDetect200MSCoef);
- break;
- default:
- break;
- }
-
- }
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voReset1MSCoef(const ALM_RESET1MS_COFIN *in, ALM_RESET1MS_COF *out)
- {
- out->ulRecAllValCt = (ULONG)in->uwBikeGlblTm * in->uwFT1MSHz / 1000;
- out->ulRecBikeSpdCt = (ULONG)in->uwBikeSpdFltTm * in->uwFT1MSHz / 1000;
- out->ulRecCadenceCt = (ULONG)in->uwCadenceFltTm * in->uwFT1MSHz / 1000;
- out->ulRecTorqCt = (ULONG)in->uwTorqFltTm * in->uwFT1MSHz / 1000;
- out->ulRecThrottleCt = (ULONG)in->uwThrottleFltTm * in->uwFT1MSHz / 1000;
- out->ulRecPCBNTCCt = (ULONG)in->uwPCBNTCFltTm * in->uwFT1MSHz / 1000;
- out->ulRecMotorNTCCt = (ULONG)in->uwMotorNTCFltTm * in->uwFT1MSHz / 1000;
- }
- /***************************************************************
- Function:
- Description:
- Call by:
- Input Variables:
- Output/Return Variables:
- Subroutine Call:
- Reference:
- ****************************************************************/
- void alm_voReset1MS(const ALM_BIKE_IN *in, const ALM_RESET1MS_COF *coef, const ALM_DETEC200MS_COF *detctcoef) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
- {
- /*=======================================================================
- Recover condition
- =======================================================================*/
- /* Recover time of global */
- if (alm_stRecCt.ulBikeGlbl < coef->ulRecAllValCt) // 1s
- {
- alm_stRecCt.ulBikeGlbl++;
- }
- /* Recover time of bike speed sensor fault */
- if((!in->blBikeSpdOvrFlg) && (in->uwBikeSpdPu > 0))
- {
- if(alm_stRecCt.ulBikeSpdFlt < coef->ulRecBikeSpdCt)
- {
- alm_stRecCt.ulBikeSpdFlt++;
- }
- }
-
- /* Recover time of bike candence sensor fault */
- if((!in->blCadenceFreqOvrFlg) && (in->uwCadenceFreqPu > 0))
- {
- if (alm_stRecCt.ulCadenceFlt < coef->ulRecCadenceCt)
- {
- alm_stRecCt.ulCadenceFlt++;
- }
- }
-
- /* Recover time of bike torque sensor fault */
- #ifdef TORSENSOR3NUM //三力距
- if((in->uwTroqReg1 > detctcoef->uwTorqMinReg) && (in->uwTroqReg1 < detctcoef->uwTorqMaxReg) && \
- (in->uwTroqReg2 > detctcoef->uwTorqMinReg) && (in->uwTroqReg2 < detctcoef->uwTorqMaxReg) && \
- (in->uwTroqReg3 > detctcoef->uwTorqMinReg) && (in->uwTroqReg3 < detctcoef->uwTorqMaxReg)
- )
- {
- if (alm_stRecCt.ulTorqFlt < coef->ulRecTorqCt)
- {
- alm_stRecCt.ulTorqFlt++;
- }
- }
- else
- {
- alm_stRecCt.ulTorqFlt = 0;
- }
- #else
- if((in->uwTroqReg1 > detctcoef->uwTorqMinReg) && (in->uwTroqReg1 < detctcoef->uwTorqMaxReg))
- {
- if (alm_stRecCt.ulTorqFlt < coef->ulRecTorqCt)
- {
- alm_stRecCt.ulTorqFlt++;
- }
- }
- else
- {
- alm_stRecCt.ulTorqFlt = 0;
- }
- #endif
- /* Recover time of bike throttle fault */
- if((in->uwThrottleReg > detctcoef->uwThrottleMinReg) && (in->uwThrottleReg < detctcoef->uwThrottleMaxReg))
- {
- if (alm_stRecCt.ulThrottleFlt < coef->ulRecThrottleCt)
- {
- alm_stRecCt.ulThrottleFlt++;
- }
- }
- else
- {
- alm_stRecCt.ulThrottleFlt = 0;
- }
-
- /* Recover time of PCB NTC fault */
- if((in->uwPCBNTCReg > detctcoef->uwNTCMinReg) && (in->uwThrottleReg < detctcoef->uwNTCMaxReg))
- {
- if (alm_stRecCt.ulPCBNTCFlt < coef->ulRecPCBNTCCt)
- {
- alm_stRecCt.ulPCBNTCFlt++;
- }
- }
- else
- {
- alm_stRecCt.ulPCBNTCFlt = 0;
- }
-
- /* Recover time of motor NTC fault */
- if((in->uwPCBNTCReg > detctcoef->uwNTCMinReg) && (in->uwThrottleReg < detctcoef->uwNTCMaxReg))
- {
- if (alm_stRecCt.ulMotorNTCFlt < coef->ulRecMotorNTCCt)
- {
- alm_stRecCt.ulMotorNTCFlt++;
- }
- }
- else
- {
- alm_stRecCt.ulMotorNTCFlt = 0;
- }
-
- /*=======================================================================
- Alarm code clear
- =======================================================================*/
- if (alm_stRecCt.ulBikeGlbl >= coef->ulRecAllValCt)
- {
- /* Bike speed sensor fault */
- if((alm_unBikeCode.bit.BikeSpdSen != 0) && (alm_stRecCt.ulBikeSpdFlt >= coef->ulRecBikeSpdCt))
- {
- alm_stDecCt.uwBikeSpdFlt = 0;
- alm_unBikeCode.bit.BikeSpdSen = 0;
- }
-
- /* Bike cadence sensor fault */
- if((alm_unBikeCode.bit.CadenceSen != 0) && (alm_stRecCt.ulCadenceFlt >= coef->ulRecCadenceCt))
- {
- alm_stDecCt.uwCadenceFlt = 0;
- alm_unBikeCode.bit.CadenceSen = 0;
- }
-
- /* Bike torque sensor fault */
- if(((alm_unBikeCode.bit.TorqSen != 0) && (alm_stRecCt.ulTorqFlt >= coef->ulRecTorqCt))
- ||(cp_stFlg.RunModelSelect == ClZLOOP))
- {
- alm_stDecCt.uwTorqFlt = 0;
- alm_unBikeCode.bit.TorqSen = 0;
- }
-
- /* Bike throttle fault */
- if((alm_unBikeCode.bit.Throttle != 0) && (alm_stRecCt.ulThrottleFlt >= coef->ulRecThrottleCt))
- {
- alm_stDecCt.uwThrottleFlt = 0;
- alm_unBikeCode.bit.Throttle = 0;
- }
-
- /* PCB NTC fault */
- if((alm_unBikeCode.bit.PCBNTC != 0) && (alm_stRecCt.ulPCBNTCFlt >= coef->ulRecPCBNTCCt))
- {
- alm_stDecCt.uwPCBNTCFlt = 0;
- alm_unBikeCode.bit.PCBNTC = 0;
- }
-
- /* Motor NTC fault */
- if((alm_unBikeCode.bit.MotorNTC != 0) && (alm_stRecCt.ulMotorNTCFlt >= coef->ulRecMotorNTCCt))
- {
- alm_stDecCt.uwMotorNTCFlt = 0;
- alm_unBikeCode.bit.MotorNTC = 0;
- }
-
- }
-
- /*=======================================================================
- Alarm flag clear
- =======================================================================*/
- if(alm_unBikeCode.all == 0)
- {
- /* Clear stop count */
- alm_stStopCt.ulBikePWMOff = 0;
-
- /* Clear recover count */
- alm_stRecCt.ulBikeGlbl = 0;
- alm_stRecCt.ulBikeSpdFlt = 0;
- alm_stRecCt.ulCadenceFlt = 0;
- alm_stRecCt.ulTorqFlt = 0;
- alm_stRecCt.ulThrottleFlt = 0;
- alm_stRecCt.ulPCBNTCFlt = 0;
- alm_stRecCt.ulMotorNTCFlt = 0;
- }
- }
- /*************************************************************************
- Local Functions (N/A)
- *************************************************************************/
- /************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************/
- #ifdef _ALARM_C_
- #undef _ALARM_C_
- #endif
- /*************************************************************************
- End of this File (EOF):
- !!!!!!Do not put anything after this part!!!!!!!!!!!
- *************************************************************************/
|