syspar.h 8.7 KB

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