tbc.c 9.5 KB

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