tbc.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: tbc.c
  4. Partner Filename: tbc.h
  5. Description: Time base for current loop
  6. Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
  7. CPU TYPE : GD32F3x0
  8. *************************************************************************
  9. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  10. All rights reserved.
  11. *************************************************************************
  12. *************************************************************************
  13. Revising History (ECL of this file):
  14. ************************************************************************/
  15. /************************************************************************
  16. Beginning of File, do not put anything above here except notes
  17. Compiler Directives:
  18. *************************************************************************/
  19. #ifndef _TBC_C_
  20. #define _TBC_C_
  21. #endif
  22. /************************************************************************
  23. Included File
  24. *************************************************************************/
  25. #include "syspar.h"
  26. #include "user.h"
  27. #include "FSM_1st.h"
  28. #include "FSM_2nd.h"
  29. #include "spdctrmode.h"
  30. #include "queue.h"
  31. #include "canAppl.h"
  32. #include "alarm.h"
  33. #include "STLmain.h"
  34. /*************************************************************************
  35. Exported Functions (N/A)
  36. *************************************************************************/
  37. /***************************************************************
  38. Function: tbc_voIsr;
  39. Description: TBC interrupt service
  40. Call by:
  41. Input Variables: N/A
  42. Output/Return Variables: N/A
  43. Subroutine Call: ...;
  44. Reference: N/A
  45. ****************************************************************/
  46. void tbc_voUpIsr(void)
  47. {
  48. /* Uart Monitor */
  49. UART_voAppMonitor();
  50. /* Motor Position Cal */
  51. if( cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER )
  52. {
  53. spi_voResolverLock();
  54. spi_voResolver(&spi_stResolverCoef, &spi_stResolverOut);
  55. }
  56. else if( cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL )
  57. {
  58. switchhall_voPosCalTbc();
  59. }
  60. else
  61. {
  62. }
  63. /* 1st FSM */
  64. FSM1st_Sys_state.Tbcup_hook();
  65. }
  66. /***************************************************************
  67. Function: tbc_voIsr;
  68. Description: TBC interrupt service
  69. Call by:
  70. Input Variables: N/A
  71. Output/Return Variables: N/A
  72. Subroutine Call: ...;
  73. Reference: N/A
  74. ****************************************************************/
  75. BOOL tbc_pvt_blErrorFlag = 0;
  76. void tbc_voDownIsr(void)
  77. {
  78. /* ADC Sample */
  79. adc_voSampleUp(&adc_stCof, &adc_stUpOut);
  80. /* Alarm detect */
  81. alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
  82. alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu;
  83. alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt;
  84. alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
  85. alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu;
  86. alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu;
  87. alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu;
  88. alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu;
  89. alm_stIn.swIqRefPu = scm_swIqRefPu;
  90. alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;
  91. alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu;
  92. if (scm_swSpdRefPu >= 0)
  93. {
  94. alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
  95. }
  96. else
  97. {
  98. alm_stIn.uwSpdRefAbsPu = (UWORD)(-scm_swSpdRefPu);
  99. }
  100. alm_stIn.uwIPMTempCe = adc_stUpOut.PCBTemp;
  101. alm_stIn.uwIdcOffset = adc_stCof.uwIdcOffset;
  102. alm_stIn.swDrumSpdAbsNowRpm = uart_swDrumSpdAbsNowRpm;
  103. alm_stIn.swDrumSpdAbsPreRpm = uart_swDrumSpdAbsPreRpm;
  104. alm_stIn.blSpiThetaFltFlg = spi_stResolverOut.blSpiThetaFltFlg;
  105. alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef);
  106. /* MCU Fault Detect */
  107. if((FALSE == UART_bInsertPendTx)&&(UART_bMonSwitch == FALSE))
  108. {
  109. stl_voTbcProc();
  110. }
  111. /* Error Log */
  112. switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
  113. if (switch_flg.SysFault_Flag == TRUE && tbc_pvt_blErrorFlag == 0)
  114. {
  115. tbc_pvt_blErrorFlag = TRUE;
  116. stErrorLog.ErrorCode = alm_unCode.all;
  117. stErrorLog.RunTime = MC_RunInfo.Ride_Time;
  118. stErrorLog.RunInfo = MC_RunInfo;
  119. stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
  120. stErrorLog.IqVoltagePu = scm_swUqRefPu;
  121. stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
  122. stErrorLog.IdVoltagePu = scm_swUdRefPu;
  123. que_ubPushIn( &stFlashErrorLog, &stErrorLog, 1);
  124. }
  125. else if(switch_flg.SysFault_Flag == FALSE)
  126. {
  127. tbc_pvt_blErrorFlag = FALSE;
  128. }
  129. /* ADC Init Finish Flag */
  130. if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
  131. {
  132. sysfsm_stFlg.blADCInitOvrFlg = TRUE;
  133. }
  134. else
  135. {
  136. sysfsm_stFlg.blADCInitOvrFlg = FALSE;
  137. }
  138. /* ADC Sample */
  139. adc_voSampleDown(&adc_stCof, &adc_stDownOut);
  140. /* ADC Rdson Calibration with Single Resistance*/
  141. adc_voSRCalibration(&adc_stCof, &adc_stUpOut, &adc_stDownOut);
  142. /* 1st FSM */
  143. FSM1st_Sys_state.TbcDown_hook();
  144. }
  145. /*************************************************************************
  146. Local Functions (N/A)
  147. *************************************************************************/
  148. /*************************************************************************
  149. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  150. All rights reserved.
  151. *************************************************************************/
  152. #ifdef _TBC_C_
  153. #undef _TBC_C_
  154. #endif
  155. /*************************************************************************
  156. End of this File (EOF)!
  157. Do not put anything after this part!
  158. *************************************************************************/