/************************************************************************ Project: Welling Motor Control Paltform Filename: pwm.h Partner Filename: pwm.c Description: The header file of pwm.c Complier: IAR Embedded Workbench for ARM 7.80.4 CPU TYPE : GD32F3x0 ************************************************************************* Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd. All rights reserved. ************************************************************************* ************************************************************************* Revising History (ECL of this file): ************************************************************************/ /************************************************************************ Beginning of File, do not put anything above here except notes Compiler Directives ************************************************************************/ #ifndef PWM_H #define PWM_H /************************************************************************ Compiler Directives (N/A) ************************************************************************/ #ifdef _PWM_C_ #define PWM_EXT #else #define PWM_EXT extern #endif #include "typedefine.h" /************************************************************************ Definitions & Macros (#define ...) ************************************************************************/ #define PWM_GEN_COF_DEFAULT \ { \ 15400, 13762, 2, 5250, 2625, 1313, 400, 2436 \ } // Default value of PWM_CALC_COF #define PWM_GEN_OUT_DEFAULT \ { \ 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, IgnoreNone, SampleNone, 108, 0, FALSE, FALSE \ } // Default value of PWM_GEN_OUT #define PWM_SQRT3 28378 // Q14, sqrt(3) #define PWM_1DIV3 5461 // Q14, 1/3 #define PWM_SQRT3_INV 9459 // Q14, 1/sqrt(3) /************************************************************************ TypeDefs & Structure defines for " XXX " ************************************************************************/ typedef enum { IgnoreNone = 0, IgnoreA = 1, IgnoreB = 2, IgnoreC = 3, IgnoreAB = 4, IgnoreBC = 5, IgnoreAC = 6 } RDSON_SAMPLE_AREA; typedef enum { SampleNone = 0, SampleA = 1, SampleB = 2, SampleC = 3, } SINGELR_SAMPLE_AREA; typedef struct { SWORD swUalphaPu; // Q14 SWORD swUbetaPu; // Q14 SWORD swUalphaCompPu; // Q14, Deadband compensation of Ualpha SWORD swUbetaCompPu; // Q14, Deadband compensation of Ubeta UWORD uwVdcPu; // Q14 } PWM_GEN_IN; typedef struct // Input of " pwm_voGenCoef " { UWORD uwPWMDutyMax; // Real Value, Unit:%, Max duty ratio in svpwm UWORD uwPWM7To5Duty; // Real Value, Unit:%, Switch duty ratio from 7 to 5 svpwm UWORD uwPWMMinSample1Pu; // Q14, unit:Pu two zero vector UWORD uwPWMMinSample2Pu; // Q14, unit:Pu (one zero vector + sample time)*2 UWORD uwPWMMinSample3Pu; // Q14, unit:Pu (one zero vector + sample time)*2 UWORD uwOvmNo; // Real Value, Unit:1, Number of over modulation type UWORD uwPWMPd; // Real Value, Unit:1, PWM period UWORD uwSampleSteadyPu; // UWORD uwSingelResisSamplePu; // } PWM_COF_IN; typedef struct // Output of " pwm_voGenCoef " { UWORD swPWMDutyMaxPu; // Q14, unit:Pu, Max duty ratio in svpwm UWORD swPWM7To5DutyPu; // Q14, unit:Pu, Switch duty ratio from 7 to 5 svpwm UWORD swPWMMinSample1Pu; // Q14, unit:Pu two zero vector UWORD swPWMMinSample2Pu; // Q14, unit:Pu (one zero vector + sample time)*2 UWORD swPWMMinSample3Pu; // Q14, unit:Pu (SignalResisToSteadyTime + sample time)*2 UWORD swPWMPu; // Q14, unit:Pu (SignalResisToSteadyTime + sample time)*2 UWORD uwOvmNo; // Q0, Number of over modulation type UWORD uwPWMPd; // Q0, PWM period UWORD uwHPWMPd; // Q0, half PWM period UWORD uwHHPWMPd; // Q0, half of half PWM period ULONG ulPWMPerInv; // Q21, unit:Pu, 1/PWM period UWORD uwMaxCmpCt; // Q14, unit:Pu, Max compare value in svpwm UWORD uwSampleSteadyCt; UWORD uwSingelResisSampleCt; // Q14, unit:Pu, } PWM_CALC_COF; typedef struct { SWORD swUalphaPu; // Q14 SWORD swUbetaPu; // Q14 UWORD uwFirstTrigCOMPR; UWORD uwSecondTrigCOMPR; UWORD uwNewTIM1COMPR[6]; UWORD uwNewSectorNum; UWORD uwOldTrig; UWORD uwNewTrig; UWORD uwPWMNewSectorNum; RDSON_SAMPLE_AREA uwSampleArea; SINGELR_SAMPLE_AREA uwSingelRSampleArea; UWORD uwRDSONTrig; UWORD uwSigRTrig; BOOL blOvmFlag; BOOL blSampleCalibFlag; } PWM_GEN_OUT; /************************************************************************ Exported Variables: ************************************************************************/ #ifdef _PWM_C_ PWM_EXT PWM_CALC_COF pwm_stGenCoef = PWM_GEN_COF_DEFAULT; PWM_EXT PWM_GEN_OUT pwm_stGenOut = PWM_GEN_OUT_DEFAULT; #else PWM_EXT PWM_CALC_COF pwm_stGenCoef; PWM_EXT PWM_GEN_OUT pwm_stGenOut; #endif /************************************************************************ RAM ALLOCATION: ************************************************************************/ #define pwm_stGenCoefIn (*(PWM_COF_IN *)MN_BUFFER) #define pwm_stGenIn (*(PWM_GEN_IN *)TBC_BUFFER) /************************************************************************ Exported Function Call Prototypes (N/A) ************************************************************************/ #ifdef _PWM_C_ PWM_EXT void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out); PWM_EXT void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef); PWM_EXT void pwm_voInit(void); #else PWM_EXT void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out); PWM_EXT void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef); PWM_EXT void pwm_voInit(void); #endif /************************************************************************ Local Function Call Prototypes (N/A) ************************************************************************/ /************************************************************************ 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! ************************************************************************/