【DSP】TMS320F28035的ePWM定时中断程序,计算定时时长

 

【DSP】TMS320F28035的ePWM定时中断程序,计算定时时长_第1张图片

/**********************************************************************************
			 定时器中断(默认2分频)
**********************************************************************************/
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

#define PWM1_INT_ENABLE  1
#define PWM1_TIMER_TBPRD   30000
__interrupt void epwm1_timer_isr(void);
void InitEPwmTimer(void);
Uint32  EPwm1TimerIntCount;

void main(void)
{
    int i;
    InitSysCtrl();
    DINT;
    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;
    InitPieVectTable();

    EALLOW;  // This is needed to write to EALLOW protected registers
    PieVectTable.EPWM1_INT = &epwm1_timer_isr;
    EDIS;    // This is needed to disable write to EALLOW protected registers

    InitEPwmTimer();    // For this example, only initialize the ePWM Timers
    EPwm1TimerIntCount = 0;

    EALLOW;
    GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;
    EDIS;

    IER |= M_INT3;

    PieCtrlRegs.PIEIER3.bit.INTx1 = PWM1_INT_ENABLE;

    EINT;   // Enable Global interrupt INTM
    ERTM;   // Enable Global realtime interrupt DBGM

    for(;;)
    {
        __asm("          NOP");
        for(i=1;i<=10;i++)
        {
            
        }
    }
}

void 
InitEPwmTimer()
{
    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;      // Stop all the TB clocks
    EDIS;

    EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;  // Pass through
    EPwm1Regs.TBCTL.bit.PHSEN = TB_ENABLE;
    EPwm1Regs.TBPHS.half.TBPHS = 100;

    EPwm1Regs.TBPRD = PWM1_TIMER_TBPRD;           //默认2分频,即60M/2 = 30M; 计数30次为1us;计数30000次为1000us产生一次定时器中断;16位计数器最大计数65535.
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;    // 向上计数模式
    //EPwm1Regs.TBCTL.bit.CLKDIV = 0X00;          //分频系数,详细配置参照数据表格
    //EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0X01;       //时基计数频率计算方式TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
    EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;     // Select INT on Zero event
    EPwm1Regs.ETSEL.bit.INTEN = PWM1_INT_ENABLE;  // Enable INT
    EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;           // Generate INT on 1st event

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;      // Start all the timers synced
    EDIS;
}

__interrupt void 
epwm1_timer_isr(void)
{
    EPwm1TimerIntCount++;
    GpioDataRegs.GPATOGGLE.bit.GPIO12 = 1;
    EPwm1Regs.ETCLR.bit.INT = 1;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}

 

你可能感兴趣的:(DSP)