123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- /************************************************************************
- 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 "user.h"
- #include "FSM_1st.h"
- #include "FSM_2nd.h"
- #include "spdctrmode.h"
- #include "queue.h"
- #include "canAppl.h"
- #include "alarm.h"
- #include "STLmain.h"
- #include "api.h"
- /*************************************************************************
- 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
- ****************************************************************/
- void tbc_voUpIsr(void)
- {
- /* Uart Monitor */
- uart_voAppMonitor();
- /* Motor Position Cal */
- if( cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER )
- {
- spi_voResolverLock();
- spi_voResolver(&spi_stResolverCoef, &spi_stResolverOut);
- }
- else if( cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL )
- {
- switchhall_voPosCalTbc();
- }
- else
- {
- //do noting
- }
- /* 1st FSM */
- FSM1st_Sys_state.Tbcup_hook();
- #ifdef RUN_ARCH_SIM
- SWORD elecOmega = 0;
- INJ_PT(INT16, uart_slSpdRefRpm, 4);
- INJ_PT(INT16, spi_stResolverOut.uwSpiThetaPu, 0);
- INJ_PT(INT16, elecOmega, 1);
- spi_stResolverOut.swSpdFbkPu = ((SLONG)elecOmega << 15) / cof_uwWebRadps * 10;
-
- TEST_PT(INT, scm_uwAngParkPu, 0);
- TEST_PT(INT, scm_swSpdRefPu, 1);
- TEST_PT(INT, scm_stSpdFbkLpf.slY.sw.hi, 2);
- TEST_PT(INT, uart_slSpdRefRpm, 3);
- TEST_PT(INT, alm_unCode.all, 4);
- TEST_PT(INT, adc_stUpOut.uwVdcLpfPu, 5);
- TEST_PT(INT, scm_swIqRefPu, 6);
- TEST_PT(INT, scm_swIqFdbLpfPu, 7);
- TEST_PT(INT, adc_stDownOut.slSampIaPu, 8);
- TEST_PT(INT, adc_stDownOut.swIaPu, 9);
- TEST_PT(INT, adc_stUpOut.swCalibIaPu, 10);
- #endif
- }
- /***************************************************************
- Function: tbc_voIsr;
- Description: TBC interrupt service
- Call by:
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: ...;
- Reference: N/A
- ****************************************************************/
- static BOOL tbc_pvt_blErrorFlag = FALSE;
- void tbc_voDownIsr(void)
- {
- /* ADC Sample */
- adc_voSampleUp(&adc_stCof, &adc_stUpOut);
-
- /* Alarm detect */
- alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
- alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu;
- alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt;
- alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
- alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu;
- alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu;
- alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu;
- alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu;
- alm_stIn.swIqRefPu = scm_swIqRefPu;
- alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;
- alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu;
- 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.blSpiThetaFltFlg = spi_stResolverOut.blSpiThetaFltFlg;
- alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef);
-
- /* MCU Fault Detect */
- if((FALSE == UART_bInsertPendTx)&&(UART_bMonSwitch == FALSE))
- {
- stl_voTbcProc();
- }
- /* Error Log */
- switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
- if (switch_flg.SysFault_Flag == TRUE && tbc_pvt_blErrorFlag == FALSE)
- {
- tbc_pvt_blErrorFlag = 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(&que_stFlashErrorLog, &que_stErrorLog, 1);
- }
- else if(switch_flg.SysFault_Flag == FALSE)
- {
- tbc_pvt_blErrorFlag = FALSE;
- }
- else
- {
- //do nothing
- }
- /* ADC Init Finish Flag */
- 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);
- /* 1st 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_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
- #endif
- /*************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|