tbc.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 "canAppl.h"
  31. #include "alarm.h"
  32. /*************************************************************************
  33. Exported Functions (N/A)
  34. *************************************************************************/
  35. /***************************************************************
  36. Function: tbc_voIsr;
  37. Description: TBC interrupt service
  38. Call by:
  39. Input Variables: N/A
  40. Output/Return Variables: N/A
  41. Subroutine Call: ...;
  42. Reference: N/A
  43. ****************************************************************/
  44. void tbc_voUpIsr(void)
  45. {
  46. /* Uart Monitor */
  47. uart_voAppMonitor();
  48. if( cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER )
  49. {
  50. spi_voResolverLock();
  51. spi_voResolver(&spi_stResolverCoef, &spi_stResolverOut);
  52. }
  53. else if( cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL )
  54. {
  55. switchhall_voPosCalTbc();
  56. }
  57. else
  58. {
  59. //do noting
  60. }
  61. /* 1st FSM */
  62. FSM1st_Sys_state.Tbcup_hook();
  63. #ifdef RUN_ARCH_SIM
  64. /* Inject */
  65. SWORD elecOmega = 0;
  66. UWORD gearstate = 0;
  67. INJ_PT(INT16, uart_slSpdRefRpm, 4);
  68. INJ_PT(INT16, spi_stResolverOut.uwSpiThetaPu, 0);
  69. INJ_PT(INT16, elecOmega, 1);
  70. INJ_PT(INT16, gearstate, 5);
  71. MC_ControlCode.GearSt =gearstate;
  72. spi_stResolverOut.swSpdFbkPu = ((SLONG)elecOmega << 15) / cof_uwWebRadps * 10;
  73. /* Watch */
  74. TEST_PT(INT, scm_uwAngParkPu, 0);
  75. TEST_PT(INT, scm_swSpdRefPu, 1);
  76. TEST_PT(INT, scm_stSpdFbkLpf.slY.sw.hi, 2);
  77. TEST_PT(INT, uart_slSpdRefRpm, 3);
  78. TEST_PT(INT, alm_unCode.all, 4);
  79. TEST_PT(INT, adc_stUpOut.uwVdcLpfPu, 5);
  80. TEST_PT(INT, scm_swIqRefPu, 6);
  81. TEST_PT(INT, scm_swIqFdbLpfPu, 7);
  82. TEST_PT(INT, adc_stDownOut.slSampIaPu, 8);
  83. TEST_PT(INT, adc_stDownOut.swIaPu, 9);
  84. TEST_PT(INT, adc_stUpOut.swCalibIaPu, 10);
  85. TEST_PT(INT, crd_stCurParkOut.swQPu, 11);
  86. #endif
  87. }
  88. /***************************************************************
  89. Function: tbc_voIsr;
  90. Description: TBC interrupt service
  91. Call by:
  92. Input Variables: N/A
  93. Output/Return Variables: N/A
  94. Subroutine Call: ...;
  95. Reference: N/A
  96. ****************************************************************/
  97. void tbc_voDownIsr(void)
  98. {
  99. /* ADC Sample with high priority */
  100. adc_voSampleUp_High(&adc_stCof, &adc_stUpOut);
  101. /* Alarm detect */
  102. alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
  103. alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu; // Q14
  104. alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt; // unit: 0.1w
  105. alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
  106. alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu; // Q14
  107. alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu; // Q14
  108. alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu; // Q14
  109. alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
  110. alm_stIn.swIqRefPu = scm_swIqRefPu;
  111. alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu; // Q14
  112. alm_stIn.uwVdcCompPu = adc_stUpOut.uwVdcLpfPu + BMS_VoltEstimat.uwVdcCompPu; // Q14
  113. alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu; // Q15
  114. if (scm_swSpdRefPu >= 0)
  115. {
  116. alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
  117. }
  118. else
  119. {
  120. alm_stIn.uwSpdRefAbsPu = (UWORD)(-scm_swSpdRefPu);
  121. }
  122. alm_stIn.uwIPMTempCe = adc_stUpOut.PCBTemp;
  123. alm_stIn.uwIdcOffset = adc_stCof.uwIdcOffset;
  124. // alm_stIn.swDrumSpdAbsNowRpm = uart_swDrumSpdAbsNowRpm;
  125. // alm_stIn.swDrumSpdAbsPreRpm = uart_swDrumSpdAbsPreRpm;
  126. alm_stIn.blSpiThetaFltFlg = spi_stResolverOut.blSpiThetaFltFlg;
  127. alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef);
  128. /* MCU Fault Detect */
  129. if((FALSE == UART_bInsertPendTx)&&(UART_bMonSwitch == FALSE))
  130. {
  131. stl_voTbcProc();
  132. }
  133. /* System FSM */
  134. switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
  135. if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
  136. {
  137. sysfsm_stFlg.blADCInitOvrFlg = TRUE;
  138. }
  139. else
  140. {
  141. sysfsm_stFlg.blADCInitOvrFlg = FALSE;
  142. }
  143. /* ADC sample */
  144. adc_voSampleDown(&adc_stCof, &adc_stDownOut);
  145. /* ADC Rdson calibration with single resistance*/
  146. adc_voSRCalibration(&adc_stCof, &adc_stUpOut, &adc_stDownOut);
  147. /* System FSM */
  148. FSM1st_Sys_state.TbcDown_hook();
  149. }
  150. /*************************************************************************
  151. Local Functions (N/A)
  152. *************************************************************************/
  153. /*************************************************************************
  154. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  155. All rights reserved.
  156. *************************************************************************/
  157. #ifdef _TBC_C_
  158. #undef _TBC_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
  159. #endif
  160. /*************************************************************************
  161. End of this File (EOF)!
  162. Do not put anything after this part!
  163. *************************************************************************/