想用定时器控制电机旋转时间,按照论坛里给的例程定义了
void InitEPwm1(uint32_t num1)
{
InitEPwm1Gpio();
EPwm1Regs.TBPRD = 6000; // Set timer period
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; // loaded from its shadow register
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm1Regs.CMPA.half.CMPA = num1;
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on Zero
EPwm1Regs.AQCTLA.bit.PRD = AQ_SET;
EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Set PWM1A on Zero
EPwm1Regs.AQCTLB.bit.PRD = AQ_SET;
// 触发ADC SOC
//EPwm1Regs.ETSEL.bit.SOCAEN = 1;
}
之后在Main()中定义了全局变量
extern uint32_t num01;
InitEPwm1(num01);
并且利用定时器一
在定时器一种引用extern uint32_t num01;;
interrupt void INT13_ISR(void) // INT13 or CPU-Timer1
{
CpuTimer1.InterruptCount++;
if(CpuTimer1.InterruptCount>50000)
{
num01=2000;
}
else {
num01=0;
}
但是老实出错,请大家帮我看看该怎么改好吗?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>