/************************************************************************ Project: Welling Motor Control Paltform Filename: hfinj.h Partner Filename: hfinj.c Description: The header file of hfinj.c Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems. CPU TYPE : GD32F3x0 ************************************************************************* Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd. All rights reserved. ************************************************************************* ************************************************************************* Revising History (ECL of this file): adding-initial position and polarity identification-xpl-2018-09-30 ************************************************************************/ /************************************************************************ Beginning of File, do not put anything above here except notes Compiler Directives: *************************************************************************/ #ifndef HFINJ_H #define HFINJ_H /************************************************************************ Compiler Directives (N/A) *************************************************************************/ #ifdef _HFINJ_C_ #define _HFINJ_EXT #else #define _HFINJ_EXT extern #endif #include "typedefine.h" /************************************************************************ Definitions & Macros *************************************************************************/ #define HFI_COF_DEFAULT \ { \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ } #define HFI_COF_IN_DEFAULT \ { \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ } #define HFI_POLEPOS_OUT_DEFAULT \ { \ 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 \ } #define HFI_POLEPOS_IN_DEFAULT \ { \ 0, 0, 0 \ } #define HARWAVECOMNO 15 /************************************************************************ Constant Table *************************************************************************/ /************************************************************************ TypeDefs & Structure defines *************************************************************************/ typedef enum { IniPosCalc = 0, PolDetect = 1, HfiCalc = 2 } HFI_INJSTATE_DEF; typedef struct { UWORD uwUbVt; // Real Value, Unit:0.1V voltage base UWORD uwFbHz; // Real Value, Unit:Hz frequency base UWORD uwIbAp; // Real Value, Unit:0.01A current base UWORD uwFreqTbcHz; // Real Value, Unit:Hz UWORD uwFreqInj1Hz; // Real Value, Unit:Hz-1st frequency UWORD uwAmplInj1Vt; // Real Value, Unit: 0.1V UWORD uwFreqInj2Hz; // Real Value, Unit:Hz-2nd frequency UWORD uwAmplInj2Vt; // Real Value, Unit: 0.1V UWORD uwTmIniPosMs; // Real Value, Unit:ms UWORD uwTmWaitIniPosMs; // Real Value, Unit: ms UWORD uwAmplPulseVt; // Real Value, Unit: 0.1V UWORD uwTmPulseMs; // Real Value, Unit: ms UWORD uwTmPulseWaitMs; // Real Value, Unit: ms UWORD uwDeltaCurMagPorOkAp; // Real Value, Unit:0.01A Threshold Current for Magnetic polarity detection ok UWORD uwCurLpfFreqHz; // Real Value, Unit:Hz UWORD uwCurHpfFreqHz; // Real Value, Unit:Hz UWORD uwPllDampingRatio; // Real Value, Unit:N/A UWORD uwPllCrossFreqHz; // Real Value, Unit:Hz UWORD uwSpdLpfCofHz; // Real Value, Unit:Hz UWORD uwMagSatrAp; // Real Value, Unit:0.01A Magnetic saturation current } HFI_COF_IN; typedef struct { UWORD uwCycleTmPu; // Q10, Control cycle time UWORD uwAmplInjAbs1Pu; // Q15, Amplitude of Injection Singal----1st frequency UWORD uwRatioTbcToInj1; // Q15, Ratio of Injection Singal Freq to Tbc Freq UWORD uwAmplInjAbs2Pu; // Q15, Amplitude of Injection Singal----2nd frequency UWORD uwRatioTbcToInj2; // Q15, Ratio of Injection Singal Freq to Tbc Freq UWORD uwTmIniPosCt; // Q0, Time of initial position dectection UWORD uwTmWaitIniPosCt; // Q0, Time of Injection Singal UWORD uwAmplPPulsePu; // Q14, Voltage of Positive Pulse UWORD uwTmPPulseCt; // Q0, Time of Positive Pulse UWORD uwTmWaitPCt; // Q0, Wait Time after Positive Pulse UWORD uwAmplNPulsePu; // Q14, Voltage of Negative Pulse UWORD uwTmNPulseCt; // Q0, Time of Negative Pulse UWORD uwTmWaitNCt; // Q0, Wait Time after Negative Pulse SWORD swDeltaCurMagPorOkPu; // Q14, Threshold Current for Magnetic polarity detection ok SWORD swMagSatrPu; // Q14, Magnetic saturation current UWORD uwPllKpPu; // Q14 UWORD uwPllKiPu; // Q24 UWORD uwCurLpfCofPu; // Q15,cut-off frequency for fundamental current filter UWORD uwCurHpfCofPu; // Q15,cut-off frequency for signal demodulation filter UWORD uwSpdLpfCof; // Q15,cut-off frequency for estimated speed filter UWORD uwPllCrossFreq; UWORD uwBandwidthPu; } HFI_COF; typedef struct { SWORD swIaFbPu; // Q14, Current A Feedback SWORD swIbFbPu; // Q14, Current B Feedback SWORD swIcFbPu; // Q14, Current C Feedback } HFI_POLEPOS_IN; typedef struct { UWORD uwTmInjCt; // Q0, SWORD swVdInjPu; // Q14, Injection Voltage on d axis SWORD swVqInjPu; // Q14, Injection Voltage on q axis SWORD swIdHfFbPu; // Q14, d Current Feedback in High Frequency SWORD swIqHfFbPu; // Q14, q Current Feedback in High Frequency SWORD swIdHfLpfPu; // Q14, d Current Feedback in High Frequency SWORD swIqHfLpfPu; // Q14, q Current Feedback in High Frequency SLONG slThetaPllPu; // Q30, 32-bits Theta of PLL UWORD uwThetaPllPu; // Q15, 16-bits Theta of PLL UWORD uwThetaOutPu; // Q15, Theta output SLONG slPllSpdPu; // Q20, 32-bits Speed of PLL SWORD swPllSpdPu; // Q15, 16-bits Speed of PLL SLONG slPllSpdLpfPu; // Q15, 32-bits Speed of PLL SWORD swPllSpdLpfPu; // Q15, 16-bits Speed of PLL LPF_OUT stPllSpdOutLpf; // Q15, Speed out SLONG slPllPPu; // Q29, Intermediate variable of PLL SLONG slPllIProLimPu; // Q39, Intermediate variable of PLL SLONG slPllIPu; // Q29, Intermediate variable of PLL SLONG slPllIRemPu; // Q39, Intermediate variable of PLL BOOL blMagPorOkFlag; // Q0, Magnetic polarity detection ok flag BOOL blMagPorOvrFlag; // Q0, Magnetic polarity detection over flag SWORD swMagIdFbPPu; // Q14, d Current Feedback of postive voltage pluse SWORD swMagIdFbNPu; // Q14, q Current Feedback of negtive voltage pluse SWORD uwDeltaThetaPu; // Q15, compensative theta of Magnetic polarity } HFI_POLEPOS_OUT; /************************************************************************ Constant Table *************************************************************************/ /************************************************************************ Exported Variables: *************************************************************************/ #ifdef _HFINJ_C_ _HFINJ_EXT SWORD hfi_swIqFbLpfPu[HARWAVECOMNO] = {-9000, -8000, -7000, -6000, -5000, -4000, -3000, 0, 3000, 4000, 5000, 6000, 7000, 8000, 9000}; // Iq _HFINJ_EXT SWORD hfi_swDcOffSetPu[HARWAVECOMNO] = {-350, -295, -230, -180, -120, -70, -35, 0, 45, 80, 125, 195, 245, 320, 370}; // dc-offset-mul-saliency _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 _HFINJ_EXT SWORD hfi_swSixPhasePu[HARWAVECOMNO] = {11000, 10000, 10000, 10000, 8000, 8000, 9000, 9000, 9000, 8500, 8000, 7000, 6000, 5000, 5000}; // 6th-phase-offset-mul-saliency _HFINJ_EXT SWORD hfi_swPI[HARWAVECOMNO] = { 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 ) _HFINJ_EXT SWORD hfi_swDcSlope[HARWAVECOMNO] = { 0, 225, 266, 205, 246, 205, 143, 48, 61, 143, 184, 287, 205, 307, 205}; // Q12/slope-dc-offset-mul-saliency,last is zero, because slope number is one smaller _HFINJ_EXT SWORD hfi_swSixAmpSlope[HARWAVECOMNO] = {0, 0, 0, -82, -82, -164, -82, -14, 20, 102, 123, 82, 82, 0, 0}; // Q12/slope-6th-amp-offset-mul-saliency _HFINJ_EXT SWORD hfi_swSixThetaShiftSlope[HARWAVECOMNO] = {0, -256, 0, 0, -512, 0, 256, 0, 0, -128, -128, -256, -256, -256, 0}; // Q8/slope-th-phase-offset-mul-saliency _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 _HFINJ_EXT HFI_COF hfi_stCof = HFI_COF_DEFAULT; _HFINJ_EXT HFI_POLEPOS_OUT hfi_stPolePosOut = HFI_POLEPOS_OUT_DEFAULT; _HFINJ_EXT HFI_POLEPOS_IN hfi_stPolePosIn = HFI_POLEPOS_IN_DEFAULT; _HFINJ_EXT HFI_COF_IN hfi_stCofIn = HFI_COF_IN_DEFAULT; _HFINJ_EXT HFI_INJSTATE_DEF hfi_euInjState = IniPosCalc; _HFINJ_EXT UWORD hfi_uwCurHpfFreqHz = 50; // HPF _HFINJ_EXT UWORD hfi_uwDampingRatio = 35; // PLL-bandwidth-Hz _HFINJ_EXT UWORD hfi_uwMcoefPu = 20; // M _HFINJ_EXT SWORD hfi_swSixHarmShftPu = 0; // 6th harmonic saliency phase shift _HFINJ_EXT SWORD hfi_swSixHarmAmpPu = 0; // 6th harmonic amplitude _HFINJ_EXT SWORD hfi_swDcShftPu = 0; // dc distortion due to multiple saliency _HFINJ_EXT SWORD hfi_swVariPIPu = 80; // PI variation due to multiple saliency,initial value>1 #else _HFINJ_EXT HFI_COF hfi_stCof; _HFINJ_EXT HFI_POLEPOS_OUT hfi_stPolePosOut; _HFINJ_EXT HFI_POLEPOS_IN hfi_stPolePosIn; _HFINJ_EXT HFI_COF_IN hfi_stCofIn; _HFINJ_EXT HFI_INJSTATE_DEF hfi_euInjState; _HFINJ_EXT UWORD hfi_uwCurHpfFreqHz; _HFINJ_EXT UWORD hfi_uwDampingRatio; _HFINJ_EXT UWORD hfi_uwMcoefPu; _HFINJ_EXT UWORD hfi_swVariPIPu; #endif /************************************************************************ RAM ALLOCATION: *************************************************************************/ //#define hfi_stCofIn (*(HFI_COF_IN *)MN_BUFFER) //#define hfi_stPolePosIn (*(HFI_POLEPOS_IN *)TBC_BUFFER) /************************************************************************ Exported Function Call Prototypes (N/A) *************************************************************************/ #ifdef _HFINJ_C_ _HFINJ_EXT void hfi_voInit(void); _HFINJ_EXT void hfi_voCof(HFI_COF_IN *in, HFI_COF *cof); _HFINJ_EXT void hfi_voPolePosDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out); _HFINJ_EXT void hfi_voMagPorDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out); #else _HFINJ_EXT void hfi_voInit(void); _HFINJ_EXT void hfi_voCof(HFI_COF_IN *in, HFI_COF *cof); _HFINJ_EXT void hfi_voPolePosDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out); _HFINJ_EXT void hfi_voMagPorDetect(HFI_POLEPOS_IN *in, HFI_COF *cof, HFI_POLEPOS_OUT *out); #endif /************************************************************************ Flag Define (N/A) *************************************************************************/ /***********************************************************************/ #endif /************************************************************************ Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd. All rights reserved. ************************************************************************* End of this File (EOF): Do not put anything after this part! *************************************************************************/