obs.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: obs.h
  4. Partner Filename: obs.c
  5. Description: The header file of obs.c
  6. Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
  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. ************************************************************************/
  15. /************************************************************************
  16. Beginning of File, do not put anything above here except notes
  17. Compiler Directives:
  18. *************************************************************************/
  19. #ifndef OBS_H
  20. #define OBS_H
  21. /************************************************************************
  22. Compiler Directives (N/A)
  23. *************************************************************************/
  24. #ifdef _OBS_C_
  25. #define _OBS_EXT
  26. #else
  27. #define _OBS_EXT extern
  28. #endif
  29. /************************************************************************
  30. Definitions & Macros
  31. *************************************************************************/
  32. #define OBS_COF_DEFAULT \
  33. { \
  34. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  35. } // Default value of OBS_COF
  36. #define OBS_OUT_DEFAULT \
  37. { \
  38. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  39. } // Default value of OBS_OUT
  40. #define OBS_FLUXPI_COF_DEFAULT \
  41. { \
  42. 0, 0 \
  43. } // Default value of OBS_FLUXPI_COF
  44. #define OBS_FLUXPI_OUT_DEFAULT \
  45. { \
  46. 0, 0, 0 \
  47. } // Default value of OBS_FLUXPI_OUT
  48. /************************************************************************
  49. Typedefs & Structure Defines
  50. *************************************************************************/
  51. typedef struct
  52. {
  53. UWORD uwFbHz; // Real Value, Unit:Hz frequency base
  54. UWORD uwRbOm; // Real Value, unit: 0.01Ohm, Resistance base
  55. UWORD uwLbHm; // Real Value, unit: 0.01mH, Inductance base
  56. UWORD uwFluxbWb; // Real Value, unit: 0.01mWb, Flux linkage base
  57. UWORD uwFreqTbcHz; // Real Value, Unit:Hz, Current loop control cycle
  58. UWORD uwRsOm; // Real Value, unit: 0.01Ohm, Phase resistance
  59. UWORD uwLdHm; // Real Value, unit: 0.01mH, D axis inductance
  60. UWORD uwLqHm; // Real Value, unit: 0.01mH, Q axis inductance
  61. UWORD uwFluxWb; // Real Value, unit: 0.01mWb, Flux linkage
  62. UWORD uwFluxDampingRatio; // Q12, Flux PI regulator damping ratio
  63. UWORD uwFluxCrossFreqHz; // Q8, Flux PI regulator cross frequency
  64. UWORD uwSpdPllMcoef; // Q0, PLL damping factor
  65. UWORD uwSpdPllWvcHz; // Q10, PLL bandwidth
  66. } OBS_COF_IN;
  67. typedef struct
  68. {
  69. UWORD uwRsPu; // Q15, Phase resistance
  70. UWORD uwLdPu; // Q10, D axis inductance
  71. UWORD uwLqPu; // Q10, Q axis inductance
  72. UWORD uwFluxPPu; // Q12, Flux linkage
  73. UWORD uwCurTsPu; // Q15, Current loop control cycle
  74. UWORD uwCurTs; // Q10, TBC time
  75. UWORD uwSpdPllKpPu; // Q14, PLL Kp
  76. UWORD uwSpdPllKiPu; // Q14, PLL Kit
  77. UWORD uwFluxKpPu; // Q18, Flux PI regulator Kp
  78. UWORD uwFluxKitPu; // Q28, Flux PI regulator Kit
  79. } OBS_COF;
  80. typedef struct
  81. {
  82. SWORD swUalphaPu; // Q14, Stationary alpha-axis stator voltage
  83. SWORD swUbetaPu; // Q14, Stationary beta-axis stator voltage
  84. SWORD swIalphaPu; // Q14, Stationary alpha-axis stator current
  85. SWORD swIbetaPu; // Q14, Stationary beta-axis stator current
  86. UWORD uwVdcPu; // Q14, unit:Pu, DC bus voltage
  87. } OBS_IN;
  88. typedef struct
  89. {
  90. SLONG slFluxAlphaPu; // Q27, Output stationary alfa-axis stator flux
  91. SWORD swFluxAlphaPu; // Q10, Output stationary alfa-axis stator flux
  92. SLONG slFluxBetaPu; // Q27, Output stationary beta-axis stator flux
  93. SWORD swFluxBetaPu; // Q10, Output stationary beta-axis stator flux
  94. SLONG slElecThetaPu; // Q29, Output motor electrical position
  95. UWORD uwElecThetaPu; // Q15, Output motor electrical position
  96. SLONG slElecFreqPu; // Q29, Output electrical speed reference
  97. SWORD swElecFreqPu; // Q15, Output motor electrical speed reference
  98. SWORD swActiveFluxPu; // Q10, Output active flux
  99. } OBS_OUT;
  100. typedef struct
  101. {
  102. SWORD swRefPu; // Q10, Flux PI regulator I reference
  103. SWORD swFdbPu; // Q10, Flux PI regulator I feedback
  104. SWORD swUmaxPu; // Q14, Flux PI regulator voltage output maximum limit
  105. SWORD swUminPu; // Q14, Flux PI regulator voltage output minimum limit
  106. } OBS_FLUXPI_IN;
  107. typedef struct
  108. {
  109. UWORD uwFluxKpPu; // Q18, Flux PI regulator Kp
  110. UWORD uwFluxKitPu; // Q28, Flux PI regulator Kit
  111. } OBS_FLUXPI_COF;
  112. typedef struct
  113. {
  114. SWORD swURefPu; // Q14, Flux PI regulator output voltage
  115. SLONG slURefPu; // Q28, Flux PI regulator output voltage
  116. SWORD swErrZ1Pu; // Q10, Flux PI regulator error recorder
  117. } OBS_FLUXPI_OUT;
  118. /************************************************************************
  119. Constant Table
  120. *************************************************************************/
  121. /************************************************************************
  122. Exported Variables
  123. *************************************************************************/
  124. #ifdef _OBS_C_
  125. _OBS_EXT OBS_COF obs_stObsCoefPu = OBS_COF_DEFAULT;
  126. _OBS_EXT OBS_OUT obs_stObsOutPu;
  127. _OBS_EXT OBS_FLUXPI_OUT obs_stFluxAlphaPIOut = OBS_FLUXPI_OUT_DEFAULT;
  128. _OBS_EXT OBS_FLUXPI_OUT obs_stFluxBetaPIOut = OBS_FLUXPI_OUT_DEFAULT;
  129. _OBS_EXT OBS_FLUXPI_COF obs_stFluxAlphaPICoef = OBS_FLUXPI_COF_DEFAULT;
  130. _OBS_EXT OBS_FLUXPI_COF obs_stFluxBetaPICoef = OBS_FLUXPI_COF_DEFAULT;
  131. _OBS_EXT CRD_PARK_OUT obs_stFluxParkPu = OBS_FLUXPI_COF_DEFAULT;
  132. _OBS_EXT CRD_IPARK_OUT obs_stFluxIParkPu = OBS_FLUXPI_COF_DEFAULT;
  133. _OBS_EXT CRD_PARK_IN obs_stParkInPu;
  134. _OBS_EXT CRD_IPARK_IN obs_stIParkInPu;
  135. _OBS_EXT OBS_FLUXPI_IN obs_stFluxAlphaPIIn;
  136. _OBS_EXT OBS_FLUXPI_IN obs_stFluxBetaPIIn;
  137. #else
  138. _OBS_EXT OBS_COF obs_stObsCoefPu;
  139. _OBS_EXT OBS_OUT obs_stObsOutPu;
  140. _OBS_EXT OBS_FLUXPI_OUT obs_stFluxAlphaPIOut;
  141. _OBS_EXT OBS_FLUXPI_OUT obs_stFluxBetaPIOut;
  142. _OBS_EXT OBS_FLUXPI_COF obs_stFluxAlphaPICoef;
  143. _OBS_EXT OBS_FLUXPI_COF obs_stFluxBetaPICoef;
  144. _OBS_EXT CRD_PARK_OUT obs_stFluxParkPu;
  145. _OBS_EXT CRD_IPARK_OUT obs_stFluxIParkPu;
  146. _OBS_EXT CRD_PARK_IN obs_stParkInPu;
  147. _OBS_EXT CRD_IPARK_IN obs_stIParkInPu;
  148. _OBS_EXT OBS_FLUXPI_IN obs_stFluxAlphaPIIn;
  149. _OBS_EXT OBS_FLUXPI_IN obs_stFluxBetaPIIn;
  150. #endif
  151. /************************************************************************
  152. RAM ALLOCATION (N/A)
  153. *************************************************************************/
  154. #define obs_stObsCalcIn (*(OBS_IN *)TBC_BUFFER)
  155. #define obs_stObsCoefIn (*(OBS_COF_IN *)MN_BUFFER)
  156. #define obs_stFluxAlphaPICoefIn (*(OBS_FLUXPI_COFIN *)MN_BUFFER)
  157. #define obs_stFluxBetaPICoefIn (*(OBS_FLUXPI_COFIN *)MN_BUFFER)
  158. /************************************************************************
  159. Exported Function Call Prototypes
  160. *************************************************************************/
  161. #ifdef _OBS_C_
  162. _OBS_EXT void obs_voObsInit(void);
  163. _OBS_EXT void obs_voObsCoef(OBS_COF_IN *in, OBS_COF *out);
  164. _OBS_EXT void obs_voFluxPI(OBS_FLUXPI_IN *in, OBS_FLUXPI_COF *coef, OBS_FLUXPI_OUT *out);
  165. _OBS_EXT void obs_voObsCalc(OBS_IN *IN, OBS_COF *COF, OBS_OUT *OUT);
  166. #else
  167. _OBS_EXT void obs_voObsInit(void);
  168. _OBS_EXT void obs_voObsCoef(OBS_COF_IN *in, OBS_COF *out);
  169. _OBS_EXT void obs_voObsCalc(OBS_IN *IN, OBS_COF *COF, OBS_OUT *OUT);
  170. #endif
  171. /************************************************************************
  172. Flag Define (N/A)
  173. *************************************************************************/
  174. /***********************************************************************/
  175. #endif
  176. /************************************************************************
  177. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  178. All rights reserved.
  179. *************************************************************************
  180. End of this File (EOF)!
  181. Do not put anything after this part!
  182. *************************************************************************/