📄 aci3_3.c
字号:
/* ==============================================================================
System Name: ACI33
File Name: ACI3_3.C
Description: Primary system file for the Sensored Indirect Field
Orientation Control for a Three Phase AC Induction Motor.
Originator: Digital control systems Group - Texas Instruments
Note: In this software, the default inverter is supposed to be DMC1500 board.
=====================================================================================
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==F2812)
#include "DSP281x_Device.h"
#endif
#include "IQmathLib.h"
#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.2; // Id reference (pu)
float32 IqRef = 0.05; // Iq reference (pu)
float32 SpeedRef = 0.5; // Speed reference (pu)
float32 T = 0.001/ISR_FREQUENCY; // 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;
Uint16 SpeedLoopPrescaler = 25; // Speed loop prescaler
Uint16 SpeedLoopCount = 1; // Speed loop counter
// Instance a current model object
//CURMOD cm1 = CURMOD_DEFAULTS;
// Instance a few transform objects
CLARKE clarke1 = CLARKE_DEFAULTS;
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 Space Vector PWM modulator. This modulator generates a, b and c
// phases based on the d and q stationery reference frame inputs
SVGENDQ svgen_dq1 = SVGENDQ_DEFAULTS;
// Instance a QEP interface driver
QEP qep1 = QEP_DEFAULTS;
// Instance a speed calculator based on QEP
SPEED_MEAS_QEP speed1 = SPEED_MEAS_QEP_DEFAULTS;
// Instance a enable PWM drive driver (only for DMC1500)
//DRIVE drv1 = DRIVE_DEFAULTS;
// Create an instance of the current/dc-bus voltage measurement driver
ILEG2DCBUSMEAS ilg2_vdc1 = ILEG2DCBUSMEAS_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 = 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 (EVA)
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.
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
pwm1.PeriodMax = SYSTEM_FREQUENCY*1000000*T/2; // Perscaler X1 (T1), ISR period = T x 1
pwm1.init(&pwm1);
// Initialize PWMDAC module
// pwmdac1.PeriodMax = (SYSTEM_FREQUENCY*200/(30*2))*5; // PWMDAC 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 QEP module
qep1.LineEncoder = 2048;
qep1.MechScaler = _IQ30(0.25/qep1.LineEncoder);
qep1.PolePairs = P/2;
qep1.CalibratedAngle = -1250;
qep1.init(&qep1);
// Initialize the Speed module for QEP based speed calculation
speed1.K1 = _IQ21(1/(BASE_FREQ*T));
speed1.K2 = _IQ(1/(1+T*2*PI*30)); // Low-pass cut-off frequency
speed1.K3 = _IQ(1)-speed1.K2;
speed1.BaseRpm = 120*(BASE_FREQ/P); //基速,因为P为极数,不是极对数
// Initialize enable drive module (FOR DMC1500 ONLY)
//drv1.init(&drv1);
// Initialize ADC module
ilg2_vdc1.init(&ilg2_vdc1);
// Initialize the SPEED_PR module
// #if (DSP_TARGET==F2812)
// x128-T2, 150MHz, 1000-teeth sprocket
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -