我想得到一个EPWM1A、EPWM1B之间相差一个占空比相位的波形,为什么我初始化完成之后连波形都没有了,希望各位帮我找一下问题
初始化程序如下
void InitEPwm1Example()
{
EPwm1Regs.CMPA.half.CMPA = 2500; EPwm1Regs.CMPB = 5000; EPwm1Regs.TBPRD = 10000;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
//EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero时间基准计数器等于周期
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET达到CMPA的值变为低电平;
EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;//达到CMPB的值变为低电平
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
//EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
}
void InitEPwm2Example()
{
EPwm2Regs.CMPA.half.CMPA = 2500; EPwm2Regs.CMPB = 5000; EPwm2Regs.TBPRD = 10000;
// Setup TBCLK
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;//TB_SYNC_DISABLE; // sync flow-through
// Setup shadowing
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
}
Eric Ma:
有没使能PWM的时钟
还有如下:
// For this example, only initialize the ePWM EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS;
InitEPwm1Example(); InitEPwm2Example(); InitEPwm3Example();
EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS;
建议用CONTROLsuite的例程去修改。
ERIC
我想得到一个EPWM1A、EPWM1B之间相差一个占空比相位的波形,为什么我初始化完成之后连波形都没有了,希望各位帮我找一下问题
初始化程序如下
void InitEPwm1Example()
{
EPwm1Regs.CMPA.half.CMPA = 2500; EPwm1Regs.CMPB = 5000; EPwm1Regs.TBPRD = 10000;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
//EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero时间基准计数器等于周期
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET达到CMPA的值变为低电平;
EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;//达到CMPB的值变为低电平
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
//EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
}
void InitEPwm2Example()
{
EPwm2Regs.CMPA.half.CMPA = 2500; EPwm2Regs.CMPB = 5000; EPwm2Regs.TBPRD = 10000;
// Setup TBCLK
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;//TB_SYNC_DISABLE; // sync flow-through
// Setup shadowing
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
}
zehao pan:
回复 Eric Ma:
初始化程序确实没有是能时钟,但是在主程序中有这一部分啊,这样不能吗???
void main(void){// Step 1. Initialize System Control:// PLL, WatchDog, enable Peripheral Clocks// This example function is found in the DSP2803x_SysCtrl.c file. InitSysCtrl();
// Step 2. Initalize GPIO:// This example function is found in the DSP2803x_Gpio.c file and// illustrates how to set the GPIO to it's default state.// InitGpio(); // Skipped for this example
// For this case just init GPIO pins for ePWM1, ePWM2, and TZ pins InitEPwm1Gpio(); InitEPwm2Gpio(); InitTzGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:// Disable CPU interrupts DINT;
// Initialize the PIE control registers to their default state.// The default state is all PIE interrupts disabled and flags// are cleared.// This function is found in the DSP2803x_PieCtrl.c file. InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;
InitPieVectTable();
// Interrupts that are used in this example are re-mapped to// ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.EPWM1_TZINT = &epwm1_tzint_isr; PieVectTable.EPWM2_TZINT = &epwm2_tzint_isr; EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:// This function is found in DSP2803x_InitPeripherals.c// InitPeripherals(); // Not required for this example
EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS;
InitEPwm1Example(); InitEPwm2Example();
EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS;
// Step 5. User specific code, enable interrupts// Initalize counters: EPwm1TZIntCount = 0; EPwm2TZIntCount = 0;
// Enable CPU INT3 which is connected to EPWM1-3 INT: IER |= M_INT2;
// Enable EPWM INTn in the PIE: Group 2 interrupt 1-3 PieCtrlRegs.PIEIER2.bit.INTx1 = 1; PieCtrlRegs.PIEIER2.bit.INTx2 = 1;
// Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional): for(;;) { asm(" NOP"); }
}
我想得到一个EPWM1A、EPWM1B之间相差一个占空比相位的波形,为什么我初始化完成之后连波形都没有了,希望各位帮我找一下问题
初始化程序如下
void InitEPwm1Example()
{
EPwm1Regs.CMPA.half.CMPA = 2500; EPwm1Regs.CMPB = 5000; EPwm1Regs.TBPRD = 10000;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
//EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero时间基准计数器等于周期
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET达到CMPA的值变为低电平;
EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;//达到CMPB的值变为低电平
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
//EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
}
void InitEPwm2Example()
{
EPwm2Regs.CMPA.half.CMPA = 2500; EPwm2Regs.CMPB = 5000; EPwm2Regs.TBPRD = 10000;
// Setup TBCLK
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;//TB_SYNC_DISABLE; // sync flow-through
// Setup shadowing
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
}
user4880999:
没看你的程序,你看一下wpwm1a没有波形,但是epwm1b是不是高电平?如果是,初始化没问题
我想得到一个EPWM1A、EPWM1B之间相差一个占空比相位的波形,为什么我初始化完成之后连波形都没有了,希望各位帮我找一下问题
初始化程序如下
void InitEPwm1Example()
{
EPwm1Regs.CMPA.half.CMPA = 2500; EPwm1Regs.CMPB = 5000; EPwm1Regs.TBPRD = 10000;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
//EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero时间基准计数器等于周期
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET达到CMPA的值变为低电平;
EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;//达到CMPB的值变为低电平
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
//EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
}
void InitEPwm2Example()
{
EPwm2Regs.CMPA.half.CMPA = 2500; EPwm2Regs.CMPB = 5000; EPwm2Regs.TBPRD = 10000;
// Setup TBCLK
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;//TB_SYNC_DISABLE; // sync flow-through
// Setup shadowing
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
}
zehao pan:
回复 user4880999:
是高电平,但是为什么没有波形
我想得到一个EPWM1A、EPWM1B之间相差一个占空比相位的波形,为什么我初始化完成之后连波形都没有了,希望各位帮我找一下问题
初始化程序如下
void InitEPwm1Example()
{
EPwm1Regs.CMPA.half.CMPA = 2500; EPwm1Regs.CMPB = 5000; EPwm1Regs.TBPRD = 10000;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
//EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero时间基准计数器等于周期
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET达到CMPA的值变为低电平;
EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;//达到CMPB的值变为低电平
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
//EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
}
void InitEPwm2Example()
{
EPwm2Regs.CMPA.half.CMPA = 2500; EPwm2Regs.CMPB = 5000; EPwm2Regs.TBPRD = 10000;
// Setup TBCLK
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;//TB_SYNC_DISABLE; // sync flow-through
// Setup shadowing
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
}
user4880999:
回复 zehao pan:
那就说明已经配置好了,但是你没有给他比较值,让它输出PWM。。。
for(;;) { EPwm1Regs.CMPA.half.CMPA = 500(这个数根据你的计数器数到的最高点来算的,假如你计数器值1000,给cmp500就有50%的PWM输出,给300就有60的%波形输出。); EPwm1Regs.CMPB = 500; }
你在配置好pwm后,加上这句,就有pwm波形了。。。没时间细说,你可以查下CMP寄存器
我想得到一个EPWM1A、EPWM1B之间相差一个占空比相位的波形,为什么我初始化完成之后连波形都没有了,希望各位帮我找一下问题
初始化程序如下
void InitEPwm1Example()
{
EPwm1Regs.CMPA.half.CMPA = 2500; EPwm1Regs.CMPB = 5000; EPwm1Regs.TBPRD = 10000;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
//EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero时间基准计数器等于周期
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET达到CMPA的值变为低电平;
EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;//达到CMPB的值变为低电平
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
//EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
}
void InitEPwm2Example()
{
EPwm2Regs.CMPA.half.CMPA = 2500; EPwm2Regs.CMPB = 5000; EPwm2Regs.TBPRD = 10000;
// Setup TBCLK
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//0x0-1分频,TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;//TB_SYNC_DISABLE; // sync flow-through
// Setup shadowing
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_zero; // Load on Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_zero;
// Action Qualifier SubModule Registers
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_CLEAR;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;//AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
}
user4880999:
回复 user4880999:
你百度一下PPT ‘TMS320F28027课件_第七讲_ePWM’,这个比表详细