123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /************************************************************************
- 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 "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 "STLmain.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
- {
- }
- /* 1st FSM */
- FSM1st_Sys_state.Tbcup_hook();
- }
- /***************************************************************
- Function: tbc_voIsr;
- Description: TBC interrupt service
- Call by:
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: ...;
- Reference: N/A
- ****************************************************************/
- BOOL tbc_pvt_blErrorFlag = 0;
- 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 == 0)
- {
- tbc_pvt_blErrorFlag = 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, 1);
- }
- else if(switch_flg.SysFault_Flag == FALSE)
- {
- tbc_pvt_blErrorFlag = FALSE;
- }
- /* 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_
- #endif
- /*************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|