我想要产生一个三角载波,但是上升和下降的斜率不一样,目前的做法是,利用ePWM1和ePWM2产生两个中断,分别在TBCTR=0和TBCTR=TBPRD的时候进入中断,改变CLKDIV和HSPCLKDIV的值,改变基准时钟分频位,从而改变三角波两边的斜率
EALLOW;
PieVectTable.EPWM1_INT = &OffsetISR;
PieVectTable.EPWM2_INT = &Clk_ISR;
EDIS;
// Enable CNT_zero interrupt using EPWM1 Time-base
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation 使能产生中断信号EPWMx_INT
EPwm1Regs.ETSEL.bit.INTSEL = 1; // Enable interrupt CNT_zero event 001:TBCTR=0x0000时产生EPWMx_INT
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate interrupt on the 1st event 中断周期设定,01:每发生一次事件,产生中断信号EPWMx_INT
EPwm1Regs.ETCLR.bit.INT = 1; // Enable more interrupts
// Enable CNT_zero interrupt using EPWM1 Time-base
EPwm2Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation 使能产生中断信号EPWMx_INT
EPwm2Regs.ETSEL.bit.INTSEL = 2; // Enable interrupt CNT_zero event 001:TBCTR=0xTBPRD时产生EPWMx_INT
EPwm2Regs.ETPS.bit.INTPRD = 1; // Generate interrupt on the 1st event 中断周期设定,01:每发生一次事件,产生中断信号EPWMx_INT
EPwm2Regs.ETCLR.bit.INT = 1; // Enable more interrupts
interrupt void MainISR(void)
{
pwm1.PeriodMax =750;
pwm1.HalfPerMax=pwm1.PeriodMax/2;
pwm1.Deadband = 2.0*SYSTEM_FREQUENCY; // 120 counts -> 2.0 usec for TBCLK = SYSCLK/1
pwm1.Clk = 0;
pwm1.Hspclk =3;
PWM_INIT_MACRO(1,2,3,pwm1);
// Enable more interrupts from this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge interrupt to recieve more interrupts from PIE group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
interrupt void Clk_ISR(void)
{
pwm1.PeriodMax =750;
pwm1.HalfPerMax=pwm1.PeriodMax/2;
pwm1.Deadband = 2.0*SYSTEM_FREQUENCY; // 120 counts -> 2.0 usec for TBCLK = SYSCLK/1
pwm1.Clk = 0;
pwm1.Hspclk = 7;
PWM_INIT_MACRO(1,2,3,pwm1);
// Enable more interrupts from this timer
EPwm2Regs.ETCLR.bit.INT = 1;
// Acknowledge interrupt to recieve more interrupts from PIE group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
现在遇到问题是:
1.中断频率与我计算的频率不一致,应该是10KHz的频率,但是实测是9.6KHz,为什么会出现这种情况。
2.每一个ePWM都有各自的时间基准计数器,当ePWM2中断触发(CTL=PRD)的时候,ePWM1的计数器是否也到了CTR=PRD的条件?这样让他们同步?
3.我是在ctr=prd的时候出发了ePWM1_SOC信号,AD开始采样,这与我的ePWM2的中断是否冲突,哪个先执行?
Seven Han:请先跟踪下您的这个帖子:
e2echina.ti.com/…/443203
我想要产生一个三角载波,但是上升和下降的斜率不一样,目前的做法是,利用ePWM1和ePWM2产生两个中断,分别在TBCTR=0和TBCTR=TBPRD的时候进入中断,改变CLKDIV和HSPCLKDIV的值,改变基准时钟分频位,从而改变三角波两边的斜率
EALLOW;
PieVectTable.EPWM1_INT = &OffsetISR;
PieVectTable.EPWM2_INT = &Clk_ISR;
EDIS;
// Enable CNT_zero interrupt using EPWM1 Time-base
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation 使能产生中断信号EPWMx_INT
EPwm1Regs.ETSEL.bit.INTSEL = 1; // Enable interrupt CNT_zero event 001:TBCTR=0x0000时产生EPWMx_INT
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate interrupt on the 1st event 中断周期设定,01:每发生一次事件,产生中断信号EPWMx_INT
EPwm1Regs.ETCLR.bit.INT = 1; // Enable more interrupts
// Enable CNT_zero interrupt using EPWM1 Time-base
EPwm2Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation 使能产生中断信号EPWMx_INT
EPwm2Regs.ETSEL.bit.INTSEL = 2; // Enable interrupt CNT_zero event 001:TBCTR=0xTBPRD时产生EPWMx_INT
EPwm2Regs.ETPS.bit.INTPRD = 1; // Generate interrupt on the 1st event 中断周期设定,01:每发生一次事件,产生中断信号EPWMx_INT
EPwm2Regs.ETCLR.bit.INT = 1; // Enable more interrupts
interrupt void MainISR(void)
{
pwm1.PeriodMax =750;
pwm1.HalfPerMax=pwm1.PeriodMax/2;
pwm1.Deadband = 2.0*SYSTEM_FREQUENCY; // 120 counts -> 2.0 usec for TBCLK = SYSCLK/1
pwm1.Clk = 0;
pwm1.Hspclk =3;
PWM_INIT_MACRO(1,2,3,pwm1);
// Enable more interrupts from this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge interrupt to recieve more interrupts from PIE group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
interrupt void Clk_ISR(void)
{
pwm1.PeriodMax =750;
pwm1.HalfPerMax=pwm1.PeriodMax/2;
pwm1.Deadband = 2.0*SYSTEM_FREQUENCY; // 120 counts -> 2.0 usec for TBCLK = SYSCLK/1
pwm1.Clk = 0;
pwm1.Hspclk = 7;
PWM_INIT_MACRO(1,2,3,pwm1);
// Enable more interrupts from this timer
EPwm2Regs.ETCLR.bit.INT = 1;
// Acknowledge interrupt to recieve more interrupts from PIE group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
现在遇到问题是:
1.中断频率与我计算的频率不一致,应该是10KHz的频率,但是实测是9.6KHz,为什么会出现这种情况。
2.每一个ePWM都有各自的时间基准计数器,当ePWM2中断触发(CTL=PRD)的时候,ePWM1的计数器是否也到了CTR=PRD的条件?这样让他们同步?
3.我是在ctr=prd的时候出发了ePWM1_SOC信号,AD开始采样,这与我的ePWM2的中断是否冲突,哪个先执行?
mangui zhang:1.那个差异是不是测量误差带来的
你要输出三角波拿PWM实现不知道怎么处理我觉得你可以把比较寄存器周期给送入一个三角波的表