📄 pmsm3_3.c
字号:
// ------------------------------------------------------------------------------
// Connect inputs of the EN_DRV module and call the enable/disable PWM signal
// update function. (FOR DMC1500 ONLY)
// ------------------------------------------------------------------------------
drv1.EnableFlag = EnableFlag;
drv1.update(&drv1);
#endif // (BUILDLEVEL==LEVEL3)
// ***************** LEVEL4 *****************
#if (BUILDLEVEL==LEVEL4)
// ------------------------------------------------------------------------------
// Excitation signal generation for resolver sensor
// ------------------------------------------------------------------------------
SineRefSignal = _IQmpy(_IQ(Amplitude),_IQsinPU(_IQ(AngleExcitation)));
AngleExcitation += FreqExcitation*T;
if (AngleExcitation >= 1)
AngleExcitation -= 1;
// ------------------------------------------------------------------------------
// Connect inputs of the RMP module and call the Ramp control
// calculation function.
// ------------------------------------------------------------------------------
rc1.TargetValue = _IQ(SpeedRef);
rc1.calc(&rc1);
// ------------------------------------------------------------------------------
// Connect inputs of the RAMP GEN module and call the Ramp generator
// calculation function.
// ------------------------------------------------------------------------------
rg1.Freq = rc1.SetpointValue;
rg1.calc(&rg1);
// ------------------------------------------------------------------------------
// Call the ADC read function.
// ------------------------------------------------------------------------------
adc1.read(&adc1);
// ------------------------------------------------------------------------------
// Connect inputs of the CLARKE module and call the clarke transformation
// calculation function.
// ------------------------------------------------------------------------------
clarke1.As = _IQ15toIQ((int32)-adc1.Ch1Out); // Negate measured current based on DMC1500
clarke1.Bs = _IQ15toIQ((int32)-adc1.Ch2Out); // Negate measured current based on DMC1500
clarke1.calc(&clarke1);
// ------------------------------------------------------------------------------
// Connect inputs of the PARK module and call the park transformation
// calculation function.
// ------------------------------------------------------------------------------
park1.Alpha = clarke1.Alpha;
park1.Beta = clarke1.Beta;
park1.Angle = rg1.Out;
park1.calc(&park1);
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 module and call the PID IQ controller
// calculation function.
// ------------------------------------------------------------------------------
pid1_iq.Ref = _IQ(IqRef);
pid1_iq.Fdb = park1.Qs;
pid1_iq.calc(&pid1_iq);
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 module and call the PID ID controller
// calculation function.
// ------------------------------------------------------------------------------
pid1_id.Ref = _IQ(IdRef);
pid1_id.Fdb = park1.Ds;
pid1_id.calc(&pid1_id);
// ------------------------------------------------------------------------------
// Connect inputs of the INV_PARK module and call the inverse park transformation
// calculation function.
// ------------------------------------------------------------------------------
ipark1.Ds = pid1_id.Out;
ipark1.Qs = pid1_iq.Out;
ipark1.Angle = rg1.Out;
ipark1.calc(&ipark1);
// ------------------------------------------------------------------------------
// Connect inputs of the SVGEN_DQ module and call the space-vector gen.
// calculation function.
// ------------------------------------------------------------------------------
svgen_dq1.Ualpha = ipark1.Alpha;
svgen_dq1.Ubeta = ipark1.Beta;
svgen_dq1.calc(&svgen_dq1);
// ------------------------------------------------------------------------------
// Connect inputs of the PWM_DRV module and call the PWM signal generation
// update function.
// ------------------------------------------------------------------------------
pwm1.MfuncC1 = (int16)_IQtoIQ15(svgen_dq1.Ta); // MfuncC1 is in Q15
pwm1.MfuncC2 = (int16)_IQtoIQ15(svgen_dq1.Tb); // MfuncC2 is in Q15
pwm1.MfuncC3 = (int16)_IQtoIQ15(svgen_dq1.Tc); // MfuncC3 is in Q15
pwm1.update(&pwm1);
// ------------------------------------------------------------------------------
// Connect inputs of the Resolver PWM module and call its update
// function.
// ------------------------------------------------------------------------------
res_pwm1.RefSignal = _IQtoIQ15(SineRefSignal);
res_pwm1.update(&res_pwm1);
// ------------------------------------------------------------------------------
// Connect inputs of the RESOLVER module and call the speed/position calculation
// function.
// ------------------------------------------------------------------------------
speed1.SinIn = _IQ15toIQ((int32)adc1.Ch3Out);
speed1.CosIn = _IQ15toIQ((int32)adc1.Ch4Out);
speed1.calc(&speed1);
// ------------------------------------------------------------------------------
// Connect inputs of the DATALOG module
// ------------------------------------------------------------------------------
DlogCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
DlogCh2 = (int16)_IQtoIQ15(clarke1.As);
DlogCh3 = (int16)_IQtoIQ15(speed1.OutputTheta);
DlogCh4 = (int16)_IQtoIQ15(rg1.Out);
// ------------------------------------------------------------------------------
// Connect inputs of the EN_DRV module and call the enable/disable PWM signal
// update function. (FOR DMC1500 ONLY)
// ------------------------------------------------------------------------------
drv1.EnableFlag = EnableFlag;
drv1.update(&drv1);
#endif // (BUILDLEVEL==LEVEL4)
// ***************** LEVEL5 *****************
#if (BUILDLEVEL==LEVEL5)
// ------------------------------------------------------------------------------
// Excitation signal generation for resolver sensor
// ------------------------------------------------------------------------------
SineRefSignal = _IQmpy(_IQ(Amplitude),_IQsinPU(_IQ(AngleExcitation)));
AngleExcitation += FreqExcitation*T;
if (AngleExcitation >= 1)
AngleExcitation -= 1;
// ------------------------------------------------------------------------------
// Connect inputs of the RMP module and call the Ramp control
// calculation function.
// ------------------------------------------------------------------------------
rc1.TargetValue = _IQ(SpeedRef);
rc1.calc(&rc1);
// ------------------------------------------------------------------------------
// Call the ADC read function.
// ------------------------------------------------------------------------------
adc1.read(&adc1);
// ------------------------------------------------------------------------------
// Connect inputs of the CLARKE module and call the clarke transformation
// calculation function.
// ------------------------------------------------------------------------------
clarke1.As = _IQ15toIQ((int32)-adc1.Ch1Out); // Negate measured current based on DMC1500
clarke1.Bs = _IQ15toIQ((int32)-adc1.Ch2Out); // Negate measured current based on DMC1500
clarke1.calc(&clarke1);
// ------------------------------------------------------------------------------
// Connect inputs of the PARK module and call the park transformation
// calculation function.
// ------------------------------------------------------------------------------
park1.Alpha = clarke1.Alpha;
park1.Beta = clarke1.Beta;
park1.Angle = speed1.OutputTheta;
park1.calc(&park1);
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 module and call the PID speed controller
// calculation function.
// ------------------------------------------------------------------------------
if (SpeedLoopCount==SpeedLoopPrescaler)
{
// pid1_spd.Ref = rc1.SetpointValue;
pid1_spd.Ref = _IQ(SpeedRef);
pid1_spd.Fdb = speed1.Speed;
pid1_spd.calc(&pid1_spd);
SpeedLoopCount=1;
}
else SpeedLoopCount++;
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 module and call the PID IQ controller
// calculation function.
// ------------------------------------------------------------------------------
pid1_iq.Ref = pid1_spd.Out;
pid1_iq.Fdb = park1.Qs;
pid1_iq.calc(&pid1_iq);
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 module and call the PID ID controller
// calculation function.
// ------------------------------------------------------------------------------
pid1_id.Ref = _IQ(IdRef);
pid1_id.Fdb = park1.Ds;
pid1_id.calc(&pid1_id);
// ------------------------------------------------------------------------------
// Connect inputs of the INV_PARK module and call the inverse park transformation
// calculation function.
// ------------------------------------------------------------------------------
ipark1.Ds = pid1_id.Out;
ipark1.Qs = pid1_iq.Out;
ipark1.Angle = speed1.OutputTheta;
ipark1.calc(&ipark1);
// ------------------------------------------------------------------------------
// Connect inputs of the SVGEN_DQ module and call the space-vector gen.
// calculation function.
// ------------------------------------------------------------------------------
svgen_dq1.Ualpha = ipark1.Alpha;
svgen_dq1.Ubeta = ipark1.Beta;
svgen_dq1.calc(&svgen_dq1);
// ------------------------------------------------------------------------------
// Connect inputs of the PWM_DRV module and call the PWM signal generation
// update function.
// ------------------------------------------------------------------------------
pwm1.MfuncC1 = (int16)_IQtoIQ15(svgen_dq1.Ta); // MfuncC1 is in Q15
pwm1.MfuncC2 = (int16)_IQtoIQ15(svgen_dq1.Tb); // MfuncC2 is in Q15
pwm1.MfuncC3 = (int16)_IQtoIQ15(svgen_dq1.Tc); // MfuncC3 is in Q15
pwm1.update(&pwm1);
// ------------------------------------------------------------------------------
// Connect inputs of the Resolver PWM module and call its update
// function.
// ------------------------------------------------------------------------------
res_pwm1.RefSignal = _IQtoIQ15(SineRefSignal);
res_pwm1.update(&res_pwm1);
// ------------------------------------------------------------------------------
// Connect inputs of the RESOLVER module and call the speed/position calculation
// function.
// ------------------------------------------------------------------------------
speed1.SinIn = _IQ15toIQ((int32)adc1.Ch3Out);
speed1.CosIn = _IQ15toIQ((int32)adc1.Ch4Out);
speed1.calc(&speed1);
// ------------------------------------------------------------------------------
// Connect inputs of the DATALOG module
// ------------------------------------------------------------------------------
DlogCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
DlogCh2 = (int16)_IQtoIQ15(speed1.OutputTheta);
DlogCh3 = (int16)_IQtoIQ15(pid1_spd.Ref);
DlogCh4 = (int16)_IQtoIQ15(pid1_spd.Fdb);
// ------------------------------------------------------------------------------
// Connect inputs of the EN_DRV module and call the enable/disable PWM signal
// update function. (FOR DMC1500 ONLY)
// ------------------------------------------------------------------------------
drv1.EnableFlag = EnableFlag;
drv1.update(&drv1);
#endif // (BUILDLEVEL==LEVEL5)
// ------------------------------------------------------------------------------
// Call the DATALOG update function.
// ------------------------------------------------------------------------------
dlog.update(&dlog);
#if (DSP_TARGET==F2808)
// Enable more interrupts from this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge interrupt to recieve more interrupts from PIE group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
#endif
#if (DSP_TARGET==F2812)
// Enable more interrupts from this timer
EvaRegs.EVAIMRA.bit.T1UFINT = 1;
// Note: To be safe, use a mask value to write to the entire
// EVAIFRA register. Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear
// bits other then those intended.
EvaRegs.EVAIFRA.all = BIT9;
// Acknowledge interrupt to recieve more interrupts from PIE group 2
PieCtrlRegs.PIEACK.all |= PIEACK_GROUP2;
#endif
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -