tbc.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 "LoadObsTheta.h"
  26. #include "syspar.h"
  27. #include "user.h"
  28. #include "FSM_1st.h"
  29. #include "FSM_2nd.h"
  30. #include "spdctrmode.h"
  31. #include "queue.h"
  32. #include "canAppl.h"
  33. #include "alarm.h"
  34. #include "AngleObserver_discrete.h"
  35. //#include "profiler.h"
  36. //#include "STLmain.h"
  37. extern ExtU_LoadObsTheta_T LoadObsTheta_U;
  38. /*************************************************************************
  39. Exported Functions (N/A)
  40. *************************************************************************/
  41. /***************************************************************
  42. Function: tbc_voIsr;
  43. Description: TBC interrupt service
  44. Call by:
  45. Input Variables: N/A
  46. Output/Return Variables: N/A
  47. Subroutine Call: ...;
  48. Reference: N/A
  49. ****************************************************************/
  50. UWORD tst_CadIO = 0;
  51. void tbc_voUpIsr(void)
  52. {
  53. // PROFILER_START(1);
  54. // uart_voAppMonitor();
  55. // switchhall_voPosCalTbc();
  56. // tst_CadIO = iGpio_Read(HW_GPIO_CADENCE_PIN);
  57. //// /* Full Order Observer */
  58. //// LoadObsTheta_U.IqFbkPu = scm_swIqFdbLpfPu;
  59. //// LoadObsTheta_U.ThetamPu = switchhall_stOut.uwLowThetaPu;
  60. //// LoadObsTheta_step();
  61. //
  62. // /* Full Order Observer: Hall Angle Filter */
  63. // rtU.AngleIn = switchhall_stOut.uwLowThetaPu;
  64. // Trigger();
  65. //
  66. // FSM1st_Sys_state.Tbcup_hook();
  67. // PROFILER_END(1);
  68. // if( cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER )
  69. // {
  70. // /*Resolver lock data*/
  71. // //spi_voResolverLock();
  72. // /* Resolver data read */
  73. // // spi_voResolver(&spi_stResolverCoef, &spi_stResolverOut);
  74. // }
  75. // else if( cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL )
  76. // {
  77. // /*Switchhall Position Cal*/
  78. //
  79. // }
  80. // else
  81. // {
  82. //
  83. // }
  84. switchhall_voPosCalTbc(); //角度获取
  85. /* Full Order Observer */
  86. // LoadObsTheta_U.IqFbkPu = scm_swIqFdbLpfPu;
  87. // LoadObsTheta_U.ThetamPu = switchhall_stOut.uwLowThetaPu;
  88. // LoadObsTheta_step();
  89. /* Full Order Observer: Hall Angle Filter */
  90. rtU.AngleIn = switchhall_stOut.uwLowThetaPu;
  91. Trigger();
  92. FSM1st_Sys_state.Tbcup_hook(); //初始状态采集零点AD值,有故障时判断
  93. }
  94. /***************************************************************
  95. Function: tbc_voIsr;
  96. Description: TBC interrupt service
  97. Call by:
  98. Input Variables: N/A
  99. Output/Return Variables: N/A
  100. Subroutine Call: ...;
  101. Reference: N/A
  102. ****************************************************************/
  103. void tbc_voDownIsr(void)
  104. {
  105. // tst_CadIO = iGpio_Read(HW_GPIO_CADENCE_PIN);
  106. adc_voSampleUp(&adc_stCof, &adc_stUpOut);
  107. // if((FALSE == UART_bInsertPendTx)&&(UART_bMonSwitch == FALSE))
  108. // {
  109. // stl_voTbcProc();
  110. // }
  111. /* Alarm detect */
  112. alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
  113. alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu; // Q14
  114. alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt; // unit: 0.1w
  115. alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
  116. alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu; // Q14
  117. alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu; // Q14
  118. alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu; // Q14
  119. alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
  120. alm_stIn.swIqRefPu = scm_swIqRefPu;
  121. alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu; // Q14
  122. alm_stIn.uwVdcCompPu = adc_stUpOut.uwVdcLpfPu + BMS_VoltEstimat.uwVdcCompPu; // Q14
  123. alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu; // Q15
  124. if (scm_swSpdRefPu >= 0)
  125. {
  126. alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
  127. }
  128. else
  129. {
  130. alm_stIn.uwSpdRefAbsPu = (UWORD)(-scm_swSpdRefPu);
  131. }
  132. alm_stIn.swIPMTempCe = adc_stUpOut.PCBTemp;
  133. alm_stIn.uwMotorTempCe = adc_stUpOut.MotorTemp;
  134. alm_stIn.uwIdcOffset = adc_stCof.uwIdcOffset;
  135. alm_stIn.uwSectorNum = switchhall_stOut.uwSectorNum;
  136. alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef);
  137. /* System FSM */
  138. if (adc_stDownOut.blADCCalibFlg!=0)//自检完再切换状态机
  139. switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
  140. // if (switch_flg.SysFault_Flag == TRUE)
  141. // {
  142. // que_stErrorLog.ErrorCode = alm_unCode.all;
  143. // que_stErrorLog.RunTime = MC_RunInfo.Ride_Time;
  144. // que_stErrorLog.RunInfo = MC_RunInfo;
  145. // que_stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
  146. // que_stErrorLog.IqVoltagePu = scm_swUqRefPu;
  147. // que_stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
  148. // que_stErrorLog.IdVoltagePu = scm_swUdRefPu;
  149. //
  150. // // que_ubPushIn( &stFlashErrorLog, &stErrorLog, 54 );
  151. // }
  152. if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
  153. {
  154. sysfsm_stFlg.blADCInitOvrFlg = TRUE;
  155. }
  156. else
  157. {
  158. sysfsm_stFlg.blADCInitOvrFlg = FALSE;
  159. }
  160. /* ADC sample */
  161. adc_voSampleDown(&adc_stCof, &adc_stDownOut);
  162. /* System FSM */
  163. FSM1st_Sys_state.TbcDown_hook();
  164. // adc_voSampleUp(&adc_stCof, &adc_stUpOut); //电流获取
  165. // /* Alarm detect */
  166. // alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
  167. //
  168. // alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu; // Q14
  169. // alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt; // unit: 0.1w
  170. // alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
  171. //
  172. // alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu; // Q14
  173. // alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu; // Q14
  174. // alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu; // Q14
  175. // alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
  176. // alm_stIn.swIqRefPu = scm_swIqRefPu;
  177. // alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu; // Q14
  178. // alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu; // Q15
  179. // if (scm_swSpdRefPu >= 0)
  180. // {
  181. // alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
  182. // }
  183. // else
  184. // {
  185. // alm_stIn.uwSpdRefAbsPu = (UWORD)(-scm_swSpdRefPu);
  186. // }
  187. // alm_stIn.uwIPMTempCe = adc_stUpOut.PCBTemp;
  188. // alm_stIn.uwIdcOffset = adc_stCof.uwIdcOffset;
  189. // alm_stIn.swDrumSpdAbsNowRpm = uart_swDrumSpdAbsNowRpm;
  190. // alm_stIn.swDrumSpdAbsPreRpm = uart_swDrumSpdAbsPreRpm;
  191. // alm_stIn.uwSectorNum = switchhall_stOut.uwSectorNum;
  192. // alm_stIn.uwBikeFrequencyPu = bikespeed_stFreGetOut.uwLPFFrequencyPu;
  193. // alm_stIn.uwCadFrequencyPu = cadence_stFreGetOut.uwFreqPercent;
  194. // // alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef); //缺相过流堵转故障判断
  195. // sys_unFaultCode.unalmcode = alm_unCode;
  196. //
  197. // /* System FSM */
  198. // switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
  199. // if (switch_flg.SysFault_Flag == TRUE)
  200. // {
  201. // stErrorLog.ErrorCode = alm_unCode.all;
  202. // stErrorLog.RunTime = MC_RunInfo.Ride_Time;
  203. // stErrorLog.RunInfo = MC_RunInfo;
  204. // stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
  205. // stErrorLog.IqVoltagePu = scm_swUqRefPu;
  206. // stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
  207. // stErrorLog.IdVoltagePu = scm_swUdRefPu;
  208. //
  209. // // que_ubPushIn( &stFlashErrorLog, &stErrorLog, 54 );
  210. // }
  211. //
  212. // if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
  213. // {
  214. // sysfsm_stFlg.blADCInitOvrFlg = TRUE;
  215. // }
  216. // else
  217. // {
  218. // sysfsm_stFlg.blADCInitOvrFlg = FALSE;
  219. // }
  220. //
  221. //
  222. // /* ADC sample */
  223. // adc_voSampleDown(&adc_stCof, &adc_stDownOut); //相电流采样读取
  224. //
  225. // /* ADC Rdson calibration with single resistance*/ //单电阻采样
  226. // adc_voSRCalibration(&adc_stCof, &adc_stUpOut, &adc_stDownOut);
  227. //
  228. // /* System FSM */
  229. // FSM1st_Sys_state.TbcDown_hook();
  230. }
  231. /*************************************************************************
  232. Local Functions (N/A)
  233. *************************************************************************/
  234. /*************************************************************************
  235. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  236. All rights reserved.
  237. *************************************************************************/
  238. #ifdef _TBC_C_
  239. #undef _TBC_C_
  240. #endif
  241. /*************************************************************************
  242. End of this File (EOF)!
  243. Do not put anything after this part!
  244. *************************************************************************/