tbc.c 9.4 KB

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