📄 aci3_1.c
字号:
pid1_spd.Kd = _IQ(0/(T*SpeedLoopPrescaler));
pid1_spd.Kc = _IQ(0.2);
pid1_spd.OutMax = _IQ(0.05);
pid1_spd.OutMin = _IQ(-0.05);
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// IDLE loop. Just sit and loop forever:
for(;;) BackTicker++;
}
interrupt void MainISR(void)
{
// Verifying the ISR
IsrTicker++;
// ***************** LEVEL1 *****************
#if (BUILDLEVEL==LEVEL1)
// ------------------------------------------------------------------------------
// Connect inputs of the VOLT_PROF module and call the volt profile
// calculation function.
// ------------------------------------------------------------------------------
vhz1.Freq = _IQ(SpeedRef);
vhz1.calc(&vhz1);
// ------------------------------------------------------------------------------
// Connect inputs of the SVGEN_MF module and call the space-vector gen.
// calculation function.
// ------------------------------------------------------------------------------
svgen_mf1.Gain = vhz1.VoltOut;
svgen_mf1.Freq = vhz1.Freq;
svgen_mf1.calc(&svgen_mf1);
// ------------------------------------------------------------------------------
// Connect inputs of the PWMDAC module
// ------------------------------------------------------------------------------
PwmDacCh1 = (int16)_IQtoIQ15(svgen_mf1.Ta);
PwmDacCh2 = (int16)_IQtoIQ15(svgen_mf1.Tb);
PwmDacCh3 = (int16)_IQtoIQ15(svgen_mf1.Tc);
// ------------------------------------------------------------------------------
// Connect inputs of the DATALOG module
// ------------------------------------------------------------------------------
DlogCh1 = (int16)_IQtoIQ15(svgen_mf1.Ta);
DlogCh2 = (int16)_IQtoIQ15(svgen_mf1.Tb);
DlogCh3 = (int16)_IQtoIQ15(svgen_mf1.Tc);
DlogCh4 = (int16)_IQtoIQ15(svgen_mf1.Ta-svgen_mf1.Tb);
// ------------------------------------------------------------------------------
// 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==LEVEL1)
// ***************** LEVEL2 *****************
#if (BUILDLEVEL==LEVEL2)
// ------------------------------------------------------------------------------
// Connect inputs of the RMP_CNTL module and call the Ramp control
// calculation function.
// ------------------------------------------------------------------------------
rc1.TargetValue = _IQ(SpeedRef);
rc1.calc(&rc1);
// ------------------------------------------------------------------------------
// Connect inputs of the VOLT_PROF module and call the volt profile
// calculation function.
// ------------------------------------------------------------------------------
vhz1.Freq = rc1.SetpointValue; // Speed open-loop V/f control
vhz1.calc(&vhz1);
// ------------------------------------------------------------------------------
// Connect inputs of the SVGEN_MF module and call the space-vector gen.
// calculation function.
// ------------------------------------------------------------------------------
svgen_mf1.Gain = vhz1.VoltOut;
svgen_mf1.Freq = vhz1.Freq;
svgen_mf1.calc(&svgen_mf1);
// ------------------------------------------------------------------------------
// Connect inputs of the PWM_DRV module and call the PWM signal generation
// update function.
// ------------------------------------------------------------------------------
pwm1.MfuncC1 = (int16)_IQtoIQ15(svgen_mf1.Ta); // MfuncC1 is in Q15
pwm1.MfuncC2 = (int16)_IQtoIQ15(svgen_mf1.Tb); // MfuncC2 is in Q15
pwm1.MfuncC3 = (int16)_IQtoIQ15(svgen_mf1.Tc); // MfuncC3 is in Q15
pwm1.update(&pwm1);
// ------------------------------------------------------------------------------
// Connect inputs of the SPEED_PR module and call the speed calculation function
// ------------------------------------------------------------------------------
#if (DSP_TARGET==F2808)
if((cap1.read(&cap1))==0) // Call the capture read function
{
speed1.EventPeriod=(int32)(cap1.EventPeriod); // Read out new time stamp difference
speed1.calc(&speed1); // Call the speed calulator
}
#endif
#if (DSP_TARGET==F2812)
if((cap1.read(&cap1))==0) // Call the capture read function
{
speed1.TimeStamp=(int32)(cap1.TimeStamp); // Read out new time stamp
speed1.calc(&speed1); // Call the speed calulator
}
#endif
// ------------------------------------------------------------------------------
// Connect inputs of the PWMDAC module
// ------------------------------------------------------------------------------
PwmDacCh1 = (int16)_IQtoIQ15(svgen_mf1.Ta);
PwmDacCh2 = (int16)_IQtoIQ15(svgen_mf1.Tb);
PwmDacCh3 = (int16)_IQtoIQ15(svgen_mf1.Tc);
// ------------------------------------------------------------------------------
// Connect inputs of the DATALOG module
// ------------------------------------------------------------------------------
DlogCh1 = (int16)_IQtoIQ15(svgen_mf1.Ta);
DlogCh2 = (int16)_IQtoIQ15(svgen_mf1.Tb);
DlogCh3 = (int16)_IQtoIQ15(speed1.Speed);
DlogCh4 = (int16)_IQtoIQ15(vhz1.VoltOut);
// ------------------------------------------------------------------------------
// 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==LEVEL2)
// ***************** LEVEL3 *****************
#if (BUILDLEVEL==LEVEL3)
// ------------------------------------------------------------------------------
// Connect inputs of the RMP_CNTL module and call the Ramp control
// calculation function.
// ------------------------------------------------------------------------------
rc1.TargetValue = _IQ(SpeedRef);
rc1.calc(&rc1);
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 modules and compute the PID speed
// controller.
// ------------------------------------------------------------------------------
if (SpeedLoopCount == SpeedLoopPrescaler)
{
pid1_spd.Ref = rc1.SetpointValue;
pid1_spd.Fdb = speed1.Speed;
pid1_spd.calc(&pid1_spd);
SpeedLoopCount = 1;
}
else SpeedLoopCount ++;
// ------------------------------------------------------------------------------
// Connect inputs of the VOLT_PROF module for open-loop or closed-loop
// ------------------------------------------------------------------------------
if (ClosedLoopFlag==FALSE)
vhz1.Freq = rc1.SetpointValue; // Open-loop V/f control
else
vhz1.Freq = rc1.SetpointValue + pid1_spd.Out; // Speed closed-loop V/f control
// ------------------------------------------------------------------------------
// Call the volt profile calculation function.
// ------------------------------------------------------------------------------
vhz1.calc(&vhz1);
// ------------------------------------------------------------------------------
// Connect inputs of the SVGEN_MF module and call the space-vector gen.
// calculation function.
// ------------------------------------------------------------------------------
svgen_mf1.Gain = vhz1.VoltOut;
svgen_mf1.Freq = vhz1.Freq;
svgen_mf1.calc(&svgen_mf1);
// ------------------------------------------------------------------------------
// Connect inputs of the PWM_DRV module and call the PWM signal generation
// update function.
// ------------------------------------------------------------------------------
pwm1.MfuncC1 = (int16)_IQtoIQ15(svgen_mf1.Ta); // MfuncC1 is in Q15
pwm1.MfuncC2 = (int16)_IQtoIQ15(svgen_mf1.Tb); // MfuncC2 is in Q15
pwm1.MfuncC3 = (int16)_IQtoIQ15(svgen_mf1.Tc); // MfuncC3 is in Q15
pwm1.update(&pwm1);
// ------------------------------------------------------------------------------
// Connect inputs of the SPEED_PR module and call the speed calculation function
// ------------------------------------------------------------------------------
#if (DSP_TARGET==F2808)
if((cap1.read(&cap1))==0) // Call the capture read function
{
speed1.EventPeriod=(int32)(cap1.EventPeriod); // Read out new time stamp difference
speed1.calc(&speed1); // Call the speed calulator
}
#endif
#if (DSP_TARGET==F2812)
if((cap1.read(&cap1))==0) // Call the capture read function
{
speed1.TimeStamp=(int32)(cap1.TimeStamp); // Read out new time stamp
speed1.calc(&speed1); // Call the speed calulator
}
#endif
// ------------------------------------------------------------------------------
// Connect inputs of the PWMDAC module
// ------------------------------------------------------------------------------
PwmDacCh1 = (int16)_IQtoIQ15(svgen_mf1.Ta);
PwmDacCh2 = (int16)_IQtoIQ15(svgen_mf1.Tb);
PwmDacCh3 = (int16)_IQtoIQ15(svgen_mf1.Tc);
// ------------------------------------------------------------------------------
// Connect inputs of the DATALOG module
// ------------------------------------------------------------------------------
DlogCh1 = (int16)_IQtoIQ15(svgen_mf1.Ta);
DlogCh2 = (int16)_IQtoIQ15(svgen_mf1.Tb);
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==LEVEL3)
// ------------------------------------------------------------------------------
// Call the PWMDAC update function.
// ------------------------------------------------------------------------------
pwmdac1.update(&pwmdac1);
// ------------------------------------------------------------------------------
// 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 + -