flxwkn.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: flxwkn.h
  4. Partner Filename: flxwkn.c
  5. Description: The header file of flxwkn.c
  6. Complier: IAR Embedded Workbench for ARM 7.80.4
  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. Fjy create this file;
  15. ************************************************************************/
  16. #include "typedefine.h"
  17. /************************************************************************
  18. Beginning of File, do not put anything above here except notes
  19. Compiler Directives:
  20. *************************************************************************/
  21. #ifndef FLXWKN_H
  22. #define FLXWKN_H
  23. /************************************************************************
  24. Compiler Directives (N/A)
  25. ************************************************************************/
  26. #ifdef _FLXWKN_C_
  27. #define _FLXWKN_EXT
  28. #else
  29. #define _FLXWKN_EXT extern
  30. #endif
  31. /************************************************************************
  32. Definitions & Macros
  33. ************************************************************************/
  34. #define FW_CTRL_COEF_DEFAULT \
  35. { \
  36. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  37. } // Default value of FW_CTRL_COEF
  38. #define FW_CTRL_OUT_DEFAULT \
  39. { \
  40. 0, 0, 0, 0 \
  41. } // Default value of FW_CTRL_OUT
  42. /************************************************************************
  43. TypeDefs & Structure Defines
  44. ************************************************************************/
  45. typedef struct
  46. {
  47. UWORD uwPWMDutyMax; // Q0, Max modulation ratio in flux weakening
  48. UWORD uwIdRegKpPu; // Q16, Kp for d axis current
  49. UWORD uwIdRegKiPu; // Q16, Ki for d axis current
  50. SWORD swIdPIOutMinAp; // Q0, Min Id of PI out
  51. UWORD uwVdcMinCalcTmMs; // Q0, period of Vdc fluctuate
  52. UWORD uwVdcLpfFreqHz; // Q0, Frequency of Vdc LPF
  53. UWORD uwCharCurDampRatio; // Q0, Charactoristic current Damping Ratio
  54. UWORD uwCharCurCrossFreqHz; // Q0, Charactoristic current Cross Frequence
  55. UWORD uwFwCurLimAp; // Q0, Current Limit
  56. UWORD uwIdMinLimRatio; // Q0, Ratio of Min d axis current (Charactoristic current)
  57. SWORD swIdMaxAp; // Q0, Max d axis current
  58. SWORD swIdMinAp; // Q0, Min d axis current (Charactoristic current)
  59. UWORD uwRsOhm; // Q0, Phase resistance
  60. UWORD uwFreqTbcHz; // Q0, TBC freq
  61. UWORD uwIBaseAp; // Q0, Base Current
  62. UWORD uwFBaseHz; // Q0, Base Frequency
  63. UWORD uwUbVt; // Q0, Voltage base
  64. } FW_CTRL_COEFIN;
  65. typedef struct
  66. {
  67. UWORD uwVdcPu; // Q14, DC bus Voltage
  68. SWORD swUalphaPu; // Q14, alpha-axis Voltage
  69. SWORD swUbetaPu; // Q14, beta-axis Voltage
  70. SWORD swIqRefPu; // Q14, q-axis Current
  71. SWORD swUqRefPu; // Q14, q-axis Voltage
  72. } FW_CTRL_IN;
  73. typedef struct
  74. {
  75. UWORD uwVdcRatioPu; // Q14, Vdc ration
  76. UWORD uwIdRegKpPu; // Q16, d-axis Current regulation Kp
  77. UWORD uwIdRegKitPu; // Q16, d-axis Current regulation Kit
  78. UWORD uwIqRegKpPu; // Q15, q-axis Current regulation Kp
  79. SWORD swIqLimMaxPu; // Q14, q-axis Currentlimit value used for speed loop out
  80. SLONG slIdMaxPu; // Q30, d-axis Current max
  81. SLONG slIdMinPu; // Q30, d-axis Current min
  82. SLONG slIdMinLimPu; // Q30, d-axis Current min limit
  83. UWORD uwVdcAvgLpfCoef; // Q15, DC bus Voltage LowPass filter coefficient
  84. UWORD uwVdcMinCalcTm; // Q0, period of Vdc fluctuate
  85. SLONG slIdPIOutMinPu; // Q30, Min Id of PI out
  86. UWORD uwKpPu; // Q16, Estimate Min d-axis Current regulation Kp
  87. SLONG slKitPu; // Q25, Estimate Min d-axis Current regulation Kit
  88. UWORD uwFwCurLimPu; // Q14, Current Limit
  89. UWORD uwRsPu; // Q15, Motor phase resistance
  90. } FW_CTRL_COEF;
  91. typedef struct
  92. {
  93. SLONG slIdSumPu; // Q30, d-axis Current PI regulation output before limitation
  94. SWORD swIqLimPu; // Q14, q-axis Currentlimit value used for speed loop out
  95. SWORD swIdRefPu; // Q14, d-axis Current reference value used for current loop regulation
  96. SLONG slIdMinEstPu; // Q30, d-axis Current Estimate Min
  97. } FW_CTRL_OUT;
  98. /************************************************************************
  99. Constant Table
  100. *************************************************************************/
  101. /************************************************************************
  102. Exported Variables
  103. ************************************************************************/
  104. #ifdef _FLXWKN_C_
  105. _FLXWKN_EXT FW_CTRL_OUT flx_stCtrlOut = FW_CTRL_OUT_DEFAULT;
  106. _FLXWKN_EXT FW_CTRL_COEF flx_stCtrlCoef = FW_CTRL_COEF_DEFAULT;
  107. #else
  108. _FLXWKN_EXT FW_CTRL_OUT flx_stCtrlOut;
  109. _FLXWKN_EXT FW_CTRL_COEF flx_stCtrlCoef;
  110. #endif
  111. /************************************************************************
  112. RAM ALLOCATION
  113. ************************************************************************/
  114. #define flx_stCtrlIn (*(FW_CTRL_IN *)TBC_BUFFER)
  115. #define flx_stCtrlCoefIn (*(FW_CTRL_COEFIN *)MN_BUFFER)
  116. /************************************************************************
  117. Exported Function Call Prototypes
  118. ************************************************************************/
  119. #ifdef _FLXWKN_C_
  120. _FLXWKN_EXT void flx_voInit(void);
  121. _FLXWKN_EXT void flx_voCoef(FW_CTRL_COEFIN *in, FW_CTRL_COEF *out);
  122. _FLXWKN_EXT void flx_voCtrl(FW_CTRL_IN *in, FW_CTRL_COEF *coef, FW_CTRL_OUT *out);
  123. #else
  124. _FLXWKN_EXT void flx_voInit(void);
  125. _FLXWKN_EXT void flx_voCoef(FW_CTRL_COEFIN *in, FW_CTRL_COEF *out);
  126. _FLXWKN_EXT void flx_voCtrl(FW_CTRL_IN *in, FW_CTRL_COEF *coef, FW_CTRL_OUT *out);
  127. #endif
  128. /************************************************************************
  129. Flag Define (N/A)
  130. ************************************************************************/
  131. /***********************************************************************/
  132. #endif
  133. /************************************************************************
  134. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  135. All rights reserved.
  136. *************************************************************************
  137. End of this File (EOF):
  138. Do not put anything after this part!
  139. ************************************************************************/