📄 aci3_3.c
字号:
/* ==============================================================================
System Name: ACI33_SIM (Floating-point version)
File Name: ACI3_3.C
Description: Primary system file for the Simulation of Sensored Indirect
Field Orientation Control for a Three Phase AC Induction Motor.
Originator: Digital control systems Group - Texas Instruments
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20: Support both F280x and F281x targets
04-25-2005 Version 3.21: Move EINT and ERTM down to ensure that all initialization
is completed before interrupts are allowed.
================================================================================= */
// Include header files used in the main function
#include "target.h"
#if (DSP_TARGET==F2808)
#include "DSP280x_Device.h"
#endif
#if (DSP_TARGET==F2812)
#include "DSP281x_Device.h"
#endif
#include "aci3_3.h"
#include "parameter.h"
#include "build.h"
#include <math.h>
// Prototype statements for functions found within this file.
interrupt void MainISR(void);
// Global variables used in this system
float32 VdTesting = 0.25; // Vd testing (pu)
float32 VqTesting = 0; // Vq testing (pu)
float32 IdRef = 0.4; // Id reference (pu)
float32 IqRef = 0.05; // Iq reference (pu)
float32 SpeedRef = 0.5; // Speed reference (pu)
float32 T = SAMPLING_PERIOD; // Samping period (sec), see parameter.h
Uint16 IsrTicker = 0;
Uint16 BackTicker = 0;
int16 PwmDacCh1=0;
int16 PwmDacCh2=0;
int16 PwmDacCh3=0;
int16 DlogCh1 = 0;
int16 DlogCh2 = 0;
int16 DlogCh3 = 0;
int16 DlogCh4 = 0;
volatile Uint16 EnableFlag = FALSE;
// Instance a induction model object
ACI aci1 = ACI_DEFAULTS;
// Instance a current model object
CURMOD cm1 = CURMOD_DEFAULTS;
// Instance a few transform objects
PARK park1 = PARK_DEFAULTS;
IPARK ipark1 = IPARK_DEFAULTS;
// Instance PID regulators to regulate the d and q synchronous axis currents,
// and speed
PIDREG3 pid1_id = PIDREG3_DEFAULTS;
PIDREG3 pid1_iq = PIDREG3_DEFAULTS;
PIDREG3 pid1_spd = PIDREG3_DEFAULTS;
// Instance a ramp controller to smoothly ramp the frequency
RMPCNTL rc1 = RMPCNTL_DEFAULTS;
// Instance a ramp generator to simulate an Anglele
RAMPGEN rg1 = RAMPGEN_DEFAULTS;
// Instance a PWM driver instance
PWMGEN pwm1 = PWMGEN_DEFAULTS;
// Instance a PWM DAC driver instance
PWMDAC pwmdac1 = PWMDAC_DEFAULTS;
// Instance a induction model constant object
ACI_CONST aci1_const = ACI_CONST_DEFAULTS;
// Instance a current model constant object
CURMOD_CONST cm1_const = CURMOD_CONST_DEFAULTS;
// Create an instance of DATALOG Module
DLOG_4CH dlog = DLOG_4CH_DEFAULTS;
void main(void)
{
// ******************************************
// Initialization code for DSP_TARGET = F2808
// ******************************************
#if (DSP_TARGET==F2808)
// Initialize System Control registers, PLL, WatchDog, Clocks to default state:
// This function is found in the DSP280x_SysCtrl.c file.
InitSysCtrl();
// Globally synchronize all ePWM modules to the time base clock (TBCLK)
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
// HISPCP prescale register settings, normally it will be set to default values
EALLOW; // This is needed to write to EALLOW protected registers
SysCtrlRegs.HISPCP.all = 0x0000; // SYSCLKOUT/1
EDIS; // This is needed to disable write to EALLOW protected registers
// Disable and clear all CPU interrupts:
DINT;
IER = 0x0000;
IFR = 0x0000;
// Initialize Pie Control Registers To Default State:
// This function is found in the DSP280x_PieCtrl.c file.
InitPieCtrl();
// Initialize the PIE Vector Table To a Known State:
// This function is found in DSP280x_PieVect.c.
// This function populates the PIE vector table with pointers
// to the shell ISR functions found in DSP280x_DefaultIsr.c.
InitPieVectTable();
// User specific functions, Reassign vectors (optional), Enable Interrupts:
// Waiting for enable flag set
while (EnableFlag==FALSE)
{
BackTicker++;
}
// Enable CNT_zero interrupt using EPWM1 Time-base
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation
EPwm1Regs.ETSEL.bit.INTSEL = 1; // Enable interrupt CNT_zero event
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate interrupt on the 1st event
EPwm1Regs.ETCLR.bit.INT = 1; // Enable more interrupts
// Reassign ISRs.
// Reassign the PIE vector for EPWM1_INT to point to a different
// ISR then the shell routine found in DSP280x_DefaultIsr.c.
// This is done if the user does not want to use the shell ISR routine
// but instead wants to use their own ISR. This step is optional:
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EPWM1_INT = &MainISR;
EDIS; // This is needed to disable write to EALLOW protected registers
// Enable PIE group 3 interrupt 1 for EPWM1_INT
PieCtrlRegs.PIEIER3.all = M_INT1;
// Enable CPU INT3 for EPWM1_INT:
IER |= M_INT3;
#endif
// ******************************************
// Initialization code for DSP_TARGET = F2812
// ******************************************
#if (DSP_TARGET==F2812)
// Initialize System Control registers, PLL, WatchDog, Clocks to default state:
// This function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// HISPCP prescale register settings, normally it will be set to default values
EALLOW; // This is needed to write to EALLOW protected registers
SysCtrlRegs.HISPCP.all = 0x0000; // SYSCLKOUT/1
EDIS; // This is needed to disable write to EALLOW protected registers
// Disable and clear all CPU interrupts:
DINT;
IER = 0x0000;
IFR = 0x0000;
// Initialize Pie Control Registers To Default State:
// This function is found in the DSP281x_PieCtrl.c file.
InitPieCtrl();
// Initialize the PIE Vector Table To a Known State:
// This function is found in DSP281x_PieVect.c.
// This function populates the PIE vector table with pointers
// to the shell ISR functions found in DSP281x_DefaultIsr.c.
InitPieVectTable();
// User specific functions, Reassign vectors (optional), Enable Interrupts:
// Initialize EVA Timer 1:
// Setup Timer 1 Registers (EV A)
EvaRegs.GPTCONA.all = 0;
// Waiting for enable LowFreqag set
while (EnableFlag==FALSE)
{
BackTicker++;
}
// Enable Underflow interrupt bits for GP timer 1
EvaRegs.EVAIMRA.bit.T1UFINT = 1;
EvaRegs.EVAIFRA.bit.T1UFINT = 1;
// Reassign ISRs.
// Reassign the PIE vector for T1UFINT to point to a different
// ISR then the shell routine found in DSP281x_DefaultIsr.c.
// This is done if the user does not want to use the shell ISR routine
// but instead wants to use their own ISR. This step is optional:
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.T1UFINT = &MainISR;
EDIS; // This is needed to disable write to EALLOW protected registers
// Enable PIE group 2 interrupt 6 for T1UFINT
PieCtrlRegs.PIEIER2.all = M_INT6;
// Enable CPU INT2 for T1UFINT:
IER |= M_INT2;
#endif
// Initialize PWM module
#if (DSP_TARGET==F2808)
pwm1.PeriodMax = 0x61A8; // ISR frequency = 2 kHz with 100MHz clock (0x61A8 = 25000)
#endif
#if (DSP_TARGET==F2812)
pwm1.PeriodMax = 0x927C; // ISR frequency = 2 kHz with 150MHz clock (0x927C = 37500)
#endif
pwm1.init(&pwm1);
// Initialize PWMDAC module
pwmdac1.PeriodMax = 2500; // PWM frequency = 30 kHz
pwmdac1.PwmDacInPointer0 = &PwmDacCh1;
pwmdac1.PwmDacInPointer1 = &PwmDacCh2;
pwmdac1.PwmDacInPointer2 = &PwmDacCh3;
pwmdac1.init(&pwmdac1);
// Initialize DATALOG module
dlog.iptr1 = &DlogCh1;
dlog.iptr2 = &DlogCh2;
dlog.iptr3 = &DlogCh3;
dlog.iptr4 = &DlogCh4;
dlog.trig_value = 0x0;
dlog.size = 0x400;
dlog.prescalar = 1;
dlog.init(&dlog);
// Initialize RAMPGEN module
rg1.StepAngleMax = BASE_FREQ*T;
// Initialize RAMP_CNTL module
rc1.RampDelayMax = 1;
// Initialize the ACI constant module
aci1_const.Rs = RS;
aci1_const.Rr = RR;
aci1_const.Ls = LS;
aci1_const.Lr = LR;
aci1_const.Lm = LM;
aci1_const.p = P;
aci1_const.B = BB;
aci1_const.J = JJ;
aci1_const.Ib = BASE_CURRENT;
aci1_const.Vb = BASE_VOLTAGE;
aci1_const.Wb = 2*PI*BASE_FREQ;
aci1_const.Tb = BASE_TORQUE;
aci1_const.Lb = BASE_FLUX;
aci1_const.Ts = T;
aci1_const.calc(&aci1_const);
// Initialize the ACI module
aci1.K1 = aci1_const.K1;
aci1.K2 = aci1_const.K2;
aci1.K3 = aci1_const.K3;
aci1.K4 = aci1_const.K4;
aci1.K5 = aci1_const.K5;
aci1.K6 = aci1_const.K6;
aci1.K7 = aci1_const.K7;
aci1.K8 = aci1_const.K8;
aci1.K9 = aci1_const.K9;
aci1.K10 = aci1_const.K10;
aci1.BaseRpm = 120*BASE_FREQ/P;
aci1.LoadTorque = TL/BASE_TORQUE;
// Initialize the CUR_MOD constant module
cm1_const.Rr = RR;
cm1_const.Lr = LR;
cm1_const.fb = BASE_FREQ;
cm1_const.Ts = T;
cm1_const.calc(&cm1_const);
// Initialize the CUR_MOD module
cm1.Kr = cm1_const.Kr;
cm1.Kt = cm1_const.Kt;
cm1.K = cm1_const.K;
// Initialize the PID module for Id
pid1_id.Kp = 0.0541;
pid1_id.Ki = T/0.001;
pid1_id.Kd = 0/T;
pid1_id.Kc = 0.1;
pid1_id.OutMax = 0.71;
pid1_id.OutMin = -0.71;
// Initialize the PID module for Iq
pid1_iq.Kp = 0.0541;
pid1_iq.Ki = T/0.001;
pid1_iq.Kd = 0/T;
pid1_iq.Kc = 0.1;
pid1_iq.OutMax = 0.71;
pid1_iq.OutMin = -0.71;
// Initialize the PID module for speed
pid1_spd.Kp = 7.2;
pid1_spd.Ki = T/0.01;
pid1_spd.Kd = 0/T;
pid1_spd.Kc = 0.9;
pid1_spd.OutMax = 1;
pid1_spd.OutMin = -1;
// 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 RMP module and call the Ramp control
// calculation function.
// ------------------------------------------------------------------------------
rc1.TargetValue = 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);
// ------------------------------------------------------------------------------
// Connect inputs of the INV_PARK module and call the inverse park transformation
// calculation function.
// ------------------------------------------------------------------------------
ipark1.Ds = VdTesting;
ipark1.Qs = VqTesting;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -