syspar.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: syspar.h
  4. Partner Filename: Null
  5. Description: System parameters
  6. Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
  7. CPU TYPE : Cortex-M4
  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 SYSPAR_H
  16. #define SYSPAR_H
  17. /************************************************************************
  18. Compiler Directives
  19. *************************************************************************/
  20. /************************************************************************
  21. Definitions & Macros
  22. *************************************************************************/
  23. /*======================================================================*
  24. Update Time
  25. 2020-2-13 11:22:19
  26. *=======================================================================*/
  27. /*======================================================================*
  28. MCU Model Number
  29. *=======================================================================*/
  30. #define HARDWARE_STM4_64PIN 0
  31. #define HARDWARE_STM4_32PIN 1
  32. #define HARDWARE_VERSION HARDWARE_STM4_32PIN
  33. /*======================================================================*
  34. MCU Frequency
  35. *=======================================================================*/
  36. #define CLK_CORE_KHZ 72000
  37. #define CLK_PWM_KHZ 72000
  38. #define CLK_ADC_KHZ 36000
  39. #define CLK_AHB_KHZ 72000
  40. #define CLK_APB1_KHZ 36000
  41. #define CLK_APB2_KHZ 72000
  42. #define CLK_TIM0_KHZ 72000
  43. #define CLK_TIM1_KHZ 72000
  44. /*======================================================================*
  45. Control Frequency
  46. *=======================================================================*/
  47. #define FPWM_HZ 16000
  48. #define FTBC_HZ 8000
  49. #define FTBS_HZ 4000
  50. #define FSYSTICK_HZ 1000
  51. #define PWM_PERIOD_CNT 4500
  52. #define PWM_PERIOD_US 625
  53. #define TBC_PERIOD_US 1250
  54. #define TBS_PERIOD_US 2500
  55. #define EVENT_1MS_HZ 1000
  56. /*======================================================================*
  57. ADC
  58. *=======================================================================*/
  59. #define ADC_RESOLUTION_BIT 12
  60. #define ADC_CALIB_INDEX 12
  61. #define ADC_SMPL_PERIOD 7POINT5
  62. #define ADC_CONV_PERIOD 12POINT5
  63. #define ADC_INSERTED_CH_NUM 1
  64. #define ADC_REGULAR_CH_NUM 5
  65. #define ADC_UABC_LPF_COMP 20430
  66. /*======================================================================*
  67. ADC Maximum Value
  68. *=======================================================================*/
  69. //#if ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V))
  70. //#define ADC_IPHASE_CUR_MAX_AP 15600 //13400
  71. //#elif ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V))
  72. //#define ADC_IPHASE_CUR_MAX_AP 7500 //13400
  73. //#endif
  74. #define ADC_IDC_CUR_MAX_AP 9524//10476//11640//9524 //10476
  75. #define ADC_ISENSOR_CUR_MAX_AP 6005
  76. #define ADC_VDC_MAX_VT 605
  77. #define ADC_UABC_MAX_VT 495
  78. #define ADC_DISPLAY_MAX_VT 363
  79. #define ADC_LIGHT_MAX_VT 188
  80. #define ADC_SPDSENSOR_MAX_VT 188
  81. #define ADC_UABC_MAX_VT 495
  82. #define ADC_UMotorTemp_MAX_VT 0
  83. #define ADC_UPcbTemp_MAX_VT 33
  84. /*======================================================================*
  85. Base value
  86. *=======================================================================*/
  87. #define VBASE 480 // 0.1V 100mv
  88. #define IBASE 6000 // 0.01A
  89. #define FBASE 700 // Hz
  90. #define TORQUEBASE 900 // 0.1Nm wzy
  91. /*======================================================================*
  92. Control cycle
  93. *=======================================================================*/
  94. #define TBC_TM (((ULONG)FBASE << 10) / FTBC_HZ)
  95. #define TBS_TM (((ULONG)FBASE << 10) / FTBS_HZ)
  96. /*=======================================================================
  97. TBC real value to count function define
  98. =======================================================================*/
  99. #define TBC_US2CT(x) ((ULONG)(x)*FTBC_HZ / 1000000)
  100. #define TBC_MS2CT(x) ((ULONG)(x)*FTBC_HZ / 1000)
  101. #define TBC_S2CT(x) ((ULONG)(x)*FTBC_HZ)
  102. #define EVENT1MS_MS2CT(x) ((ULONG)(x)*EVENT_1MS_HZ / 1000)
  103. #define EVENT1MS_S2CT(x) ((ULONG)(x)*EVENT_1MS_HZ)
  104. /*=======================================================================
  105. TBS real value to count function define
  106. =======================================================================*/
  107. #define TBS_US2CT(x) ((ULONG)(x)*FTBS_HZ / 1000000)
  108. #define TBS_MS2CT(x) ((ULONG)(x)*FTBS_HZ / 1000)
  109. #define TBS_S2CT(x) ((ULONG)(x)*FTBS_HZ)
  110. #define TBS_MIN2CT(x) ((ULONG)(x)*FTBS_HZ * 60)
  111. /*=======================================================================
  112. SysTick real value to count function define
  113. =======================================================================*/
  114. #define TBT_MS2CT(x) ((ULONG)(x)*FSYSTICK_HZ / 1000)
  115. #define TBT_S2CT(x) ((ULONG)(x)*FSYSTICK_HZ)
  116. #define TBT_MIN2CT(x) ((ULONG)(x)*FSYSTICK_HZ * 60)
  117. /*=======================================================================
  118. Speed real value to pu value function define
  119. =======================================================================*/
  120. #define MOTOR_PAIRS M_POLE_PAIRS
  121. //#define SPD_RPM2PU(x) (((SLONG)(x)<<15)/60*MOTOR_PAIRS/FBASE)
  122. //#define SPD_HZ2PU(x) (((ULONG)(x)<<15)/FBASE)
  123. //#define SPD_ACC_RPM2PU(x) ((((ULONG)SPD_RPM2PU(x)<<16)/FTBS_HZ)<<1)
  124. #define SPD_RPM2PU(x) (((SLONG)(x) << 15) / 60 * MOTOR_PAIRS / FBASE) /* rpm to Pu(Q15) */
  125. #define SPD_HZ2PU(x) (((SLONG)(x) << 15) / FBASE) /* Hz(Electric) to Pu(Q15) */
  126. #define SPD_ACC_RPM2PU(x) (((SLONG)SPD_RPM2PU(x) << 14) / FTBS_HZ) /* rpm/s to Pu(Q29) */
  127. /*=======================================================================
  128. Voltage real value to pu value function define
  129. =======================================================================*/
  130. #define VLT_VT2PU(x) (((ULONG)(x) << 14) / VBASE)
  131. /*=======================================================================
  132. Current real value to pu value function define
  133. =======================================================================*/
  134. #define CUR_AP2PU(x) (((ULONG)(x) << 14) / IBASE)
  135. /*=======================================================================
  136. Angle real value to pu value function define
  137. =======================================================================*/
  138. #define ANG_DEG2PU(x) (((SLONG)(x) << 15) / 360)
  139. /*=======================================================================
  140. Bandwidth real value to pu value function define
  141. =======================================================================*/
  142. #define BW_HZ2PU(x) (((ULONG)(x) << 15) / FBASE)
  143. /************************************************************************
  144. Constant Table
  145. *************************************************************************/
  146. /************************************************************************
  147. TypeDefs & Structure defines
  148. *************************************************************************/
  149. /************************************************************************
  150. Exported Variables:
  151. *************************************************************************/
  152. /************************************************************************
  153. RAM ALLOCATION:
  154. *************************************************************************/
  155. /************************************************************************
  156. Exported Function Call Prototypes (N/A)
  157. *************************************************************************/
  158. /************************************************************************
  159. Local Function Call Prototypes (N/A)
  160. *************************************************************************/
  161. /************************************************************************
  162. Head files (N/A)
  163. *************************************************************************/
  164. /************************************************************************
  165. Flag Define (N/A)
  166. *************************************************************************/
  167. #endif
  168. /*************************************************************************
  169. Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
  170. All rights reserved.
  171. *************************************************************************
  172. End of this File (EOF)!
  173. Do not put anything after this part!
  174. *************************************************************************/