user.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: user.h
  4. Partner Filename: Null
  5. Description: User parameters
  6. Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
  7. CPU TYPE : STM32F30x
  8. *************************************************************************
  9. Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
  10. All rights reserved.
  11. *************************************************************************
  12. *************************************************************************
  13. Revising History (ECL of this file):
  14. ************************************************************************/
  15. #ifndef USER_H
  16. #define USER_H
  17. /************************************************************************
  18. Compiler Directives
  19. *************************************************************************/
  20. #include "typedefine.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif // __cplusplus
  24. /************************************************************************
  25. Definitions & Macros
  26. *************************************************************************/
  27. /*======================================================================*
  28. Update Time
  29. 2021-06-21 13:47:04
  30. *=======================================================================*/
  31. /*======================================================================*
  32. Software version
  33. *=======================================================================*/
  34. #define SOFTWARE_VERSION 0x1C10
  35. #define SOFTWARE_VERSION_WELLING 0x0001
  36. /*======================================================================*
  37. Motor Parameters
  38. *=======================================================================*/
  39. /*======================================================================*
  40. Motor Number Selection
  41. *=======================================================================*/
  42. #define MOTOR_WELLING_CITY_36V 0x20
  43. #define MOTOR_WELLING_MTB_36V 0x21
  44. #define MOTOR_WELLING_CITY_48V 0x30
  45. #define MOTOR_WELLING_MTB_48V 0x31
  46. #define MOTOR_ID_SEL MOTOR_WELLING_MTB_48V
  47. #define GEARSENSOR_ENABLE 1 // 0-Uart,1-GearSensor
  48. // #define TEST //only use for testing
  49. /*======================================================================*
  50. ADC Maximum Value
  51. *=======================================================================*/
  52. //#if (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V || MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V)
  53. //#define ADC_IPHASE_CUR_MAX_AP 15600
  54. //#define ADC_IPHASE_CUR_OVER_K 780 // SWORD最大电流/采样最大电流=120A/156A=0.769=787(Q10)
  55. //#elif (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V)
  56. //#define ADC_IPHASE_CUR_MAX_AP 16500
  57. //#define ADC_IPHASE_CUR_OVER_K 1024
  58. //#else
  59. //#define ADC_IPHASE_CUR_MAX_AP 10355
  60. //#define ADC_IPHASE_CUR_OVER_K 1024
  61. //#endif
  62. #if (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V)
  63. #define ADC_IPHASE_CUR_MAX_AP 15600
  64. #define ADC_IPHASE_CUR_OVER_K 780 // SWORD最大电流/采样最大电流=120A/156A=0.769=787(Q10)
  65. #else
  66. #define ADC_IPHASE_CUR_MAX_AP 16500
  67. #define ADC_IPHASE_CUR_OVER_K 1024
  68. #endif
  69. /*======================================================================*
  70. 巡航Bike Cruise
  71. //指拨巡航功能 0xAA-指拨维持不动维持8秒,进入巡航功能,仪表出线巡航图标,刹车,0档,有助力踏频,重新调速,有故障会退出,else-无巡航功能
  72. *=======================================================================*/
  73. #define THOTTLECRUISE_EN 0x00 //0xAA-enable,else-disable
  74. /*======================================================================*
  75. NOT ZERO Ssart
  76. //0xAA-速度非零起动,速度大于3KM/H,转把才有效 ;else-车速为零可以转把启动
  77. *=======================================================================*/
  78. #define THOTTLE_STARTRUNATSPEED 0x00 //0xAA-enable,else-disable
  79. /*======================================================================*
  80. //转把分档
  81. *=======================================================================*/
  82. #define THROTTLEGEAR_ENABLE 0xAA //转把分档 0xAA-enable,else-disable
  83. /*======================================================================*
  84. Motor Parameters
  85. *=======================================================================*/
  86. #if (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V)
  87. #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
  88. #define M_RS_OHM 170 // unit: 0.1mOhm, Phase resistance
  89. #define M_MATERIAL Al // unit:Null
  90. #define M_LD_NOLOAD_MH 11000 // unit: 0.01uH, D axis inductance
  91. #define M_LQ_NOLOAD_MH 11500 // unit: 0.01uH, Q axis inductance
  92. #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
  93. #define M_LD_TURN1_LD_MH 11000 // unit: 0.01uH,D axis inductance
  94. #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
  95. #define M_LD_TURN2_LD_MH 11000 // unit: 0.01uH,D axis inductance
  96. #define M_LD_MIN_MH 11000 // unit: 0.01uH,D axis inductance
  97. #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
  98. #define M_LQ_TURN1_LQ_MH 11500 // unit: 0.01uH,Q axis inductance
  99. #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
  100. #define M_LQ_TURN2_LQ_MH 11500 // unit: 0.01uH,Q axis inductance
  101. #define M_LQ_MIN_MH 11500 // unit: 0.01uH,Q axis inductance
  102. #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
  103. #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
  104. #define M_FLUX_WB 5360 // unit: 0.001mWb, Flux linkage
  105. #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
  106. #define M_ID_MIN_AP -300 // unit: 0.01A, Min d axis current
  107. #define M_IS_PEAK_MAX_AP 5000 //5500 // unit: 0.01A, Max phase current(below base speed)
  108. #define M_POWER_MAX_WT 600 // unit: W, Max power
  109. #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
  110. #define M_R_PWR_WT 250 // unit: W, rate power
  111. #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
  112. #define M_R_UDC_v 360 // unit: 0.1V, rate Udc
  113. #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
  114. #elif (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V)
  115. #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
  116. #define M_RS_OHM 345 // unit: 0.1mOhm, Phase resistance
  117. #define M_MATERIAL Al // unit:Null
  118. #define M_LD_NOLOAD_MH 22250 // unit: 0.01uH, D axis inductance
  119. #define M_LQ_NOLOAD_MH 23000 // unit: 0.01uH, Q axis inductance
  120. #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
  121. #define M_LD_TURN1_LD_MH 22250 // unit: 0.01uH,D axis inductance
  122. #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
  123. #define M_LD_TURN2_LD_MH 22250 // unit: 0.01uH,D axis inductance
  124. #define M_LD_MIN_MH 22250 // unit: 0.01uH,D axis inductance
  125. #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
  126. #define M_LQ_TURN1_LQ_MH 23000 // unit: 0.01uH,Q axis inductance
  127. #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
  128. #define M_LQ_TURN2_LQ_MH 23000 // unit: 0.01uH,Q axis inductance
  129. #define M_LQ_MIN_MH 23000 // unit: 0.01uH,Q axis inductance
  130. #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
  131. #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
  132. #define M_FLUX_WB 8920 // unit: 0.001mWb, Flux linkage
  133. #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
  134. #define M_ID_MIN_AP -600 // unit: 0.01A, Min d axis current
  135. #define M_IS_PEAK_MAX_AP 3800 // unit: 0.01A, Max phase current(below base speed)
  136. #define M_POWER_MAX_WT 600 // unit: W, Max power
  137. #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
  138. #define M_R_PWR_WT 250 // unit: W, rate power
  139. #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
  140. #define M_R_UDC_v 480 // unit: 0.1V, rate Udc
  141. #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
  142. #elif (MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V)
  143. #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
  144. #define M_RS_OHM 297 // unit: 0.1mOhm, Phase resistance
  145. #define M_MATERIAL Al // unit:Null
  146. #define M_LD_NOLOAD_MH 16000 // unit: 0.01uH, D axis inductance
  147. #define M_LQ_NOLOAD_MH 16750 // unit: 0.01uH, Q axis inductance
  148. #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
  149. #define M_LD_TURN1_LD_MH 16000 // unit: 0.01uH,D axis inductance
  150. #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
  151. #define M_LD_TURN2_LD_MH 16000 // unit: 0.01uH,D axis inductance
  152. #define M_LD_MIN_MH 16000 // unit: 0.01uH,D axis inductance
  153. #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
  154. #define M_LQ_TURN1_LQ_MH 16750 // unit: 0.01uH,Q axis inductance
  155. #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
  156. #define M_LQ_TURN2_LQ_MH 16750 // unit: 0.01uH,Q axis inductance
  157. #define M_LQ_MIN_MH 16750 // unit: 0.01uH,Q axis inductance
  158. #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
  159. #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
  160. #define M_FLUX_WB 7336 // 5056 // unit: 0.001mWb, Flux linkage
  161. #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
  162. #define M_ID_MIN_AP -600 // unit: 0.01A, Min d axis current
  163. #define M_IS_PEAK_MAX_AP 3600 // unit: 0.01A, Max phase current(below base speed)
  164. #define M_POWER_MAX_WT 600 // unit: W, Max power
  165. #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
  166. #define M_R_PWR_WT 250 // unit: W, rate power
  167. #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
  168. #define M_R_UDC_v 360 // unit: 0.1V, rate Udc
  169. #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
  170. #elif (MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V)
  171. #define M_POLE_PAIRS 7 // unit:Null,Pole pairs
  172. #define M_RS_OHM 297 // unit: 0.1mOhm, Phase resistance
  173. #define M_MATERIAL Al // unit:Null
  174. #define M_LD_NOLOAD_MH 16000 // unit: 0.01uH, D axis inductance
  175. #define M_LQ_NOLOAD_MH 16750 // unit: 0.01uH, Q axis inductance
  176. #define M_LD_TURN1_ID_AP 5000 // unit: 0.01A,
  177. #define M_LD_TURN1_LD_MH 16000 // unit: 0.01uH,D axis inductance
  178. #define M_LD_TURN2_ID_AP 700 // unit: 0.01A,
  179. #define M_LD_TURN2_LD_MH 16000 // unit: 0.01uH,D axis inductance
  180. #define M_LD_MIN_MH 16000 // unit: 0.01uH,D axis inductance
  181. #define M_LQ_TURN1_IQ_AP 200 // unit: 0.01A,
  182. #define M_LQ_TURN1_LQ_MH 16750 // unit: 0.01uH,Q axis inductance
  183. #define M_LQ_TURN2_IQ_AP 700 // unit: 0.01A,
  184. #define M_LQ_TURN2_LQ_MH 16750 // unit: 0.01uH,Q axis inductance
  185. #define M_LQ_MIN_MH 16750 // unit: 0.01uH,Q axis inductance
  186. #define M_JD 2500 // unit: 10-7Kg*m2, Rotational inertia
  187. #define M_MAGNETIC_MATERIAL Ferrite // unit:Null
  188. #define M_FLUX_WB 7336 // 5056 // unit: 0.001mWb, Flux linkage
  189. #define M_ID_MAX_AP 0 //-25 // unit: 0.01A, Max d axis current
  190. #define M_ID_MIN_AP -600 // unit: 0.01A, Min d axis current
  191. #define M_IS_PEAK_MAX_AP 3600 // unit: 0.01A, Max phase current(below base speed)
  192. #define M_POWER_MAX_WT 600 // unit: W, Max power
  193. #define M_R_SPD_RPM 5000 // unit: r/min, rate spd
  194. #define M_R_PWR_WT 250 // unit: W, rate power
  195. #define M_R_IRMS_A 2500 // unit: 0.01A, rate Irms
  196. #define M_R_UDC_v 480 // unit: 0.1V, rate Udc
  197. #define M_MAX_TOR_NM 30 // unit: 0.1Nm, Max tor
  198. #endif
  199. /*======================================================================*
  200. IPM Paremeters
  201. *=======================================================================*/
  202. /* SL IPM */
  203. #define IPM_TURN_ON_TM_NS 300 // 86 // unit:ns
  204. #define IPM_TURN_OFF_TM_NS 300 // 105 // unit:ns
  205. #define IPM_DEAD_TM_NS 1000 // unit:ns
  206. #define IPM_HVIC_CHRG_TM 20 // unit: ms,Bootstrap capacitor charge time
  207. /*======================================================================*
  208. Alarm threshold value & time of duration define
  209. *=======================================================================*/
  210. /* Over current */
  211. #define ALM_OVR_CNT_VAL 6400 // unit: 0.01A, Threshold value
  212. #define ALM_OVR_CNT_TM 500 // unit: us, Time of duration(TBC)
  213. /* Phase loss */
  214. #define ALM_PHS_LOSS_VAL 50 // unit: 0.01A, Threshold value
  215. #define ALM_PHS_LOSS_TM 5 // unit: s, Time of duration(TBC)
  216. /* Rotor lock */
  217. #define ALM_ROTOR_LOCK_SPD_K 30 // unit: %, Q10, Ratio of resistance power and motor input power
  218. #define ALM_ROTOR_LOCK_TM 3 // unit: s, Time of duration(TBC)
  219. #define ALM_ROTOR_LOCK_IQ_ABS 4500 // unit: 0.01A, Threshold value
  220. #define ALM_ROTOR_LOCK_SPD 100 // unit: rpm, Threshold value
  221. #if ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V))
  222. /* Over voltage */
  223. #define ALM_OVR_VLT_LVL1_VAL 450 // unit: 0.1V, Threshold value level1
  224. #define ALM_OVR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
  225. #define ALM_OVR_VLT_LVL2_VAL 460 // unit: 0.1V, Threshold value level2
  226. #define ALM_OVR_VLT_LVL2_TM 100 // unit: ms, Time of duration level2(TBS)
  227. #define ALM_OVR_VLT_LVL3_VAL 470 // unit: 0.1V, Threshold value level3
  228. #define ALM_OVR_VLT_LVL3_TM 5 // unit: ms, Time of duration level3(TBS)
  229. /* Under voltage */
  230. #define ALM_UNDR_VLT_LVL1_VAL 300 // unit: 0.1V, Threshold value level1
  231. #define ALM_UNDR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
  232. #define ALM_UNDR_VLT_LVL2_VAL 280 // unit: 0.1V, Threshold value level2
  233. #define ALM_UNDR_VLT_LVL2_TM 2 // unit: ms, Time of duration level2(TBS)
  234. #elif ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V))
  235. /* Over voltage */
  236. #define ALM_OVR_VLT_LVL1_VAL 585 // unit: 0.1V, Threshold value level1
  237. #define ALM_OVR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
  238. #define ALM_OVR_VLT_LVL2_VAL 598 // unit: 0.1V, Threshold value level2
  239. #define ALM_OVR_VLT_LVL2_TM 100 // unit: ms, Time of duration level2(TBS)
  240. #define ALM_OVR_VLT_LVL3_VAL 611 // unit: 0.1V, Threshold value level3
  241. #define ALM_OVR_VLT_LVL3_TM 5 // unit: ms, Time of duration level3(TBS)
  242. /* Under voltage */
  243. #define ALM_UNDR_VLT_LVL1_VAL 390 // unit: 0.1V, Threshold value level1
  244. #define ALM_UNDR_VLT_LVL1_TM 2 // unit: s, Time of duration level1(TBS)
  245. #define ALM_UNDR_VLT_LVL2_VAL 364 // unit: 0.1V, Threshold value level2
  246. #define ALM_UNDR_VLT_LVL2_TM 2 // unit: ms, Time of duration level2(TBS)
  247. #endif
  248. /* Over speed */
  249. #define ALM_OVR_SPD_VAL 6000 // unit: rpm, Threshold value
  250. #define ALM_OVR_SPD_TM 100 // unit: ms, Time of duration(TBS)
  251. /* ADC self detecting */
  252. #define ALM_ADC_DETE_LOW_VAL 155 // unit: 0.01V, ADC offset Voltage min
  253. #define ALM_ADC_DETE_HIG_VAL 175 // unit: 0.01V, ADC offset Voltage max
  254. /* IPM over heat */
  255. #define ALM_IPM_OVR_HEAT_VAL 105 // 50 //105 // unit: Ce, Threshold value
  256. #define ALM_IPM_OVR_TM 2 // unit: s, Time of duration(TBS)
  257. /* Stop time of three phase short force */
  258. #define ALM_THR_PHS_SHRT_FRC_TM 200 // unit: ms, Time of duration(TBC)
  259. /* Stop time of pwm off */
  260. #define ALM_PWM_OFF_TM 200 // unit: ms, Time of duration(TBC)
  261. #define ALM_PWMOFF_SHRT1_SW_TM 100 // unit: ms, Time of duration(TBC)
  262. /* Stop time of three phase short */
  263. #define ALM_THR_PHS_SHRT_NORM_TM 100 // unit: ms, Time of duration(TBC)
  264. #define ALM_SHRT_PWMOFF_SW_TM 100 // unit: ms, Time of duration(TBC)
  265. /* Stop Minimum Current */
  266. #define ALM_STOP_IPM_OVER_CUR_TM 100 // unit: ms, Time of duration(TBC)
  267. /* Recover time of global */
  268. #define ALM_REC_ALL_TM 5000 // unit: ms, Time of duration(TBC)
  269. /* Recover time of IPM OC */
  270. #define ALM_IPM_OC_REC_TM 200 // unit: ms, Time of duration(TBC)
  271. /* Recover value of over voltage and under voltage error*/
  272. #define ALM_VLT_REC_ERRVAL 30 // unit: 0.1V
  273. /* Recover time & value of over voltage */
  274. #define ALM_OVR_VLT_REC_VAL (ALM_OVR_VLT_LVL1_VAL - ALM_VLT_REC_ERRVAL) // unit: 0.1V
  275. #define ALM_OVR_VLT_REC_TM 100 // unit: ms, Time of duration(TBC)
  276. #define ALM_OVR_VLT_REC_TM1 150 // unit: ms, Time of duration(TBC)
  277. /* Recover time & value of under voltage */
  278. #define ALM_UNDR_VLT_REC_VAL (ALM_UNDR_VLT_LVL1_VAL + ALM_VLT_REC_ERRVAL) // unit: 0.1V
  279. #define ALM_UNDR_VLT_REC_TM 200 // unit: ms, Time of duration(TBC)
  280. #define ALM_UNDR_VLT_REC_TM1 400 // unit: ms, Time of duration(TBC)
  281. /* Recover time & value of IPM over heat */
  282. #define ALM_IPM_OVR_HEAT_REC_VAL 90 // unit: Ce, Threshold value
  283. #define ALM_IPM_OVR_REC_TM 60 // unit: s, Time of duration(TBC)
  284. #define ALM_IPM_OVR_REC_TM1 120 // unit: s, Time of duration(TBC)
  285. /* Ebike sensor fault detect*/
  286. #define ALM_MOTORSPD_MIN_RPM 50 // unit: rpm
  287. #define ALM_BIKESPD_FLT_TS 10 // unit: s
  288. #define ALM_CADENCE_FLT_TS 10 // unit: s
  289. #define ALM_TORQ_MAX_VOL 30 // unit: 0.1V
  290. #define ALM_TORQ_MIN_VOL 1 // unit: 0.1V
  291. #define ALM_TORQ_FLT_TS 1 // unit: s
  292. #define ALM_THROTTLE_MAX_VOL 30 // unit: 0.1V
  293. #define ALM_THROTTLE_MIN_VOL 0 //1 // unit: 0.1V
  294. #define ALM_THROTTLE_FLT_TS 1 // unit: s
  295. #define ALM_NTC_MAX_VOL 32 // unit: 0.1V
  296. #define ALM_NTC_MIN_VOL 3 // unit: 0.1V
  297. #define ALM_MOTORNTC_FLT_TS 1 // unit: s
  298. #define ALM_PCBNTC_FLT_TS 1 // unit: s
  299. /* Ebike sensor fault recover*/
  300. #define ALM_BIKE_REC_ALL_TM 1000 // unit: ms
  301. #define ALM_BIKESPD_REC_TM 200 // unit: ms
  302. #define ALM_CADENCE_REC_TM 200 // unit: ms
  303. #define ALM_TORQ_REC_TM 200 // unit: ms
  304. #define ALM_THROTTLE_REC_TM 200 // unit: ms
  305. #define ALM_MOTORNTC_REC_TM 200 // unit: ms
  306. #define ALM_PCBNTC_REC_TM 200 // unit: ms
  307. /*======================================================================*
  308. Motor start
  309. *=======================================================================*/
  310. /* Start mode */
  311. #define START_ALIGN 0 // Motor start with three stage
  312. #define START_MODE START_ALIGN // Motor start mode
  313. /* InitPosDet mode */
  314. #define INITPOS_ALIGN 0 // Motor start with three stage
  315. #define INITPOS_MODE INITPOS_ALIGN // Motor initposdet mode
  316. /* Park time & current */
  317. #define ALIGN_CUR_AP 1000 // unit: 0.01A, Park current value
  318. #define ALIGN_RAMP_TM_MS 500 // unit: ms, Time of current ramp
  319. #define ALIGN_HOLD_TM_MS 2000 // unit: ms, Time of current hold
  320. #define ALIGN_ANG_INIT 0 // unit: deg, Park angle init, can not be 90deg
  321. /* Drag speed & current */
  322. #define DRAG_CUR_AP 1000 // 1500 //100 Huawei // unit: 0.01A, Drag current value
  323. #define DRAG_VOL_AP 10 // 0.1v
  324. #define DRAG_SPD_HZ 20 // unit: Hz, Final speed of drag
  325. #define DRAG_SPD_RAMP_TM_MS 4000 // unit: ms, Time of speed from 0Hz to target Hz
  326. /* Open to close */
  327. #define OPEN2CLZ_CUR_RAMP_TM_MS 5000 // 5000//1000 Huawei // unit: ms, Time of current from drag value to 0
  328. /* Close loop */
  329. /* stop loop */
  330. #define STOP_SPD_REF_RPM 100 // unit: rpm, Speed reference value when status go to stop
  331. /*======================================================================*
  332. Flux observer
  333. *=======================================================================*/
  334. #define OBS_SPD_PLL_M 2 // Flux observer m coefficient
  335. #define OBS_SPD_PLL_BANDWIDTH_HZ 150 // Flux observer PLL bandwidth
  336. #define OBS_FLUX_PI_DAMPRATIO 10 // unit:0.1, Flux observer PI regulator dampratio
  337. #define OBS_FLUX_PI_CROSSFREQ_HZ 10 // unit:Hz, Flux observer PI regulator crossfrequency
  338. /*======================================================================*
  339. Current loop PI regulation
  340. *=======================================================================*/
  341. #define ACR_PI_BANDWIDTH_FLX 300 // unit: Hz, Current loop bandwidth when flux observer run
  342. #define ACR_CUR_FLX_FBK_LPF_FRQ 8000 // unit: Hz, Frequency of current feedback LPF when flux observer run
  343. #define ACR_CUR_OUT_LIM 37837 // Q15, 2/sqrt(3)*Vdc for current output limit //18919
  344. #define ACR_RA_COEF 1 // Coefficient of Active Resistance
  345. #define ACR_UDCP_OUT_LIM 18918 // Q15, 2/3*Vdc for Udcp output limit //18918 //21845 //10923
  346. /*======================================================================*
  347. Speed loop PI regulation
  348. *=======================================================================*/
  349. #define ASR_PI_BANDWIDTH 3 // unit: Hz, Speed loop bandwidth
  350. #define ASR_PI_M 4 //
  351. #define ASR_SPD_FBK_LPF_FRQ 50 //
  352. #define ASR_SPD_INER_RATE 1 //
  353. /*=====================================================================*
  354. PWM generation
  355. *=======================================================================*/
  356. #define PWM_MAX_DUTY_CYLE_IPM 880 // 890 // 938 // unit: 0.1%,Max duty cyle for compare value
  357. #define PWM_7SVM_TO_5SVM_DUTY_IPM 700 // unit: 0.1%, Switch ratio from 7 to 5 svpwm
  358. #define PWM_MIN_SAMPLE_DUTY1_IPM 5 * 10000 / PWM_PERIOD_US // unit: 0.1%, 5us TWO MIN ZERO VECTOR = two sample current steady time
  359. #define PWM_MIN_SAMPLE_DUTY2_IPM 10 * 10000 / PWM_PERIOD_US // unit: 0.1%, 10us TWO (one sample current steady time + one sample time)
  360. #define PWM_MIN_SAMPLE_DUTY3_IPM \
  361. ((ULONG)6 * 10000 / PWM_PERIOD_US) // unit: 0.1%, 6 us TWO (one Singel Resistance sample current steady time + one sample time)
  362. #define PWM_SAMPLE_TOSTEADY_IPM ((ULONG)8 * 10000 / PWM_PERIOD_US) // unit: 0.1%, 4us TWO sample current to steady time
  363. #define PWM_SAMPLE_SINGELRESIS_IPM ((ULONG)1 * 10000 / PWM_PERIOD_US) // unit: 0.1%, 1us TWO singel Resistance sample time
  364. #define PWM_1ST_SAMPLE_CTS_IPM 25 // 43 // 25 // unit: Null, first current sample counts
  365. #define PWM_2ND_SAMPLE_CTS_IPM 220 // 280 // 220 // unit: Null, second current sample counts
  366. #define PWM_MIN_EFF_VECTOR_CTS_IPM 245 // 323 // unit: Null, Min effective vector counts
  367. #define PWM_MIN_EFF_VECTOR_PU_IPM 892 // 1176 // 600 // unit: Q14, Min effective vector pu
  368. #define PWM_OVR_MDL_MIN_PHS 0 // SVPWM over modulation: min phase error
  369. #define PWM_OVR_MDL_MIN_AMP 1 // SVPWM over modulation: min amplitude error
  370. #define PWM_OVR_MDL_OPTIMUM 2 // SVPWM over modulation: amplitude and phase optimum
  371. #define PWM_OVR_MDL_SEL PWM_OVR_MDL_MIN_PHS //
  372. /*======================================================================*
  373. Flux Weakening
  374. *=======================================================================*/
  375. #define FW_VDC_MIN_CALC_TM 20 // unit: ms,50Hz=>20ms, period of Vdc fluctuate
  376. #define FW_VDC_LPF_FRQ 50 // unit: Hz, Frequency of Vdc LPF
  377. #define FW_PWM_MAX_DUTY_CYLE_IPM 880 // unit: 0.1%,PWM max duty cyle for flux weakening
  378. #define FW_ID_PI_OUT_MIN 1000 // unit: 0.01A, Min Id of PI outunit: 0.01A, Current Limit
  379. #define FW_ID_MIN_LIM_RATIO 80 // Q0:1%, Ratio of Min d axis current (Charactoristic current)
  380. #define FW_ID_KP_PU 10 // Q16, Kp for d axis current
  381. #define FW_ID_KI_PU 5 // Q16, Ki for d axis current
  382. #define FW_CHAR_CUR_CROSS_FREQ 2 // Q0,unit: SQRT(1/2piR)
  383. #define FW_CHAR_CUR_DAMP_RATIO 2 // Q0,unit: SQRT(pi/2R)
  384. /*======================================================================*
  385. Constant Voltage Braking Parameter define
  386. *=======================================================================*/
  387. #define CVB_CONSTANT_VOL_BRAKE_ERRV 30 // unit:0.1V,Voltage limit of Constant Voltage Brake
  388. #define CVB_CONSTANT_VOL_BRAKE_V (ALM_OVR_VLT_LVL1_VAL - CVB_CONSTANT_VOL_BRAKE_ERRV) // unit:0.1V,Voltage limit of Constant Voltage Brake
  389. #define CVB_CONSTANT_SPD_LOW_RPM 4500 // unit:rpm,
  390. /*======================================================================*
  391. Power limit
  392. *=======================================================================*/
  393. #define PWRLIM_VAL 6500 // unit: 0.1w, Power limit value
  394. #define PWRLIM_ERR 500 // unit: 0.1w, Start power limit when "VAL - ERR"
  395. #define PWRLIM_LPF_FRQ 8000 // unit: Hz, Frequency of LPF in input power of motor
  396. #define PWR_IQ_LIMIT_KP_PU 20 // Q15
  397. #define PWR_IQ_LIMIT_KI_PU 3000 // Q15
  398. #define PWRLIM_START_THRESHOLD_TEMP 90 // Ce
  399. /*======================================================================*
  400. Deadband compensation
  401. *=======================================================================*/
  402. #define DBC_K_COEF 300 // unit:0.1V/A Deadband compensation slope coefficient
  403. /*======================================================================*
  404. Communication type define
  405. *=======================================================================*/
  406. #define UART_MONITOR 0 //
  407. #define UART_HOST 1 //
  408. #define UART_TYPE UART_HOST //
  409. /*==============================================================================
  410. Speed & Acc Constant parameters define
  411. ==============================================================================*/
  412. #define USER_MOTOR_45RPM2PU SPD_RPM2PU(45) // 45rpm,Q15
  413. #define USER_MOTOR_100RPM2PU SPD_RPM2PU(100)
  414. #define USER_MOTOR_200RPM2PU SPD_RPM2PU(200)
  415. #define USER_MOTOR_300RPM2PU SPD_RPM2PU(300)
  416. #define USER_MOTOR_400RPM2PU SPD_RPM2PU(400)
  417. #define USER_MOTOR_600RPM2PU SPD_RPM2PU(600) // 600rpm,Q15
  418. #define USER_MOTOR_800RPM2PU SPD_RPM2PU(800) // 800rpm,Q15
  419. #define USER_MOTOR_1000RPM2PU SPD_RPM2PU(1000) // 1000rpm,Q15
  420. #define USER_MOTOR_1500RPM2PU SPD_RPM2PU(1500) // 6000rpm,Q15
  421. #define USER_MOTOR_4000RPM2PU SPD_RPM2PU(4000) // 6000rpm,Q15
  422. #define USER_MOTOR_5500RPM2PU SPD_RPM2PU(5500)
  423. #define USER_MOTOR_100RPMPS2PU_Q29 SPD_ACC_RPM2PU(100) // 100rpm/s,(0x40000000/FTBS_Hz/cof_uwVbRpm*100)
  424. /*=======================================================================
  425. TBS&TBC Time Cnts Define
  426. =======================================================================*/
  427. #define TBCCNT_500us (((ULONG)500 * FTBC_HZ) / 1000000)
  428. #define TBCCNT_1ms (((ULONG)1 * FTBC_HZ) / 1000)
  429. #define TBCCNT_5ms (((ULONG)5 * FTBC_HZ) / 1000)
  430. #define TBCCNT_10ms (((ULONG)10 * FTBC_HZ) / 1000)
  431. #define TBCCNT_50ms (((ULONG)50 * FTBC_HZ) / 1000)
  432. #define TBCCNT_32ms (((ULONG)32 * FTBC_HZ) / 1000)
  433. #define TBCCNT_60ms (((ULONG)60 * FTBC_HZ) / 1000)
  434. #define TBCCNT_100ms (((ULONG)100 * FTBC_HZ) / 1000)
  435. #define TBCCNT_150ms (((ULONG)150 * FTBC_HZ) / 1000)
  436. #define TBCCNT_200ms (((ULONG)200 * FTBC_HZ) / 1000)
  437. #define TBCCNT_250ms (((ULONG)250 * FTBC_HZ) / 1000)
  438. #define TBCCNT_300ms (((ULONG)300 * FTBC_HZ) / 1000)
  439. #define TBCCNT_400ms (((ULONG)400 * FTBC_HZ) / 1000)
  440. #define TBCCNT_500ms (((ULONG)500 * FTBC_HZ) / 1000)
  441. #define TBCCNT_100ms (((ULONG)100 * FTBC_HZ) / 1000)
  442. #define EVE1MSCNT_1ms (((ULONG)1 * EVENT_1MS_HZ) / 1000)
  443. #define EVE1MSCNT_5ms (((ULONG)5 * EVENT_1MS_HZ) / 1000)
  444. #define EVE1MSCNT_10ms (((ULONG)10 * EVENT_1MS_HZ) / 1000)
  445. #define EVE1MSCNT_20ms (((ULONG)20 * EVENT_1MS_HZ) / 1000)
  446. #define EVE1MSCNT_50ms (((ULONG)50 * EVENT_1MS_HZ) / 1000)
  447. #define EVE1MSCNT_100ms (((ULONG)100 * EVENT_1MS_HZ) / 1000)
  448. #define EVE1MSCNT_200ms (((ULONG)200 * EVENT_1MS_HZ) / 1000)
  449. #define EVE10MSCNT_3s ((ULONG)3 * EVENT_1MS_HZ / 10)
  450. #define EVE10MSCNT_5s ((ULONG)5 * EVENT_1MS_HZ / 10)
  451. #define EVE10MSCNT_10s ((ULONG)10 * EVENT_1MS_HZ / 10)
  452. /************************************************************************
  453. Comment Table
  454. *************************************************************************/
  455. // /*======================================================================*
  456. // High Frequency Signal Injection
  457. // *=======================================================================*/
  458. // #define HFI_FREQ1_HZ 1200 // unit: Hz, Inject signal frequency 1
  459. // #define HFI_AMP1_VT 600 // unit: 0.1v, Inject signal voltage 1
  460. // #define HFI_FREQ2_HZ 1400 // unit: Hz, Inject signal frequency 2
  461. // #define HFI_AMP2_VT 700 // unit: 0.1v, Inject signal voltage 2
  462. // #define HFI_TM_INIPOS_MS 60 // unit: ms, Initial position detection time
  463. // #define HFI_WAITTM_INIPOS_MS 6 // unit: ms, Wait time after initial position detection
  464. // #define HFI_AMP_POR_VT 700 // unit: 0.1v, Polarity detection voltage amplitude
  465. // #define HFI_TM_POR_PULS_MS 1 // unit: ms, Polarity detection voltage pulse time
  466. // #define HFI_WAITTM_POR_PULS_MS 12 // Wunit: ms, ait time after voltage pulse
  467. // #define HFI_DELTA_CUR_MAG_POR_OK_AP 20 // unit: 0.01A, delta current for polarity detection ok
  468. // #define HFI_CUR_LPF_HZ 500 // unit: Hz, Cut-off frequency of current lpf
  469. // #define HFI_CUR_HPF_HZ 50 // unit: Hz, Cut-off frequency of current hpf
  470. // #define HFI_PLL_DAMPING_RATIO 35 // unit: Null, Pll damping ratio
  471. // #define HFI_PLL_CROSS_FREQ_HZ 20 // unit: Hz, Pll cross frequency
  472. // #define HFI_SPD_LPF_HZ 8 // unit: Hz, Cut-off frequency of spd lpf
  473. // #define HFI_MAG_SATR_AP 240 // unit: 0.01A, Magnetic saturation current
  474. /*==============================================================================
  475. Deadband Compensation parameters define
  476. ==============================================================================*/
  477. /* Api Device Index Definations */
  478. #define ADC_IA_CH 0
  479. #define ADC_IB_CH 1
  480. #define ADC_IC_CH 2
  481. #define ADC_IDC_CH 0
  482. #define ADC_UDC_CH 0
  483. #define ADC_TEMP_CH 1
  484. #define ADC_UAC_CH 2
  485. #define GPIO_LED_PIN 0
  486. #define GPIO_CAP_PIN 1
  487. /************************************************************************
  488. TypeDefs & Structure defines
  489. *************************************************************************/
  490. /************************************************************************
  491. Exported Variables:
  492. *************************************************************************/
  493. /************************************************************************
  494. RAM ALLOCATION:
  495. *************************************************************************/
  496. /************************************************************************
  497. Exported Function Call Prototypes (N/A)
  498. *************************************************************************/
  499. /************************************************************************
  500. Local Function Call Prototypes (N/A)
  501. *************************************************************************/
  502. /************************************************************************
  503. Head files (N/A)
  504. *************************************************************************/
  505. // #include <stdlib.h>
  506. #include "typedefine.h"
  507. #include "CodePara.h"
  508. #include "classB.h"
  509. #include "hwsetup.h"
  510. #include "board_config.h"
  511. #include "mathtool.h"
  512. #include "main.h"
  513. #include "spdctrFSM.h"
  514. #include "glbcof.h"
  515. #include "crdnt.h"
  516. #include "tbc.h"
  517. #include "tbs.h"
  518. #include "tbt.h"
  519. #include "alarm.h"
  520. #include "adc.h"
  521. #include "spi_master.h"
  522. #include "i2c_master.h"
  523. #include "spdctrmode.h"
  524. #include "acr.h"
  525. #include "asr.h"
  526. #include "torqobs.h"
  527. #include "obs.h"
  528. #include "dbc.h"
  529. #include "flxwkn.h"
  530. #include "pwm.h"
  531. #include "hfinj.h"
  532. #include "pwrlim.h"
  533. #include "bootloader.h"
  534. #include "brake.h"
  535. #include "uart_monitor.h"
  536. #include "macroequ.h"
  537. #include "alignstartup.h"
  538. #include "switchhall.h"
  539. /************************************************************************
  540. Flag Define (N/A)
  541. *************************************************************************/
  542. #ifdef __cplusplus
  543. }
  544. #endif // __cplusplus
  545. #endif
  546. /*************************************************************************
  547. Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
  548. All rights reserved.
  549. *************************************************************************
  550. End of this File (EOF)!
  551. Do not put anything after this part!
  552. *************************************************************************/