我是一个在校生,刚接触F28335,最近在做SVPWM相关的实验,有用到PWM中断,程序如下:(没有进入PWM中断服务子程序希望大神讲解一下)
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "math.h"
#include "IQmathLib.h"
//#include "DSP2833x_CpuTimers.c"
//#include "DSP2833x_PieCtrl.c"
//#include "DSP2833x_PieVect.c"
#if (CPU_FRQ_150MHZ)
#define CPU_CLK 150e6
#endif
#if (CPU_FRQ_100MHZ)
#define CPU_CLK 100e6
#endif
#define PWM_CLK 10e3 // If diff freq. desired, change freq here.
#define SP CPU_CLK/(2*PWM_CLK)
#define TBCTLVAL 0x200E // Up-down cnt, timebase = SYSCLKOUT
#define Valpha 0
#define Vbeta 8
#define Tpwm 7500
#define T 0.0001
#define Udc 24
interrupt void epwm1_isr(void);
Uint16 *ExRamStart = (Uint16 *)0x100000;
void EPwmSetup();
void Section();
void TIMER12();
//Uint16 i;
//float Valpha,Vbeta;
float A,B,C,Sector;
float Ta,Tb,Tc,CMPR1,CMPR2,CMPR3;
//float Tpwm,Udc;
//float Valpha,Vbeta;
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
InitXintf16Gpio(); //zq
InitEPwm1Gpio();
InitEPwm2Gpio();
InitEPwm3Gpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2833x_CpuTimers.c
// InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EPWM1_INT = &epwm1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// For this example, only initialize the ePWM
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
// EPwmSetup();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
// Step 5. User specific code, enable interrupts:
// Enable CPU INT3 which is connected to EPWM1-3 INT:
IER |= M_INT3;
// Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//ConfigCpuTimer(&CpuTimer0, 150, 1000000);
//ConfigCpuTimer(&CpuTimer1, 150, 1000000);
//ConfigCpuTimer(&CpuTimer2, 150, 1000000);
// StartCpuTimer0();
// for(i=0;i<361;i++)
// {
// if(i=360)
// {
// i=0;
// }
// Valpha=8*cos(i);
//Vbeta=8*sin(i);
// Section();
// TIMER12();
// EPwmSetup();
// }
for(; 😉
{
}
}
void EPwmSetup()
{
//InitEPwm1Gpio();
EPwm1Regs.TBSTS.all=0;
EPwm1Regs.TBPHS.half.TBPHS=0;
EPwm1Regs.TBCTR=0;
EPwm1Regs.CMPCTL.all=0x50; // Immediate mode for CMPA and CMPB
EPwm1Regs.CMPA.half.CMPA =CMPR1;
EPwm1Regs.CMPB=SP/2;
EPwm1Regs.AQCTLA.all=0x60; // EPWMxA = 1 when CTR=CMPA and counter inc
// EPWMxA = 0 when CTR=CMPA and counter dec
EPwm1Regs.AQCTLB.all=0x60;
// EPwm1Regs.AQCTLB.all=0;
EPwm1Regs.AQSFRC.all=0;
EPwm1Regs.AQCSFRC.all=0;
EPwm1Regs.DBCTL.all=0xb; // EPWMxB is inverted
EPwm1Regs.DBRED=0x4b;
EPwm1Regs.DBFED=0x4b;
EPwm1Regs.TZSEL.all=0;
EPwm1Regs.TZCTL.all=0;
EPwm1Regs.TZEINT.all=0;
EPwm1Regs.TZFLG.all=0;
EPwm1Regs.TZCLR.all=0;
EPwm1Regs.TZFRC.all=0;
EPwm1Regs.ETSEL.all=0; // Interrupt when TBCTR = 0x0000
EPwm1Regs.ETFLG.all=0;
EPwm1Regs.ETCLR.all=0;
EPwm1Regs.ETFRC.all=0;
EPwm1Regs.PCCTL.all=0;
EPwm1Regs.TBCTL.all=0x0010+TBCTLVAL; // Enable Timer
EPwm1Regs.TBPRD=SP;
//InitEPwm2Gpio();
EPwm2Regs.TBSTS.all=0;
EPwm2Regs.TBPHS.half.TBPHS=0;
EPwm2Regs.TBCTR=0;
EPwm2Regs.CMPCTL.all=0x50; // Immediate mode for CMPA and CMPB
EPwm2Regs.CMPA.half.CMPA =CMPR2;
EPwm2Regs.CMPB=SP/2;
EPwm2Regs.AQCTLA.all=0x60; // EPWMxA = 1 when CTR=CMPA and counter inc
// EPWMxA = 0 when CTR=CMPA and counter dec
EPwm2Regs.AQCTLB.all=0x60;
// EPwm2Regs.AQCTLB.all=0;
EPwm2Regs.AQSFRC.all=0;
EPwm2Regs.AQCSFRC.all=0;
EPwm2Regs.DBCTL.all=0xb; // EPWMxB is inverted
EPwm2Regs.DBRED=0x4b;
EPwm2Regs.DBFED=0x4b;
EPwm2Regs.TZSEL.all=0;
EPwm2Regs.TZCTL.all=0;
EPwm2Regs.TZEINT.all=0;
EPwm2Regs.TZFLG.all=0;
EPwm2Regs.TZCLR.all=0;
EPwm2Regs.TZFRC.all=0;
EPwm2Regs.ETSEL.all=0; // Interrupt when TBCTR = 0x0000
EPwm2Regs.ETFLG.all=0;
EPwm2Regs.ETCLR.all=0;
EPwm2Regs.ETFRC.all=0;
EPwm2Regs.PCCTL.all=0;
EPwm2Regs.TBCTL.all=0x0010+TBCTLVAL; // Enable Timer
EPwm2Regs.TBPRD=SP;
//InitEPwm3Gpio();
EPwm3Regs.TBSTS.all=0;
EPwm3Regs.TBPHS.half.TBPHS=0;
EPwm3Regs.TBCTR=0;
EPwm3Regs.CMPCTL.all=0x50; // Immediate mode for CMPA and CMPB
EPwm3Regs.CMPA.half.CMPA =CMPR3;
EPwm3Regs.CMPB=SP/2;
EPwm3Regs.AQCTLA.all=0x60; // EPWMxA = 1 when CTR=CMPA and counter inc
// EPWMxA = 0 when CTR=CMPA and counter dec
EPwm3Regs.AQCTLB.all=0x60;
// EPwm3Regs.AQCTLB.all=0;
EPwm3Regs.AQSFRC.all=0;
EPwm3Regs.AQCSFRC.all=0;
EPwm3Regs.DBCTL.all=0xb; // EPWMxB is inverted
EPwm3Regs.DBRED=0x4b;
EPwm3Regs.DBFED=0x4b;
EPwm3Regs.TZSEL.all=0;
EPwm3Regs.TZCTL.all=0;
EPwm3Regs.TZEINT.all=0;
EPwm3Regs.TZFLG.all=0;
EPwm3Regs.TZCLR.all=0;
EPwm3Regs.TZFRC.all=0;
EPwm3Regs.ETSEL.all=0; // Interrupt when TBCTR = 0x0000
EPwm3Regs.ETFLG.all=0;
EPwm3Regs.ETCLR.all=0;
EPwm3Regs.ETFRC.all=0;
EPwm3Regs.PCCTL.all=0;
EPwm3Regs.TBCTL.all=0x0010+TBCTLVAL; // Enable Timer
EPwm3Regs.TBPRD=SP;
}
/*interrupt void ISR_Timer0 (void)
{
CpuTimer0.InterruptCount++;
PieCtrlRegs.PIEACK.all=PIEACK_GROUP1;
CpuTimer0Regs.TCR.bit.TIF=1;
CpuTimer0Regs.TCR.bit.TRB=1;
Section();
TIMER12();
EPwm1Regs.CMPA.half.CMPA=CMPR1;
EPwm2Regs.CMPA.half.CMPA=CMPR2;
EPwm3Regs.CMPA.half.CMPA=CMPR3;
}*/
interrupt void epwm1_isr(void)
{
// Update the CMPA and CMPB values
Section();
TIMER12();
EPwmSetup();
// EPwm1Regs.CMPA.half.CMPA=CMPR1;
// EPwm2Regs.CMPA.half.CMPA=CMPR2;
// EPwm3Regs.CMPA.half.CMPA=CMPR3;
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void Section()
{
if(Vbeta>0)
{
A=1;
}
else
{
A=0;
}
if((1.732*Valpha-Vbeta)>0)
{
B=1;
}
else
{
B=0;
}
if((-1.732*Valpha-Vbeta)>0)
{
C=1;
}
else
{
C=0;
}
Sector=A+2*B+4*C;
//Sector=4;
}
void TIMER12()
{
float T1,T2,X,Y,Z;
X=(2*Vbeta/1.732)*T/Udc;
Y=(Vbeta/1.732+Valpha)*T/Udc;
Z=(Vbeta/1.732-Valpha)*T/Udc;
if(Sector==1)
{
T1=Z;
T2=Y;
if((T1+T2)>T)
{
T1=T1*T/(T1+T2);
T2=T2*T/(T1+T2);
}
Ta=(T-T1-T2)/2;
Tb=Ta+T1;
Tc=Tb+T2;
CMPR1=(Tb/T)*Tpwm;
CMPR2=(Ta/T)*Tpwm;
CMPR3=(Tc/T)*Tpwm;
}
if(Sector==2)
{
T1=Y;
T2=-X;
if((T1+T2)>T)
{
T1=T1*T/(T1+T2);
T2=T2*T/(T1+T2);
}
Ta=(T-T1-T2)/2;
Tb=Ta+T1;
Tc=Tb+T2;
CMPR1=(Ta/T)*Tpwm;
CMPR2=(Tc/T)*Tpwm;
CMPR3=(Tb/T)*Tpwm;
}
if(Sector==3)
{
T1=-Z;
T2=X;
if((T1+T2)>T)
{
T1=T1*T/(T1+T2);
T2=T2*T/(T1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