tbc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 "user.h"
  26. #include "FSM_1st.h"
  27. #include "FSM_2nd.h"
  28. #include "spdctrmode.h"
  29. #include "queue.h"
  30. #include "canAppl.h"
  31. #include "alarm.h"
  32. #include "STLmain.h"
  33. /*************************************************************************
  34. Exported Functions (N/A)
  35. *************************************************************************/
  36. /***************************************************************
  37. Function: tbc_voIsr;
  38. Description: TBC interrupt service
  39. Call by:
  40. Input Variables: N/A
  41. Output/Return Variables: N/A
  42. Subroutine Call: ...;
  43. Reference: N/A
  44. ****************************************************************/
  45. UWORD timer1cnt;
  46. void tbc_voUpIsr(void)
  47. {
  48. /* Uart Monitor */
  49. UART_voAppMonitor();
  50. timer1cnt = TIMER_CNT(TIMER1);
  51. /* Motor Position Cal */
  52. if( cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER )
  53. {
  54. spi_voResolverLock();
  55. spi_voResolver(&spi_stResolverCoef, &spi_stResolverOut);
  56. }
  57. else if( cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL )
  58. {
  59. switchhall_voPosCalTbc();
  60. }
  61. else
  62. {
  63. //do noting
  64. }
  65. /* 1st FSM */
  66. FSM1st_Sys_state.Tbcup_hook();
  67. }
  68. /***************************************************************
  69. Function: tbc_voIsr;
  70. Description: TBC interrupt service
  71. Call by:
  72. Input Variables: N/A
  73. Output/Return Variables: N/A
  74. Subroutine Call: ...;
  75. Reference: N/A
  76. ****************************************************************/
  77. static BOOL tbc_pvt_blErrorFlag = FALSE;
  78. void tbc_voDownIsr(void)
  79. {
  80. /* ADC Sample */
  81. adc_voSampleUp(&adc_stCof, &adc_stUpOut);
  82. /* Alarm detect */
  83. alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
  84. alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu;
  85. alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt;
  86. alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
  87. alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu;
  88. alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu;
  89. alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu;
  90. alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu;
  91. alm_stIn.swIqRefPu = scm_swIqRefPu;
  92. alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;
  93. alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu;
  94. if (scm_swSpdRefPu >= 0)
  95. {
  96. alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
  97. }
  98. else
  99. {
  100. alm_stIn.uwSpdRefAbsPu = (UWORD)-scm_swSpdRefPu;
  101. }
  102. alm_stIn.uwIPMTempCe = adc_stUpOut.PCBTemp;
  103. alm_stIn.uwIdcOffset = adc_stCof.uwIdcOffset;
  104. alm_stIn.swDrumSpdAbsNowRpm = uart_swDrumSpdAbsNowRpm;
  105. alm_stIn.swDrumSpdAbsPreRpm = uart_swDrumSpdAbsPreRpm;
  106. alm_stIn.blSpiThetaFltFlg = spi_stResolverOut.blSpiThetaFltFlg;
  107. alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef);
  108. /* MCU Fault Detect */
  109. if((FALSE == UART_bInsertPendTx)&&(UART_bMonSwitch == FALSE))
  110. {
  111. stl_voTbcProc();
  112. }
  113. /* Error Log */
  114. switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
  115. if (switch_flg.SysFault_Flag == TRUE && tbc_pvt_blErrorFlag == FALSE)
  116. {
  117. tbc_pvt_blErrorFlag = TRUE;
  118. que_stErrorLog.ErrorCode = alm_unCode.all;
  119. que_stErrorLog.RunTime = MC_RunInfo.Ride_Time;
  120. que_stErrorLog.RunInfo = MC_RunInfo;
  121. que_stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
  122. que_stErrorLog.IqVoltagePu = scm_swUqRefPu;
  123. que_stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
  124. que_stErrorLog.IdVoltagePu = scm_swUdRefPu;
  125. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  126. }
  127. else if(switch_flg.SysFault_Flag == FALSE)
  128. {
  129. tbc_pvt_blErrorFlag = FALSE;
  130. }
  131. else
  132. {
  133. //do nothing
  134. }
  135. /* ADC Init Finish Flag */
  136. if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
  137. {
  138. sysfsm_stFlg.blADCInitOvrFlg = TRUE;
  139. }
  140. else
  141. {
  142. sysfsm_stFlg.blADCInitOvrFlg = FALSE;
  143. }
  144. /* ADC Sample */
  145. adc_voSampleDown(&adc_stCof, &adc_stDownOut);
  146. /* ADC Rdson Calibration with Single Resistance*/
  147. adc_voSRCalibration(&adc_stCof, &adc_stUpOut, &adc_stDownOut);
  148. /* 1st FSM */
  149. FSM1st_Sys_state.TbcDown_hook();
  150. }
  151. /*************************************************************************
  152. Local Functions (N/A)
  153. *************************************************************************/
  154. /*************************************************************************
  155. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  156. All rights reserved.
  157. *************************************************************************/
  158. #ifdef _TBC_C_
  159. #undef _TBC_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
  160. #endif
  161. /*************************************************************************
  162. End of this File (EOF)!
  163. Do not put anything after this part!
  164. *************************************************************************/