硬件28027,软件ccs5.5,主频60M,使用内置振荡器1,通过设置pwm1周期10us频率100k的方波,结果输出的波形频率细看确实是100k(10us),但波形失真严重,同时观测到EPwm1Regs.TBCTR始终为0,也就是时基模块并未计数。
注明:1用别的软件跑过,硬件检测正常。2中断关闭了,未打开,程序通过步进模式观测,未跑飞。3检测XCLKOUT引脚,输出波形为60M的三角波。4pwm时钟使能确认打开了 下附图1pwm输出 图2XCLKOUT引脚输出。5上拉去掉也没有作用 附件是程序。
已经检查两天了,不知道是什么原因,求大神解释?
#include "system.h" int main(void) { DeviceInit();//系统初始化 //配置PWM 1打开时钟使能,2setTBCLKSYNC = 0,3配置pwm寄存器 4setTBCLKSYNC = 1.开始工作 EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; InitEPwmGpio(); InitEPwm();//4 EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; while(1) { //GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;long a=EPwm1Regs.TBCTR; } } void InitEPwmGpio(void) {InitEPwm1Gpio();// InitEPwm2Gpio();// InitEPwm3Gpio(); //#if DSP28_EPWM4 // InitEPwm4Gpio(); //#endif // endif DSP28_EPWM4 } void InitEPwm1Gpio(void) {EALLOW; /* Disable internal pull-up for the selected output pinsfor reduced power consumption */ // Pull-ups can be enabled or disabled by the user. // Comment out other unwanted lines.GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;// Disable pull-up on GPIO0 (EPWM1A)GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up on GPIO1 (EPWM1B) /* Configure EPwm-1 pins using GPIO regs*/ // This specifies which of the possible GPIO pins will be EPWM1 functional pins. // Comment out other unwanted lines.GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;// Configure GPIO0 as EPWM1AGpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;// Configure GPIO1 as EPWM1BEDIS; } void InitEPwm(void) {// Initialize EPwm1/2/3/4EPwm1Regs.TBPRD=600;EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;// Set Immediate loadEPwm1Regs.TBPHS.half.TBPHS = 0;EPwm1Regs.TBCTR = 0;EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_CMPB;// Used to sync EPWM(n+1) "down-stream"EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;// Counter compare submodule registersEPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE;EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE;EPwm1Regs.CMPA.half.CMPA = 350;EPwm1Regs.CMPB = 300;// Action Qualifier SubModule RegistersEPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//EPwm1Regs.AQCTLA.bit.PRD = AQ_CLEAR;EPwm1Regs.AQCTLA.bit.CBU=AQ_CLEAR;// DeadBand Control RegisterEPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;// Active Hi ComplimentaryEPwm1Regs.DBRED = 20;// Initial valueEPwm1Regs.DBFED = 20;// Initial value//tbd... } pwm时钟使能也打开了SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 1;// ePWM1
dewei he:
好吧,我自问自答了,把周期寄存器的模式改为shadow模式,就输出正常了,这样可以解决问题,但不清楚是什么原因,有TI工作人员解释下吗?谢谢
EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;// Set Immediate load改为
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;// disable Immediate load
硬件28027,软件ccs5.5,主频60M,使用内置振荡器1,通过设置pwm1周期10us频率100k的方波,结果输出的波形频率细看确实是100k(10us),但波形失真严重,同时观测到EPwm1Regs.TBCTR始终为0,也就是时基模块并未计数。
注明:1用别的软件跑过,硬件检测正常。2中断关闭了,未打开,程序通过步进模式观测,未跑飞。3检测XCLKOUT引脚,输出波形为60M的三角波。4pwm时钟使能确认打开了 下附图1pwm输出 图2XCLKOUT引脚输出。5上拉去掉也没有作用 附件是程序。
已经检查两天了,不知道是什么原因,求大神解释?
#include "system.h" int main(void) { DeviceInit();//系统初始化 //配置PWM 1打开时钟使能,2setTBCLKSYNC = 0,3配置pwm寄存器 4setTBCLKSYNC = 1.开始工作 EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; InitEPwmGpio(); InitEPwm();//4 EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; while(1) { //GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;long a=EPwm1Regs.TBCTR; } } void InitEPwmGpio(void) {InitEPwm1Gpio();// InitEPwm2Gpio();// InitEPwm3Gpio(); //#if DSP28_EPWM4 // InitEPwm4Gpio(); //#endif // endif DSP28_EPWM4 } void InitEPwm1Gpio(void) {EALLOW; /* Disable internal pull-up for the selected output pinsfor reduced power consumption */ // Pull-ups can be enabled or disabled by the user. // Comment out other unwanted lines.GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;// Disable pull-up on GPIO0 (EPWM1A)GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up on GPIO1 (EPWM1B) /* Configure EPwm-1 pins using GPIO regs*/ // This specifies which of the possible GPIO pins will be EPWM1 functional pins. // Comment out other unwanted lines.GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;// Configure GPIO0 as EPWM1AGpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;// Configure GPIO1 as EPWM1BEDIS; } void InitEPwm(void) {// Initialize EPwm1/2/3/4EPwm1Regs.TBPRD=600;EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;// Set Immediate loadEPwm1Regs.TBPHS.half.TBPHS = 0;EPwm1Regs.TBCTR = 0;EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_CMPB;// Used to sync EPWM(n+1) "down-stream"EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;// Counter compare submodule registersEPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE;EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE;EPwm1Regs.CMPA.half.CMPA = 350;EPwm1Regs.CMPB = 300;// Action Qualifier SubModule RegistersEPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//EPwm1Regs.AQCTLA.bit.PRD = AQ_CLEAR;EPwm1Regs.AQCTLA.bit.CBU=AQ_CLEAR;// DeadBand Control RegisterEPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;// Active Hi ComplimentaryEPwm1Regs.DBRED = 20;// Initial valueEPwm1Regs.DBFED = 20;// Initial value//tbd... } pwm时钟使能也打开了SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 1;// ePWM1
mou he:
回复 dewei he:
感觉一般周期寄存器的值不是Shadow模式实时更新的话容易由于各种原因的干扰导致周期寄存器的值被以外改变,从而造成各种问题