Other Parts Discussed in Thread: C2000WARE
Tool/software:
Dear Experts,
I am trying to initialize the timer and PWM.First issue is the timer interrupt -is being called but I see there is a timing issue.
Here is my calculation for 1 second timer:
SYSCLK: 200MHz
CpuTimer0Regs.PRD.bit.LSW = 0x2D00;
CpuTimer0Regs.PRD.bit.MSW = 0x0131;
CpuTimer0Regs.TPR.bit.TDDR= 10;
Second, the PWM interrupt that is enabled at CTR=0 is not al all being called.
Here is the code
#include "F28x_Project.h" extern void InitSysCtrl(void); extern void InitPieCtrl(void); extern void InitPieVectTable(void); interrupt void TimerOvf(void); interrupt void PWM_Int(void); void Initialize_GPIO(void); void Initialize_PWM1(void); void Custom_Init(void); void timer0_init(void); int pwm,b=0; void main(void) { InitSysCtrl(); Custom_Init(); DINT; Initialize_GPIO(); Initialize_PWM1(); InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieCtrl(); InitPieVectTable(); EALLOW; PieCtrlRegs.PIEIER1.bit.INTx7 = 1; PieCtrlRegs.PIEIER3.bit.INTx1 = 1; PieVectTable.TIMER0_INT = &TimerOvf; PieVectTable.EPWM1_INT = &PWM_Int; PieCtrlRegs.PIECTRL.bit.ENPIE= 1; EDIS; IER |= 3; EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM timer0_init(); CpuTimer0Regs.TCR.bit.TSS=0; while(1) { } } void Initialize_GPIO(void) { EALLOW; GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1; GpioCtrlRegs.GPCDIR.bit.GPIO73= 1; GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; //EPwm1 EDIS; } void Custom_Init(void) { EALLOW; ClkCfgRegs.AUXPLLMULT.bit.IMULT=20; ClkCfgRegs.SYSCLKDIVSEL.bit.PLLSYSCLKDIV=0; ClkCfgRegs.SYSPLLCTL1.bit.PLLCLKEN = 1; ClkCfgRegs.LOSPCP.bit.LSPCLKDIV = 2; ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV = 0; CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1; ///source initsysctrl CpuSysRegs.PCLKCR2.bit.EPWM1 = 1; DevCfgRegs.CPUSEL0.bit.EPWM1 = 0; EDIS; } void Initialize_PWM1(void) { EPwm1Regs.TBCTL.bit.CTRMODE = 0; // Count up EPwm1Regs.TBPRD = 10000; // Set timer period EPwm1Regs.TBCTL.bit.PHSEN = 0; // Disable phase loading EPwm1Regs.TBPHS.bit.TBPHS = 0x0000; // Phase is 0 EPwm1Regs.TBCTR = 0x0000; // Clear counter EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; // Clock ratio to SYSCLKOUT EPwm1Regs.TBCTL.bit.CLKDIV = 0; EPwm1Regs.TBCTL.bit.SYNCOSEL = 1; // SYNC output on CTR = 0 // Setup shadow register load on ZERO EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0; EPwm1Regs.CMPCTL.bit.SHDWBMODE = 0; EPwm1Regs.CMPCTL.bit.LOADAMODE = 0; EPwm1Regs.CMPCTL.bit.LOADBMODE = 0; // Set Compare values EPwm1Regs.CMPA.bit.CMPA = 10000/2; // Set compare A value // Set actions EPwm1Regs.AQCTLA.bit.ZRO = 2; // Set PWM1A on Zero EPwm1Regs.AQCTLA.bit.CAU = 1; // Clear PWM1A on event A, up count //interrput enable EPwm1Regs.ETSEL.bit.INTSEL = 1; //@ CTR = 0 EPwm1Regs.ETSEL.bit.INTEN = 1; } void timer0_init(void) { EALLOW; CpuTimer0Regs.PRD.bit.LSW = 0x2D00; CpuTimer0Regs.PRD.bit.MSW = 0x0131; CpuTimer0Regs.TPR.bit.TDDR= 10; CpuTimer0Regs.TCR.bit.TIE= 1; CpuTimer0Regs.TCR.bit.TSS=1; CpuTimer0Regs.TCR.bit.FREE=0; CpuTimer0Regs.TCR.bit.TRB=0; EDIS; } void TimerOvf(void) { b= b+1; if(b>10) { b=0; } GpioDataRegs.GPBTOGGLE.bit.GPIO62=1; CpuTimer0Regs.TCR.bit.TIF = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; } void PWM_Int(void) { pwm = pwm+1; if(pwm>10) {pwm =0;} GpioDataRegs.GPCTOGGLE.bit.GPIO73 = 1; // EPwm1Regs.ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; }
Thanks in advance!