syspar.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #define ADC_IDC_CUR_MAX_AP 9524//10476//11640//9524 //10476
  70. #define ADC_ISENSOR_CUR_MAX_AP 6005
  71. #define ADC_VDC_MAX_VT 605
  72. #define ADC_UABC_MAX_VT 495
  73. #define ADC_DISPLAY_MAX_VT 363
  74. #define ADC_LIGHT_MAX_VT 188
  75. #define ADC_SPDSENSOR_MAX_VT 188
  76. #define ADC_UABC_MAX_VT 495
  77. #define ADC_UMotorTemp_MAX_VT 0
  78. #define ADC_UPcbTemp_MAX_VT 33
  79. /*======================================================================*
  80. Base value
  81. *=======================================================================*/
  82. #define VBASE 480 // 0.1V 100mv
  83. #define IBASE 6000 // 0.01A
  84. #define FBASE 700 // Hz
  85. #define TORQUEBASE 900 // 0.1Nm wzy
  86. /*======================================================================*
  87. Control cycle
  88. *=======================================================================*/
  89. #define TBC_TM (((ULONG)FBASE << 10) / FTBC_HZ)
  90. #define TBS_TM (((ULONG)FBASE << 10) / FTBS_HZ)
  91. /*=======================================================================
  92. TBC real value to count function define
  93. =======================================================================*/
  94. #define TBC_US2CT(x) ((ULONG)(x)*FTBC_HZ / 1000000)
  95. #define TBC_MS2CT(x) ((ULONG)(x)*FTBC_HZ / 1000)
  96. #define TBC_S2CT(x) ((ULONG)(x)*FTBC_HZ)
  97. #define EVENT1MS_MS2CT(x) ((ULONG)(x)*EVENT_1MS_HZ / 1000)
  98. #define EVENT1MS_S2CT(x) ((ULONG)(x)*EVENT_1MS_HZ)
  99. /*=======================================================================
  100. TBS real value to count function define
  101. =======================================================================*/
  102. #define TBS_US2CT(x) ((ULONG)(x)*FTBS_HZ / 1000000)
  103. #define TBS_MS2CT(x) ((ULONG)(x)*FTBS_HZ / 1000)
  104. #define TBS_S2CT(x) ((ULONG)(x)*FTBS_HZ)
  105. #define TBS_MIN2CT(x) ((ULONG)(x)*FTBS_HZ * 60)
  106. /*=======================================================================
  107. SysTick real value to count function define
  108. =======================================================================*/
  109. #define TBT_MS2CT(x) ((ULONG)(x)*FSYSTICK_HZ / 1000)
  110. #define TBT_S2CT(x) ((ULONG)(x)*FSYSTICK_HZ)
  111. #define TBT_MIN2CT(x) ((ULONG)(x)*FSYSTICK_HZ * 60)
  112. /*=======================================================================
  113. Speed real value to pu value function define
  114. =======================================================================*/
  115. #define MOTOR_PAIRS M_POLE_PAIRS
  116. //#define SPD_RPM2PU(x) (((SLONG)(x)<<15)/60*MOTOR_PAIRS/FBASE)
  117. //#define SPD_HZ2PU(x) (((ULONG)(x)<<15)/FBASE)
  118. //#define SPD_ACC_RPM2PU(x) ((((ULONG)SPD_RPM2PU(x)<<16)/FTBS_HZ)<<1)
  119. #define SPD_RPM2PU(x) (((SLONG)(x) << 15) / 60 * MOTOR_PAIRS / FBASE) /* rpm to Pu(Q15) */
  120. #define SPD_HZ2PU(x) (((SLONG)(x) << 15) / FBASE) /* Hz(Electric) to Pu(Q15) */
  121. #define SPD_ACC_RPM2PU(x) (((SLONG)SPD_RPM2PU(x) << 14) / FTBS_HZ) /* rpm/s to Pu(Q29) */
  122. /*=======================================================================
  123. Voltage real value to pu value function define
  124. =======================================================================*/
  125. #define VLT_VT2PU(x) (((ULONG)(x) << 14) / VBASE)
  126. /*=======================================================================
  127. Current real value to pu value function define
  128. =======================================================================*/
  129. #define CUR_AP2PU(x) (((ULONG)(x) << 14) / IBASE)
  130. /*=======================================================================
  131. Angle real value to pu value function define
  132. =======================================================================*/
  133. #define ANG_DEG2PU(x) (((SLONG)(x) << 15) / 360)
  134. /*=======================================================================
  135. Bandwidth real value to pu value function define
  136. =======================================================================*/
  137. #define BW_HZ2PU(x) (((ULONG)(x) << 15) / FBASE)
  138. /************************************************************************
  139. Constant Table
  140. *************************************************************************/
  141. /************************************************************************
  142. TypeDefs & Structure defines
  143. *************************************************************************/
  144. /************************************************************************
  145. Exported Variables:
  146. *************************************************************************/
  147. /************************************************************************
  148. RAM ALLOCATION:
  149. *************************************************************************/
  150. /************************************************************************
  151. Exported Function Call Prototypes (N/A)
  152. *************************************************************************/
  153. /************************************************************************
  154. Local Function Call Prototypes (N/A)
  155. *************************************************************************/
  156. /************************************************************************
  157. Head files (N/A)
  158. *************************************************************************/
  159. /************************************************************************
  160. Flag Define (N/A)
  161. *************************************************************************/
  162. #endif
  163. /*************************************************************************
  164. Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
  165. All rights reserved.
  166. *************************************************************************
  167. End of this File (EOF)!
  168. Do not put anything after this part!
  169. *************************************************************************/