tbc.c 9.4 KB

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