EVA通用定时器问题
时间:10-02
整理:3721RD
点击:
F2812
1、写的PWM波程序,用的是PWM5\6驱动电机,不清楚用比较寄存器产生PWM时与通用定时器有什么关系吗?
2、用定时器产生PWM,发生比较匹配时,发生触变,计数器继续计数直到与周期寄存器值相等,清零。在这个过程中,有中断吗?我现在搞不清楚下面这个程序运行流程,特别是void init_eva(void);之后进入到while()以后,while()为真且为空语句,那么程序是怎么到void init_eva(void);内的呢?
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
void init_eva(void);
void delay();
unsigned int i,j,k;
unsigned int led[4]={0x01,0x02,0x20,0x40};
void main(void)
{
// Step 1. Initialize System Control:
InitSysCtrl();
// Step 2. Initalize GPIO:
EALLOW;
// Enable PWM pins
GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6 pins
GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
GpioMuxRegs.GPDMUX.all=0x00;
GpioMuxRegs.GPDDIR.all=0x63;
GpioMuxRegs.GPDQUAL.all=0x00;
EDIS;
// Step 3. Clear all interrupts and initialize PIE vector table:
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// EvaRegs.EXTCONA.bit.INDCOE=1;
// Step 4. Initialize all the Device Peripherals:
init_eva();
init_evb();
// Step 5. User specific code, enable interrupts:
// Just sit and loop forever:
// PWM pins can be observed with a scope.
while(1)
{
}
void init_eva()
{
// EVA Configure T1PWM, T2PWM, PWM1-PWM6
// Initalize the timers
// Initalize EVA Timer1
EvaRegs.T1PR = 0xFFFF; // Timer1 period
EvaRegs.T1CMPR = 0x8000; // Timer1 compare
EvaRegs.T1CNT = 0x0000; // Timer1 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T1CON.all = 0x1042;
// Initalize EVA Timer2
EvaRegs.T2PR = 0x0FFF; // Timer2 period
EvaRegs.T2CMPR = 0x03C0; // Timer2 compare
EvaRegs.T2CNT = 0x0000; // Timer2 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T2CON.all = 0x1042;
// Setup T1PWM and T2PWM
// Drive T1/T2 PWM by compare logic
EvaRegs.GPTCONA.bit.TCMPOE = 1;
// Polarity of GP Timer 1 Compare = Active low
EvaRegs.GPTCONA.bit.T1PIN = 1;
// Polarity of GP Timer 2 Compare = Active high
EvaRegs.GPTCONA.bit.T2PIN = 2; //2 high 1 low 0 force 0 3 force 1
// Enable compare for PWM1-PWM6
EvaRegs.CMPR1 = 0x7FFF;
EvaRegs.CMPR2 = 0x4000;
EvaRegs.CMPR3 = 0xC000;
// Compare action control. Action that takes place
// on a cmpare event
// output pin 1 CMPR1 - active high
// output pin 2 CMPR1 - active low
// output pin 3 CMPR2 - active high
// output pin 4 CMPR2 - active low
// output pin 5 CMPR3 - active high
// output pin 6 CMPR3 - active low
EvaRegs.ACTRA.all = 0x0666;
EvaRegs.DBTCONA.all = 0x0000; // Disable deadband
// EvaRegs.COMCONA.all = 0xA600;
EvaRegs.COMCONA.all = 0xA6ff;
}
void delay(unsigned int value)
{
for(i=0;i<10000;i++)
{ for(j=0;j<value;j++) ;}
}
1、写的PWM波程序,用的是PWM5\6驱动电机,不清楚用比较寄存器产生PWM时与通用定时器有什么关系吗?
2、用定时器产生PWM,发生比较匹配时,发生触变,计数器继续计数直到与周期寄存器值相等,清零。在这个过程中,有中断吗?我现在搞不清楚下面这个程序运行流程,特别是void init_eva(void);之后进入到while()以后,while()为真且为空语句,那么程序是怎么到void init_eva(void);内的呢?
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
void init_eva(void);
void delay();
unsigned int i,j,k;
unsigned int led[4]={0x01,0x02,0x20,0x40};
void main(void)
{
// Step 1. Initialize System Control:
InitSysCtrl();
// Step 2. Initalize GPIO:
EALLOW;
// Enable PWM pins
GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6 pins
GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
GpioMuxRegs.GPDMUX.all=0x00;
GpioMuxRegs.GPDDIR.all=0x63;
GpioMuxRegs.GPDQUAL.all=0x00;
EDIS;
// Step 3. Clear all interrupts and initialize PIE vector table:
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// EvaRegs.EXTCONA.bit.INDCOE=1;
// Step 4. Initialize all the Device Peripherals:
init_eva();
init_evb();
// Step 5. User specific code, enable interrupts:
// Just sit and loop forever:
// PWM pins can be observed with a scope.
while(1)
{
}
void init_eva()
{
// EVA Configure T1PWM, T2PWM, PWM1-PWM6
// Initalize the timers
// Initalize EVA Timer1
EvaRegs.T1PR = 0xFFFF; // Timer1 period
EvaRegs.T1CMPR = 0x8000; // Timer1 compare
EvaRegs.T1CNT = 0x0000; // Timer1 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T1CON.all = 0x1042;
// Initalize EVA Timer2
EvaRegs.T2PR = 0x0FFF; // Timer2 period
EvaRegs.T2CMPR = 0x03C0; // Timer2 compare
EvaRegs.T2CNT = 0x0000; // Timer2 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T2CON.all = 0x1042;
// Setup T1PWM and T2PWM
// Drive T1/T2 PWM by compare logic
EvaRegs.GPTCONA.bit.TCMPOE = 1;
// Polarity of GP Timer 1 Compare = Active low
EvaRegs.GPTCONA.bit.T1PIN = 1;
// Polarity of GP Timer 2 Compare = Active high
EvaRegs.GPTCONA.bit.T2PIN = 2; //2 high 1 low 0 force 0 3 force 1
// Enable compare for PWM1-PWM6
EvaRegs.CMPR1 = 0x7FFF;
EvaRegs.CMPR2 = 0x4000;
EvaRegs.CMPR3 = 0xC000;
// Compare action control. Action that takes place
// on a cmpare event
// output pin 1 CMPR1 - active high
// output pin 2 CMPR1 - active low
// output pin 3 CMPR2 - active high
// output pin 4 CMPR2 - active low
// output pin 5 CMPR3 - active high
// output pin 6 CMPR3 - active low
EvaRegs.ACTRA.all = 0x0666;
EvaRegs.DBTCONA.all = 0x0000; // Disable deadband
// EvaRegs.COMCONA.all = 0xA600;
EvaRegs.COMCONA.all = 0xA6ff;
}
void delay(unsigned int value)
{
for(i=0;i<10000;i++)
{ for(j=0;j<value;j++) ;}
}