TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F280025C: EPWM禁用时改变CMPA会重新启用

Part Number:TMS320F280025C

//控制8路PWM
__interrupt void ePWM7_ISR(void)
{
    //因为是同步所以放一个中断里 8路PWM:ePWM1A ~ ePWM7A 、eCAP2的APWM
    EPwm1Regs.CMPA.bit.CMPA = EPwm1Regs.TBPRD * Inverter_DATA[PV1_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比           EPwm2Regs.CMPA.bit.CMPA = EPwm2Regs.TBPRD * Inverter_DATA[PV1_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比           EPwm3Regs.CMPA.bit.CMPA = EPwm3Regs.TBPRD * Inverter_DATA[PV2_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比          EPwm4Regs.CMPA.bit.CMPA = EPwm4Regs.TBPRD * Inverter_DATA[PV2_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比        EPwm5Regs.CMPA.bit.CMPA = EPwm5Regs.TBPRD * Inverter_DATA[PV3_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比        EPwm6Regs.CMPA.bit.CMPA = EPwm6Regs.TBPRD * Inverter_DATA[PV3_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比       EPwm7Regs.CMPA.bit.CMPA = EPwm7Regs.TBPRD * Inverter_DATA[PV4_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比      ECap2Regs.CAP2          = ECap2Regs.CAP1  * Inverter_DATA[PV4_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比            Inverter_Flag[FlagX_sin_Number]++;
    if(Inverter_Flag[FlagX_sin_Number] >= Sin_sampling_Number){Inverter_Flag[FlagX_sin_Number] = 0;}
    EPwm7Regs.ETCLR.bit.INT = 1;//写1对ETFLG[INT]状态标志位清零才能进行下一次中断
    PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;       //确认组3中断
}

我屏蔽掉

EPwm1Regs.CMPA.bit.CMPA = EPwm1Regs.TBPRD * Inverter_DATA[PV1_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比           EPwm2Regs.CMPA.bit.CMPA = EPwm2Regs.TBPRD * Inverter_DATA[PV1_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比           EPwm3Regs.CMPA.bit.CMPA = EPwm3Regs.TBPRD * Inverter_DATA[PV2_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比          EPwm4Regs.CMPA.bit.CMPA = EPwm4Regs.TBPRD * Inverter_DATA[PV2_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比        EPwm5Regs.CMPA.bit.CMPA = EPwm5Regs.TBPRD * Inverter_DATA[PV3_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比        EPwm6Regs.CMPA.bit.CMPA = EPwm6Regs.TBPRD * Inverter_DATA[PV3_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比       EPwm7Regs.CMPA.bit.CMPA = EPwm7Regs.TBPRD * Inverter_DATA[PV4_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比      ECap2Regs.CAP2          = ECap2Regs.CAP1  * Inverter_DATA[PV4_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];     //按照sin变化占空比           这几个之后他就不会有波形但是没有屏蔽他就会有

我在主函数中有禁用ePWM 时钟

   EALLOW;
    CpuSysRegs.PCLKCR2.bit.EPWM1 = 0;               // 禁用ePWM1时钟
    CpuSysRegs.PCLKCR2.bit.EPWM2 = 0;               // 禁用ePWM2时钟
    CpuSysRegs.PCLKCR2.bit.EPWM3 = 0;               // 禁用ePWM3时钟
    CpuSysRegs.PCLKCR2.bit.EPWM4 = 0;               // 禁用ePWM4时钟
    CpuSysRegs.PCLKCR2.bit.EPWM5 = 0;               // 禁用ePWM5时钟
    CpuSysRegs.PCLKCR2.bit.EPWM6 = 0;               // 禁用ePWM6时钟
    CpuSysRegs.PCLKCR2.bit.EPWM7 = 0;               // 禁用ePWM7时钟
    ECap2Regs.ECCTL2.bit.TSCTRSTOP   = 0;           //禁用eCAP2计数器开始计数    APWM
    EDIS;

Yale Li:

Hi,

我不太理解您的问题,能否重新表述一下?

另外,如果方便的话,请使用 ‘插入–>代码’ 来插入代码,便于我们查看,以为您更好地解决问题:

谢谢

,

1 1:

就是我在主函数中关闭了EPWM1~EPWM7的输出    如果不进行CMPA.bit.CMPA 的修改他是正常的(就是不输出PWM)如果在中断中修改CMPA.bit.CMPA 的话他会不执行关闭输出的操作(又进行输出PWM)我的本意是让他在我关闭它输出的时候ePWM停止输出,打开的时候继续输出

//HRPWM_Config - 配置所有ePWM通道,并在ePWMxA通道和ePWMxB通道上设置HRPWM;
//ePWMx:PWM通道(ePWM1~ePWM7)period:频率dutyfactor_A:A通道占空比dutyfactor_B:B通道占空比
void ePWM_Config(Uint16 ePWMx,float period,float dutyfactor_A)
{float count;if(ePWMx==1)ePWM=&EPwm1Regs;//是初始化ePWM1else if(ePWMx==2)ePWM=&EPwm2Regs;//是初始化ePWM2else if(ePWMx==3)ePWM=&EPwm3Regs;//是初始化ePWM3else if(ePWMx==4)ePWM=&EPwm4Regs;//是初始化ePWM4else if(ePWMx==5)ePWM=&EPwm5Regs;//是初始化ePWM5else if(ePWMx==6)ePWM=&EPwm6Regs;//是初始化ePWM6else if(ePWMx==7)ePWM=&EPwm7Regs;//是初始化ePWM7dutyfactor_A = 1-dutyfactor_A / 100.0;//将通道A占空比小数化(本来调整的是低电平,使用1-的话修改的就是高电平时间)//ePwM通道寄存器配置与HRPwM//ePWMxA开关低/高与MEP上升沿控制EALLOW;CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;//在EPWM中禁用TBCLKEPWMCLK = TBCLK = 100 MHzTBCLK这是ePWM时钟(EPWMCLK)的预缩放版本,ePWM内的所有子模块都使用它。这Clock决定时基计数器递增或递减的速率。EDIS;count=50000000.0/period;//获取计数次数(是带小数的)(*ePWM).TBPRD = (Uint16)(count);//PWM频率=1/(2*TBPRD)//在周期寄存器中设置计数器的计数周期(数period个数算一个周期,频率是其倒数,按这个公式看的话是乘2的倒数(因为是上下计数所以乘以2))(*ePWM).CMPA.bit.CMPA= (Uint16)(count * dutyfactor_A);// 初始设定占空比50%period/2一半是50%// 设置EPWM1A比较值寄存器的比较值,即体现EPWM1A的占空比(*ePWM).TBPHS.all = 0;//忽略同步事件相位偏移寄存器这些位设置所选ePwM相对于提供同步输入信号的时基的时基计数器相位。—如果是TBCTL.PHSEN = O,则忽略同步事件并且时基计数器没有加载相位。-如果TBCTL.PHSEN = 1。则时基计数器(TBCTR)将为加载同步事件发生时的阶段(TBPHs)。同步事件可以由输入发起同步信号(EPWMxSYNCI)或由软件强制同步。(*ePWM).TBCTR = 0;//时基计数器寄存器//TBCTL为定时器控制寄存器(*ePWM).TBCTL.bit.PRDLD = TB_SHADOW;//映射寄存器SHADOW使能并配置映射寄存器为自动读写设置阴影负载(*ePWM).TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;//选择上下计数模式// 增减计数模式数到设定值再数到零(*ePWM).TBCTL.bit.HSPCLKDIV = TB_DIV1;//1分频分频系数\/(*ePWM).TBCTL.bit.CLKDIV = TB_DIV1;//1分频TBCLK = SYSCLKOUTHSPCLKDIV与CLKDIV对PWM的时钟进行分频(*ePWM).TBCTL.bit.FREE_SOFT = 11;//仿真模式位(*ePWM).TBCTL.bit.SWFSYNC = 1;// Synchronize high resolution phase to start HR period同步高分辨率阶段以启动HR周期(*ePWM).TBCTL.bit.PHSEN = TB_DISABLE;// 不使用移相方式if(ePWMx % 2 == 0){(*ePWM).EPWMSYNCINSEL.bit.SEL = ePWMx -1;//配置上一个PWM信号同步。(*ePWM).EPWMSYNCOUTEN.all= SYNC_OUT_SRC_DISABLE_ALL;//EPWMxSYNCOUT源使能禁用}else{(*ePWM).EPWMSYNCINSEL.all = SYNC_IN_SRC_DISABLE_ALL;//禁用EPWMxSYNCL信号的来源。可以配置为别的PWM信号(*ePWM).EPWMSYNCOUTEN.bit.ZEROEN= 1;//禁用EPWMxSYNCL信号的来源。可以配置为别的PWM信号}(*ePWM).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;//A模块比较使能加载CMPA在CTR = 0通过写0来清除SHDWAMODE位来使能load on CTR=Zero(*ePWM).CMPCTL.bit.SHDWAMODE = CC_SHADOW;//A模块比较模式//AQCTLx为输出A比较方式控制寄存器if(ePWMx % 2 == 0){(*ePWM).AQCTLA.bit.CAU = AQ_CLEAR;//PWM开关高/低(后面这个注释是AQ_CLEAR值的)//TBCTR(计数器)与CMPA在up计数时相等使输出为high,这关系的输出的占空比(*ePWM).AQCTLA.bit.CAD = AQ_SET;}else{(*ePWM).AQCTLA.bit.CAU = AQ_SET;//PWM开关高/低(后面这个注释是AQ_CLEAR值的)//TBCTR(计数器)与CMPA在up计数时相等使输出为high,这关系的输出的占空比(*ePWM).AQCTLA.bit.CAD = AQ_CLEAR;}EALLOW;// 开启ePWMx中断进入服务函数(*ePWM).ETSEL.bit.INTSEL= ET_CTR_PRD; // Select INT on PRD event在PRD事件上选择INT(*ePWM).ETSEL.bit.INTEN = 1;// Enable INT(*ePWM).ETPS.bit.INTPRD = ET_1ST;// Generate INT on 1ST event在第一个事件上生成INTEDIS;
}
//控制8路PWM
__interrupt void ePWM7_ISR(void)
{//因为是同步所以放一个中断里 8路PWM:ePWM1A ~ ePWM7A 、eCAP2的APWMEPwm1Regs.CMPA.bit.CMPA = EPwm1Regs.TBPRD * Inverter_DATA[PV1_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置EPWM1A比较值寄存器的比较值,即体现EPWM1A的占空比EPwm2Regs.CMPA.bit.CMPA = EPwm2Regs.TBPRD * Inverter_DATA[PV1_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置EPWM2A比较值寄存器的比较值,即体现EPWM1A的占空比EPwm3Regs.CMPA.bit.CMPA = EPwm3Regs.TBPRD * Inverter_DATA[PV2_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置EPWM3A比较值寄存器的比较值,即体现EPWM1A的占空比EPwm4Regs.CMPA.bit.CMPA = EPwm4Regs.TBPRD * Inverter_DATA[PV2_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置EPWM4A比较值寄存器的比较值,即体现EPWM1A的占空比EPwm5Regs.CMPA.bit.CMPA = EPwm5Regs.TBPRD * Inverter_DATA[PV3_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置EPWM5A比较值寄存器的比较值,即体现EPWM1A的占空比EPwm6Regs.CMPA.bit.CMPA = EPwm6Regs.TBPRD * Inverter_DATA[PV3_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置EPWM6A比较值寄存器的比较值,即体现EPWM1A的占空比EPwm7Regs.CMPA.bit.CMPA = EPwm7Regs.TBPRD * Inverter_DATA[PV4_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置EPWM7A比较值寄存器的比较值,即体现EPWM1A的占空比ECap2Regs.CAP2= ECap2Regs.CAP1* Inverter_DATA[PV4_PWM_control] * sina[ Inverter_Flag[FlagX_sin_Number] ];//按照sin变化占空比// 设置eCAP2 比较值寄存器的比较值,即体现eCAP2的APWM占空比Inverter_Flag[FlagX_sin_Number]++;if(Inverter_Flag[FlagX_sin_Number] >= Sin_sampling_Number){Inverter_Flag[FlagX_sin_Number] = 0;}EPwm7Regs.ETCLR.bit.INT = 1;//写1对ETFLG[INT]状态标志位清零才能进行下一次中断PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;//确认组3中断
}

,

Yale Li:

您在主函数中是通过什么来关闭输出的?AQ的动作吗?

,

1 1:

 EALLOW;    CpuSysRegs.PCLKCR2.bit.EPWM1 = 0;               // 禁用ePWM1时钟    CpuSysRegs.PCLKCR2.bit.EPWM2 = 0;               // 禁用ePWM2时钟    CpuSysRegs.PCLKCR2.bit.EPWM3 = 0;               // 禁用ePWM3时钟    CpuSysRegs.PCLKCR2.bit.EPWM4 = 0;               // 禁用ePWM4时钟    CpuSysRegs.PCLKCR2.bit.EPWM5 = 0;               // 禁用ePWM5时钟    CpuSysRegs.PCLKCR2.bit.EPWM6 = 0;               // 禁用ePWM6时钟    CpuSysRegs.PCLKCR2.bit.EPWM7 = 0;               // 禁用ePWM7时钟    ECap2Regs.ECCTL2.bit.TSCTRSTOP   = 0;           //禁用eCAP2计数器开始计数    APWM    EDIS;

使用这些语句

或者您有什么好方法么

,

1 1:

那个  这个比较着急  方便看一下么

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F280025C: EPWM禁用时改变CMPA会重新启用
分享到: 更多 (0)