123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- /************************************************************************
- 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!!!!!!!!!!!
- *************************************************************************/
|