hfinj.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: hfinj.h
  4. Partner Filename: hfinj.c
  5. Description: The header file of hfinj.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. adding-initial position and polarity identification-xpl-2018-09-30
  15. ************************************************************************/
  16. /************************************************************************
  17. Beginning of File, do not put anything above here except notes
  18. Compiler Directives:
  19. *************************************************************************/
  20. #ifndef HFINJ_H
  21. #define HFINJ_H
  22. /************************************************************************
  23. Compiler Directives (N/A)
  24. *************************************************************************/
  25. #ifdef _HFINJ_C_
  26. #define _HFINJ_EXT
  27. #else
  28. #define _HFINJ_EXT extern
  29. #endif
  30. #include "typedefine.h"
  31. /************************************************************************
  32. Definitions & Macros
  33. *************************************************************************/
  34. #define HFI_COF_DEFAULT \
  35. { \
  36. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  37. }
  38. #define HFI_COF_IN_DEFAULT \
  39. { \
  40. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  41. }
  42. #define HFI_POLEPOS_OUT_DEFAULT \
  43. { \
  44. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0}, 0, 0, 0, 0, FALSE, FALSE, 0, 0, 0 \
  45. }
  46. #define HFI_POLEPOS_IN_DEFAULT \
  47. { \
  48. 0, 0, 0 \
  49. }
  50. #define HARWAVECOMNO 15
  51. /************************************************************************
  52. Constant Table
  53. *************************************************************************/
  54. /************************************************************************
  55. TypeDefs & Structure defines
  56. *************************************************************************/
  57. typedef enum
  58. {
  59. IniPosCalc = 0,
  60. PolDetect = 1,
  61. HfiCalc = 2
  62. } HFI_INJSTATE_DEF;
  63. typedef struct
  64. {
  65. UWORD uwUbVt; // Real Value, Unit:0.1V voltage base
  66. UWORD uwFbHz; // Real Value, Unit:Hz frequency base
  67. UWORD uwIbAp; // Real Value, Unit:0.01A current base
  68. UWORD uwFreqTbcHz; // Real Value, Unit:Hz
  69. UWORD uwFreqInj1Hz; // Real Value, Unit:Hz-1st frequency
  70. UWORD uwAmplInj1Vt; // Real Value, Unit: 0.1V
  71. UWORD uwFreqInj2Hz; // Real Value, Unit:Hz-2nd frequency
  72. UWORD uwAmplInj2Vt; // Real Value, Unit: 0.1V
  73. UWORD uwTmIniPosMs; // Real Value, Unit:ms
  74. UWORD uwTmWaitIniPosMs; // Real Value, Unit: ms
  75. UWORD uwAmplPulseVt; // Real Value, Unit: 0.1V
  76. UWORD uwTmPulseMs; // Real Value, Unit: ms
  77. UWORD uwTmPulseWaitMs; // Real Value, Unit: ms
  78. UWORD uwDeltaCurMagPorOkAp; // Real Value, Unit:0.01A Threshold Current for Magnetic polarity detection ok
  79. UWORD uwCurLpfFreqHz; // Real Value, Unit:Hz
  80. UWORD uwCurHpfFreqHz; // Real Value, Unit:Hz
  81. UWORD uwPllDampingRatio; // Real Value, Unit:N/A
  82. UWORD uwPllCrossFreqHz; // Real Value, Unit:Hz
  83. UWORD uwSpdLpfCofHz; // Real Value, Unit:Hz
  84. UWORD uwMagSatrAp; // Real Value, Unit:0.01A Magnetic saturation current
  85. } HFI_COF_IN;
  86. typedef struct
  87. {
  88. UWORD uwCycleTmPu; // Q10, Control cycle time
  89. UWORD uwAmplInjAbs1Pu; // Q15, Amplitude of Injection Singal----1st frequency
  90. UWORD uwRatioTbcToInj1; // Q15, Ratio of Injection Singal Freq to Tbc Freq
  91. UWORD uwAmplInjAbs2Pu; // Q15, Amplitude of Injection Singal----2nd frequency
  92. UWORD uwRatioTbcToInj2; // Q15, Ratio of Injection Singal Freq to Tbc Freq
  93. UWORD uwTmIniPosCt; // Q0, Time of initial position dectection
  94. UWORD uwTmWaitIniPosCt; // Q0, Time of Injection Singal
  95. UWORD uwAmplPPulsePu; // Q14, Voltage of Positive Pulse
  96. UWORD uwTmPPulseCt; // Q0, Time of Positive Pulse
  97. UWORD uwTmWaitPCt; // Q0, Wait Time after Positive Pulse
  98. UWORD uwAmplNPulsePu; // Q14, Voltage of Negative Pulse
  99. UWORD uwTmNPulseCt; // Q0, Time of Negative Pulse
  100. UWORD uwTmWaitNCt; // Q0, Wait Time after Negative Pulse
  101. SWORD swDeltaCurMagPorOkPu; // Q14, Threshold Current for Magnetic polarity detection ok
  102. SWORD swMagSatrPu; // Q14, Magnetic saturation current
  103. UWORD uwPllKpPu; // Q14
  104. UWORD uwPllKiPu; // Q24
  105. UWORD uwCurLpfCofPu; // Q15,cut-off frequency for fundamental current filter
  106. UWORD uwCurHpfCofPu; // Q15,cut-off frequency for signal demodulation filter
  107. UWORD uwSpdLpfCof; // Q15,cut-off frequency for estimated speed filter
  108. UWORD uwPllCrossFreq;
  109. UWORD uwBandwidthPu;
  110. } HFI_COF;
  111. typedef struct
  112. {
  113. SWORD swIaFbPu; // Q14, Current A Feedback
  114. SWORD swIbFbPu; // Q14, Current B Feedback
  115. SWORD swIcFbPu; // Q14, Current C Feedback
  116. } HFI_POLEPOS_IN;
  117. typedef struct
  118. {
  119. UWORD uwTmInjCt; // Q0,
  120. SWORD swVdInjPu; // Q14, Injection Voltage on d axis
  121. SWORD swVqInjPu; // Q14, Injection Voltage on q axis
  122. SWORD swIdHfFbPu; // Q14, d Current Feedback in High Frequency
  123. SWORD swIqHfFbPu; // Q14, q Current Feedback in High Frequency
  124. SWORD swIdHfLpfPu; // Q14, d Current Feedback in High Frequency
  125. SWORD swIqHfLpfPu; // Q14, q Current Feedback in High Frequency
  126. SLONG slThetaPllPu; // Q30, 32-bits Theta of PLL
  127. UWORD uwThetaPllPu; // Q15, 16-bits Theta of PLL
  128. UWORD uwThetaOutPu; // Q15, Theta output
  129. SLONG slPllSpdPu; // Q20, 32-bits Speed of PLL
  130. SWORD swPllSpdPu; // Q15, 16-bits Speed of PLL
  131. SLONG slPllSpdLpfPu; // Q15, 32-bits Speed of PLL
  132. SWORD swPllSpdLpfPu; // Q15, 16-bits Speed of PLL
  133. LPF_OUT stPllSpdOutLpf; // Q15, Speed out
  134. SLONG slPllPPu; // Q29, Intermediate variable of PLL
  135. SLONG slPllIProLimPu; // Q39, Intermediate variable of PLL
  136. SLONG slPllIPu; // Q29, Intermediate variable of PLL
  137. SLONG slPllIRemPu; // Q39, Intermediate variable of PLL
  138. BOOL blMagPorOkFlag; // Q0, Magnetic polarity detection ok flag
  139. BOOL blMagPorOvrFlag; // Q0, Magnetic polarity detection over flag
  140. SWORD swMagIdFbPPu; // Q14, d Current Feedback of postive voltage pluse
  141. SWORD swMagIdFbNPu; // Q14, q Current Feedback of negtive voltage pluse
  142. SWORD uwDeltaThetaPu; // Q15, compensative theta of Magnetic polarity
  143. } HFI_POLEPOS_OUT;
  144. /************************************************************************
  145. Constant Table
  146. *************************************************************************/
  147. /************************************************************************
  148. Exported Variables:
  149. *************************************************************************/
  150. #ifdef _HFINJ_C_
  151. _HFINJ_EXT SWORD hfi_swIqFbLpfPu[HARWAVECOMNO] = {-9000, -8000, -7000, -6000, -5000, -4000, -3000, 0, 3000, 4000, 5000, 6000, 7000, 8000, 9000}; // Iq
  152. _HFINJ_EXT SWORD hfi_swDcOffSetPu[HARWAVECOMNO] = {-350, -295, -230, -180, -120, -70, -35, 0,
  153. 45, 80, 125, 195, 245, 320, 370}; // dc-offset-mul-saliency
  154. _HFINJ_EXT SWORD hfi_swSixAmpPu[HARWAVECOMNO] = {110, 110, 110, 90, 70, 30, 10, 0, 15, 40, 70, 90, 110, 110, 110}; // 6th-amp-offset-mul-saliency
  155. _HFINJ_EXT SWORD hfi_swSixPhasePu[HARWAVECOMNO] = {11000, 10000, 10000, 10000, 8000, 8000, 9000, 9000,
  156. 9000, 8500, 8000, 7000, 6000, 5000, 5000}; // 6th-phase-offset-mul-saliency
  157. _HFINJ_EXT SWORD hfi_swPI[HARWAVECOMNO] = {
  158. 368, 299, 238, 176, 121, 85, 80, 80, 80, 85, 121, 176, 238, 299, 368}; // saliency amp-variation (P.u.Q14,since directly from the current signal )
  159. _HFINJ_EXT SWORD hfi_swDcSlope[HARWAVECOMNO] = {
  160. 0, 225, 266, 205, 246, 205, 143, 48,
  161. 61, 143, 184, 287, 205, 307, 205}; // Q12/slope-dc-offset-mul-saliency,last is zero, because slope number is one smaller
  162. _HFINJ_EXT SWORD hfi_swSixAmpSlope[HARWAVECOMNO] = {0, 0, 0, -82, -82, -164, -82, -14,
  163. 20, 102, 123, 82, 82, 0, 0}; // Q12/slope-6th-amp-offset-mul-saliency
  164. _HFINJ_EXT SWORD hfi_swSixThetaShiftSlope[HARWAVECOMNO] = {0, -256, 0, 0, -512, 0, 256, 0,
  165. 0, -128, -128, -256, -256, -256, 0}; // Q8/slope-th-phase-offset-mul-saliency
  166. _HFINJ_EXT SWORD hfi_swPISlope[HARWAVECOMNO] = {0, -283, -250, -254, -225, -147, -20, 0, 0, 20, 147, 225, 254, 250, 283}; // Q12/slope-amp-variation
  167. _HFINJ_EXT HFI_COF hfi_stCof = HFI_COF_DEFAULT;
  168. _HFINJ_EXT HFI_POLEPOS_OUT hfi_stPolePosOut = HFI_POLEPOS_OUT_DEFAULT;
  169. _HFINJ_EXT HFI_POLEPOS_IN hfi_stPolePosIn = HFI_POLEPOS_IN_DEFAULT;
  170. _HFINJ_EXT HFI_COF_IN hfi_stCofIn = HFI_COF_IN_DEFAULT;
  171. _HFINJ_EXT HFI_INJSTATE_DEF hfi_euInjState = IniPosCalc;
  172. _HFINJ_EXT UWORD hfi_uwCurHpfFreqHz = 50; // HPF
  173. _HFINJ_EXT UWORD hfi_uwDampingRatio = 35; // PLL-bandwidth-Hz
  174. _HFINJ_EXT UWORD hfi_uwMcoefPu = 20; // M
  175. _HFINJ_EXT SWORD hfi_swSixHarmShftPu = 0; // 6th harmonic saliency phase shift
  176. _HFINJ_EXT SWORD hfi_swSixHarmAmpPu = 0; // 6th harmonic amplitude
  177. _HFINJ_EXT SWORD hfi_swDcShftPu = 0; // dc distortion due to multiple saliency
  178. _HFINJ_EXT SWORD hfi_swVariPIPu = 80; // PI variation due to multiple saliency,initial value>1
  179. #else
  180. _HFINJ_EXT HFI_COF hfi_stCof;
  181. _HFINJ_EXT HFI_POLEPOS_OUT hfi_stPolePosOut;
  182. _HFINJ_EXT HFI_POLEPOS_IN hfi_stPolePosIn;
  183. _HFINJ_EXT HFI_COF_IN hfi_stCofIn;
  184. _HFINJ_EXT HFI_INJSTATE_DEF hfi_euInjState;
  185. _HFINJ_EXT UWORD hfi_uwCurHpfFreqHz;
  186. _HFINJ_EXT UWORD hfi_uwDampingRatio;
  187. _HFINJ_EXT UWORD hfi_uwMcoefPu;
  188. _HFINJ_EXT UWORD hfi_swVariPIPu;
  189. #endif
  190. /************************************************************************
  191. RAM ALLOCATION:
  192. *************************************************************************/
  193. //#define hfi_stCofIn (*(HFI_COF_IN *)MN_BUFFER)
  194. //#define hfi_stPolePosIn (*(HFI_POLEPOS_IN *)TBC_BUFFER)
  195. /************************************************************************
  196. Exported Function Call Prototypes (N/A)
  197. *************************************************************************/
  198. #ifdef _HFINJ_C_
  199. _HFINJ_EXT void hfi_voInit(void);
  200. _HFINJ_EXT void hfi_voCof(HFI_COF_IN *in, HFI_COF *cof);
  201. _HFINJ_EXT void hfi_voPolePosDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out);
  202. _HFINJ_EXT void hfi_voMagPorDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out);
  203. #else
  204. _HFINJ_EXT void hfi_voInit(void);
  205. _HFINJ_EXT void hfi_voCof(HFI_COF_IN *in, HFI_COF *cof);
  206. _HFINJ_EXT void hfi_voPolePosDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out);
  207. _HFINJ_EXT void hfi_voMagPorDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out);
  208. #endif
  209. /************************************************************************
  210. Flag Define (N/A)
  211. *************************************************************************/
  212. /***********************************************************************/
  213. #endif
  214. /************************************************************************
  215. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  216. All rights reserved.
  217. *************************************************************************
  218. End of this File (EOF):
  219. Do not put anything after this part!
  220. *************************************************************************/