123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /************************************************************************
- Project: Welling Motor Control Paltform
- Filename: tbc.c
- Partner Filename: tbc.h
- Description: Time base for current loop
- 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 _TBC_C_
- #define _TBC_C_
- #endif
- /************************************************************************
- Included File
- *************************************************************************/
- #include "LoadObsTheta.h"
- #include "syspar.h"
- #include "user.h"
- #include "FSM_1st.h"
- #include "FSM_2nd.h"
- #include "spdctrmode.h"
- #include "queue.h"
- #include "canAppl.h"
- #include "alarm.h"
- #include "AngleObserver_discrete.h"
- //#include "profiler.h"
- //#include "STLmain.h"
- extern ExtU_LoadObsTheta_T LoadObsTheta_U;
- /*************************************************************************
- Exported Functions (N/A)
- *************************************************************************/
- /***************************************************************
- Function: tbc_voIsr;
- Description: TBC interrupt service
- Call by:
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: ...;
- Reference: N/A
- ****************************************************************/
- UWORD tst_CadIO = 0;
- void tbc_voUpIsr(void)
- {
- // PROFILER_START(1);
- // uart_voAppMonitor();
- // switchhall_voPosCalTbc();
- // tst_CadIO = iGpio_Read(HW_GPIO_CADENCE_PIN);
- //// /* Full Order Observer */
- //// LoadObsTheta_U.IqFbkPu = scm_swIqFdbLpfPu;
- //// LoadObsTheta_U.ThetamPu = switchhall_stOut.uwLowThetaPu;
- //// LoadObsTheta_step();
- //
- // /* Full Order Observer: Hall Angle Filter */
- // rtU.AngleIn = switchhall_stOut.uwLowThetaPu;
- // Trigger();
- //
- // FSM1st_Sys_state.Tbcup_hook();
- // PROFILER_END(1);
-
- // if( cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER )
- // {
- // /*Resolver lock data*/
- // //spi_voResolverLock();
- // /* Resolver data read */
- // // spi_voResolver(&spi_stResolverCoef, &spi_stResolverOut);
- // }
- // else if( cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL )
- // {
- // /*Switchhall Position Cal*/
- //
- // }
- // else
- // {
- //
- // }
- switchhall_voPosCalTbc(); //角度获取
- /* Full Order Observer */
- // LoadObsTheta_U.IqFbkPu = scm_swIqFdbLpfPu;
- // LoadObsTheta_U.ThetamPu = switchhall_stOut.uwLowThetaPu;
- // LoadObsTheta_step();
- /* Full Order Observer: Hall Angle Filter */
- rtU.AngleIn = switchhall_stOut.uwLowThetaPu;
- Trigger();
- FSM1st_Sys_state.Tbcup_hook(); //初始状态采集零点AD值,有故障时判断
- }
- /***************************************************************
- Function: tbc_voIsr;
- Description: TBC interrupt service
- Call by:
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: ...;
- Reference: N/A
- ****************************************************************/
- void tbc_voDownIsr(void)
- {
- // tst_CadIO = iGpio_Read(HW_GPIO_CADENCE_PIN);
- adc_voSampleUp(&adc_stCof, &adc_stUpOut);
- // if((FALSE == UART_bInsertPendTx)&&(UART_bMonSwitch == FALSE))
- // {
- // stl_voTbcProc();
- // }
- /* Alarm detect */
- alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
- alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu; // Q14
- alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt; // unit: 0.1w
- alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
- alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu; // Q14
- alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu; // Q14
- alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu; // Q14
- alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
- alm_stIn.swIqRefPu = scm_swIqRefPu;
- alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu; // Q14
- alm_stIn.uwVdcCompPu = adc_stUpOut.uwVdcLpfPu + BMS_VoltEstimat.uwVdcCompPu; // Q14
- alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu; // Q15
- if (scm_swSpdRefPu >= 0)
- {
- alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
- }
- else
- {
- alm_stIn.uwSpdRefAbsPu = (UWORD)(-scm_swSpdRefPu);
- }
- alm_stIn.swIPMTempCe = adc_stUpOut.PCBTemp;
- alm_stIn.uwMotorTempCe = adc_stUpOut.MotorTemp;
- alm_stIn.uwIdcOffset = adc_stCof.uwIdcOffset;
- alm_stIn.uwSectorNum = switchhall_stOut.uwSectorNum;
- alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef);
- /* System FSM */
- if (adc_stDownOut.blADCCalibFlg!=0)//自检完再切换状态机
- {
- switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
- switch_flg.SysWarnning_Flag = alm_blWarnOccrFlg;
- }
- // if (switch_flg.SysFault_Flag == TRUE)
- // {
- // que_stErrorLog.ErrorCode = alm_unCode.all;
- // que_stErrorLog.RunTime = MC_RunInfo.Ride_Time;
- // que_stErrorLog.RunInfo = MC_RunInfo;
- // que_stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
- // que_stErrorLog.IqVoltagePu = scm_swUqRefPu;
- // que_stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
- // que_stErrorLog.IdVoltagePu = scm_swUdRefPu;
- //
- // // que_ubPushIn( &stFlashErrorLog, &stErrorLog, 54 );
- // }
- if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
- {
- sysfsm_stFlg.blADCInitOvrFlg = TRUE;
- }
- else
- {
- sysfsm_stFlg.blADCInitOvrFlg = FALSE;
- }
- /* ADC sample */
- adc_voSampleDown(&adc_stCof, &adc_stDownOut);
- /* System FSM */
- FSM1st_Sys_state.TbcDown_hook();
-
- // adc_voSampleUp(&adc_stCof, &adc_stUpOut); //电流获取
- // /* Alarm detect */
- // alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
- //
- // alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu; // Q14
- // alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt; // unit: 0.1w
- // alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
- //
- // alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu; // Q14
- // alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu; // Q14
- // alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu; // Q14
- // alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
- // alm_stIn.swIqRefPu = scm_swIqRefPu;
- // alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu; // Q14
- // alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu; // Q15
- // if (scm_swSpdRefPu >= 0)
- // {
- // alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
- // }
- // else
- // {
- // alm_stIn.uwSpdRefAbsPu = (UWORD)(-scm_swSpdRefPu);
- // }
- // alm_stIn.uwIPMTempCe = adc_stUpOut.PCBTemp;
- // alm_stIn.uwIdcOffset = adc_stCof.uwIdcOffset;
- // alm_stIn.swDrumSpdAbsNowRpm = uart_swDrumSpdAbsNowRpm;
- // alm_stIn.swDrumSpdAbsPreRpm = uart_swDrumSpdAbsPreRpm;
- // alm_stIn.uwSectorNum = switchhall_stOut.uwSectorNum;
- // alm_stIn.uwBikeFrequencyPu = bikespeed_stFreGetOut.uwLPFFrequencyPu;
- // alm_stIn.uwCadFrequencyPu = cadence_stFreGetOut.uwFreqPercent;
- // // alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef); //缺相过流堵转故障判断
- // sys_unFaultCode.unalmcode = alm_unCode;
- //
- // /* System FSM */
- // switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
- // if (switch_flg.SysFault_Flag == TRUE)
- // {
- // stErrorLog.ErrorCode = alm_unCode.all;
- // stErrorLog.RunTime = MC_RunInfo.Ride_Time;
- // stErrorLog.RunInfo = MC_RunInfo;
- // stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
- // stErrorLog.IqVoltagePu = scm_swUqRefPu;
- // stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
- // stErrorLog.IdVoltagePu = scm_swUdRefPu;
- //
- // // que_ubPushIn( &stFlashErrorLog, &stErrorLog, 54 );
- // }
- //
- // if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
- // {
- // sysfsm_stFlg.blADCInitOvrFlg = TRUE;
- // }
- // else
- // {
- // sysfsm_stFlg.blADCInitOvrFlg = FALSE;
- // }
- //
- //
- // /* ADC sample */
- // adc_voSampleDown(&adc_stCof, &adc_stDownOut); //相电流采样读取
- //
- // /* ADC Rdson calibration with single resistance*/ //单电阻采样
- // adc_voSRCalibration(&adc_stCof, &adc_stUpOut, &adc_stDownOut);
- //
- // /* System FSM */
- // FSM1st_Sys_state.TbcDown_hook();
- }
- /*************************************************************************
- Local Functions (N/A)
- *************************************************************************/
- /*************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************/
- #ifdef _TBC_C_
- #undef _TBC_C_
- #endif
- /*************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|