/************************************************************************ Project: Welling Motor Control Paltform Filename: dbc.c Partner Filename: dbc.h Description: Dead time compensation of three-phase voltage inverter 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): ************************************************************************/ /************************************************************************ Beginning of File, do not put anything above here except notes Compiler Directives: *************************************************************************/ #ifndef _DBC_C_ #define _DBC_C_ #endif /************************************************************************ Included File: *************************************************************************/ #include "dbc.h" #include "glbcof.h" /************************************************************************ Function: dbc_voDBCompCoef; Description: deadband compensation coefficient initial; Call by: functions in main loop; Input Variables: DBC_COF_IN; Output/Return Variables: DBC_CALC_COF; Subroutine Call: N/A; Reference: N/A; *************************************************************************/ ULONG ulKcoef; SLONG slPWMPerNs; SLONG slPosLostVoltNs; SLONG slNegWinVoltNs; void dbc_voDBCompCoef(DBC_COF_IN *in, DBC_CALC_COF *out) { // ULONG ulKcoef; // SLONG slPWMPerNs; // SLONG slPosLostVoltNs; // SLONG slNegWinVoltNs; slPWMPerNs = in->ulPWMPerUs * 100; if (slPWMPerNs < 100) { slPWMPerNs = 100; } if (in->uwDeadBandTimeNs > 5000) { in->uwDeadBandTimeNs = 5000; } if (in->uwPosSwOnTimeNs > 3000) { in->uwPosSwOnTimeNs = 3000; } if (in->uwPosSwOffTimeNs > 3000) { in->uwPosSwOffTimeNs = 3000; } if (in->uwNegSwOnTimeNs > 3000) { in->uwNegSwOnTimeNs = 3000; } if (in->uwNegSwOffTimeNs > 3000) { in->uwNegSwOffTimeNs = 3000; } if (in->uwKcoefVtPerAp > 1000) { in->uwKcoefVtPerAp = 1000; } if (in->uwIBaseAp > 10000) { in->uwIBaseAp = 10000; } if (in->uwVBaseVt > 10000) { in->uwVBaseVt = 10000; } else if (in->uwVBaseVt < 10) { in->uwVBaseVt = 10; } slPosLostVoltNs = (SLONG)in->uwDeadBandTimeNs + in->uwPosSwOnTimeNs - in->uwPosSwOffTimeNs; if (slPosLostVoltNs > (slPWMPerNs >> 1)) { slPosLostVoltNs = (slPWMPerNs >> 1); } else if (slPosLostVoltNs < 0) { slPosLostVoltNs = 0; } out->uwPosLostVoltDuty = (slPosLostVoltNs << 14) / slPWMPerNs; // Q14 slNegWinVoltNs = (SLONG)in->uwDeadBandTimeNs + in->uwNegSwOnTimeNs - in->uwNegSwOffTimeNs; if (slNegWinVoltNs > (slPWMPerNs >> 1)) { slNegWinVoltNs = (slPWMPerNs >> 1); } else if (slNegWinVoltNs < 0) { slNegWinVoltNs = 0; } out->uwNegWinVoltDuty = (slNegWinVoltNs << 14) / slPWMPerNs; // Q14 ulKcoef = (((ULONG)in->uwKcoefVtPerAp * in->uwIBaseAp) << 6) / in->uwVBaseVt / 100; // Q6, Deadband compensation slope coefficient if (ulKcoef > 32767) { ulKcoef = 32767; } else { out->uwKcoef = ulKcoef; } } /************************************************************************ Function: dbc_voDBComp; Description: voltage composation for deadband; Call by: functions in TBC; Input Variables: DBC_CALC_IN, DBC_CALC_COF; Output/Return Variables: DBC_CALC_OUT; Subroutine Call: N/A; Reference: N/A; *************************************************************************/ void dbc_voDBComp(DBC_CALC_IN *in, DBC_CALC_COF *coef, DBC_CALC_OUT *out) { SLONG slUaCompPrePu, slUaCompPu, slUbCompPrePu, slUbCompPu, slUcCompPrePu, slUcCompPu, slPosLostVoltPu, slNegWinVoltPu; if (in->swWsPu > cof_uw100RpmPu) { slPosLostVoltPu = ((SLONG)in->uwVdcPu * coef->uwPosLostVoltDuty >> 14); // Q14=Q14+Q14-Q14 slNegWinVoltPu = ((SLONG)in->uwVdcPu * coef->uwNegWinVoltDuty >> 14); // Q14=Q14+Q14-Q14 slUaCompPrePu = (SLONG)in->swIaPu * coef->uwKcoef >> 6; // Q14=Q14+Q6-Q6 slUbCompPrePu = (SLONG)in->swIbPu * coef->uwKcoef >> 6; // Q14=Q14+Q6-Q6 slUcCompPrePu = (SLONG)in->swIcPu * coef->uwKcoef >> 6; // Q14=Q14+Q6-Q6 if (slPosLostVoltPu > 32767) { slPosLostVoltPu = 32767; } else if (slPosLostVoltPu < -32768) { slPosLostVoltPu = -32768; } if (slNegWinVoltPu > 32767) { slNegWinVoltPu = 32767; } else if (slNegWinVoltPu < -32768) { slNegWinVoltPu = -32768; } /* Uacomp, Ubcomp, Uccomp limination */ if (slUaCompPrePu > slPosLostVoltPu) { slUaCompPu = slPosLostVoltPu; } else if (slUaCompPrePu < -slNegWinVoltPu) { slUaCompPu = -slNegWinVoltPu; } else { slUaCompPu = slUaCompPrePu; } if (slUbCompPrePu > slPosLostVoltPu) { slUbCompPu = slPosLostVoltPu; } else if (slUbCompPrePu < -slNegWinVoltPu) { slUbCompPu = -slNegWinVoltPu; } else { slUbCompPu = slUbCompPrePu; } if (slUcCompPrePu > slPosLostVoltPu) { slUcCompPu = slPosLostVoltPu; } else if (slUcCompPrePu < -slNegWinVoltPu) { slUcCompPu = -slNegWinVoltPu; } else { slUcCompPu = slUcCompPrePu; } /* Ialfa = 2/3 * ia - 1/3 * ib - 1/3 * ic */ out->swUalphaCompPu = (slUaCompPu * 2 - slUbCompPu - slUcCompPu) * 10923 >> 15; // Q14=Q14+Q15-Q15 /* Ibeta = 1 / sqrt(3) * (ib - ic) */ out->swUbetaCompPu = (slUbCompPu - slUcCompPu) * 18919 >> 15; // Q14=Q14+Q15-Q15 } else { out->swUalphaCompPu = 0; // Q14=Q14+Q15-Q15 out->swUbetaCompPu = 0; // Q14=Q14+Q15-Q15 } } /************************************************************************ Function: asr_voSpdPIInit; Description: deadband compensation initialization; Call by: functions in main loop; Input Variables: N/A; Output/Return Variables: N/A; Subroutine Call: N/A; Reference: N/A; *************************************************************************/ void dbc_voDBCompInit(void) { dbc_stDbCompOut.swUalphaCompPu = 0; dbc_stDbCompOut.swUbetaCompPu = 0; } /************************************************************************* Local Functions (N/A) *************************************************************************/ /************************************************************************ Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd. All rights reserved. *************************************************************************/ #ifdef _DBC_C_ #undef _DBC_C_ #endif /************************************************************************* End of this File (EOF): !!!!!!Do not put anything after this part!!!!!!!!!!! *************************************************************************/