void InitEPwm1Example(void) {EALLOW;//PWM_setSyncMode(myPwm1, PWM_SyncMode_EPWMxSYNC);//CLK_enablePwmClock(myClk, PWM_Number_1);//PWM_enableSocAPulse(myPwm1);//EPwm1Regs.TBSTS.bit.SYNCI = 1;//EPwm1Regs.TBCTL.bit.SWFSYNC = 1;EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;EPwm1Regs.TBCTL.bit.PHSEN = 0;PWM_setCounterMode(myPwm1, PWM_CounterMode_Up);// Count upPWM_setPeriod(myPwm1, 2000);// Set timer periodPWM_setPhase(myPwm1, 0x0000);// Phase is 0 PWM_setCount(myPwm1, 100);// Clear counterEPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;PWM_setHighSpeedClkDiv(myPwm1, PWM_HspClkDiv_by_1);// Clock ratio to SYSCLKOUTPWM_setClkDiv(myPwm1, PWM_ClkDiv_by_1);PWM_setShadowMode_CmpA(myPwm1, PWM_ShadowMode_Shadow);PWM_setShadowMode_CmpB(myPwm1, PWM_ShadowMode_Shadow);PWM_setLoadMode_CmpA(myPwm1, PWM_LoadMode_Zero);PWM_setLoadMode_CmpB(myPwm1, PWM_LoadMode_Zero);PWM_setCmpA(myPwm1, 1000);// Set compare A valuePWM_setCmpB(myPwm1, 1000);// Set Compare B valuePWM_setActionQual_Zero_PwmA(myPwm1, PWM_ActionQual_Set);// Set PWM1A on ZeroPWM_setActionQual_CntUp_CmpA_PwmA(myPwm1, PWM_ActionQual_Clear);// Clear PWM1A on event A, up countPWM_setActionQual_Zero_PwmB(myPwm1, PWM_ActionQual_Set);// Set PWM1B on ZeroPWM_setActionQual_CntUp_CmpB_PwmB(myPwm1, PWM_ActionQual_Clear);// Clear PWM1B on event B, up countEDIS;} void InitEPwm2Example() {EALLOW;//PWM_setSyncMode(myPwm2, PWM_SyncMode_EPWMxSYNC);//CLK_enablePwmClock(myClk, PWM_Number_2);//PWM_enableSocAPulse(myPwm2);//EPwm2Regs.TBSTS.bit.SYNCI = 1;//EPwm2Regs.TBCTL.bit.SWFSYNC = 1;EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;EPwm2Regs.TBCTL.bit.PHSEN = 1;PWM_setCounterMode(myPwm2, PWM_CounterMode_Up);// Count upPWM_setPeriod(myPwm2, 2000);// Set timer period//PWM_disableCounterLoad(myPwm2);// Disable phase loading//PWM_enableCounterLoad(myPwm2);EPwm2Regs.TBPHS.half.TBPHS = 500;PWM_setCount(myPwm2, 100);// Clear counterPWM_setHighSpeedClkDiv(myPwm2, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUTPWM_setClkDiv(myPwm2, PWM_ClkDiv_by_1);EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;// Setup shadow register load on ZEROPWM_setShadowMode_CmpA(myPwm2, PWM_ShadowMode_Shadow);PWM_setShadowMode_CmpB(myPwm2, PWM_ShadowMode_Shadow);PWM_setLoadMode_CmpA(myPwm2, PWM_LoadMode_Zero);PWM_setLoadMode_CmpB(myPwm2, PWM_LoadMode_Zero);// Set Compare valuesPWM_setCmpA(myPwm2, 1000);// Set compare A valuePWM_setCmpB(myPwm2, 1000);// Set Compare B value// Set actionsPWM_setActionQual_Period_PwmA(myPwm2, PWM_ActionQual_Set);// Clear PWM2A on PeriodPWM_setActionQual_CntUp_CmpA_PwmA(myPwm2, PWM_ActionQual_Clear); // Set PWM2A on event A, up countPWM_setActionQual_Period_PwmB(myPwm2, PWM_ActionQual_Set);// Clear PWM2B on PeriodPWM_setActionQual_CntUp_CmpB_PwmB(myPwm2, PWM_ActionQual_Clear); // Set PWM2B on event B, up countEDIS; } void InitEPwm3Example() {EALLOW;//PWM_setSyncMode(myPwm3, PWM_SyncMode_EPWMxSYNC);// CLK_enablePwmClock(myClk, PWM_Number_3);//PWM_enableSocAPulse(myPwm3);//EPwm3Regs.TBSTS.bit.SYNCI = 1;//EPwm3Regs.TBCTL.bit.SWFSYNC = 1;EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;EPwm3Regs.TBCTL.bit.PHSEN = 1;PWM_setCounterMode(myPwm3, PWM_CounterMode_Up);// Count upPWM_setPeriod(myPwm3, 2000);// Set timer period//PWM_disableCounterLoad(myPwm3);// Disable phase loading//PWM_enableCounterLoad(myPwm3);EPwm3Regs.TBPHS.half.TBPHS = 99;PWM_setCount(myPwm3, 100);// Clear counterPWM_setHighSpeedClkDiv(myPwm3, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUTPWM_setClkDiv(myPwm3, PWM_ClkDiv_by_1);EPwm3Regs.TBCTL.bit.PRDLD = TB_SHADOW;// Setup shadow register load on ZEROPWM_setShadowMode_CmpA(myPwm3, PWM_ShadowMode_Shadow);PWM_setShadowMode_CmpB(myPwm3, PWM_ShadowMode_Shadow);PWM_setLoadMode_CmpA(myPwm3, PWM_LoadMode_Zero);PWM_setLoadMode_CmpB(myPwm3, PWM_LoadMode_Zero);// Set Compare valuesPWM_setCmpA(myPwm3, 1000);// Set compare A valuePWM_setCmpB(myPwm3, 1000);// Set Compare B value// Set actionsPWM_setActionQual_Period_PwmA(myPwm3, PWM_ActionQual_Set);// Clear PWM2A on PeriodPWM_setActionQual_CntUp_CmpA_PwmA(myPwm3, PWM_ActionQual_Clear); // Set PWM2A on event A, up countPWM_setActionQual_Period_PwmB(myPwm3, PWM_ActionQual_Set);// Clear PWM2B on PeriodPWM_setActionQual_CntUp_CmpB_PwmB(myPwm3, PWM_ActionQual_Clear); // Set PWM2B on event B, up countEDIS; }
代码有点乱 我简单说下 我是把epwm1配置成master 同步设置成 TB_CTR_ZERO 关闭PHSEN开关
把 epwm2 和 epwm3设置成slave 同步设置成TB_SYNC_IN 打开PHSEN开关 并设置一个相位值 (随便设置的)
这些都是按照手册 、论坛里其他人的代码设置的, 但是测试的波形并没有移相
因为我找到的 都是epwm模块的配置例程 我想知道 是不是main函数里也需要设置些什么 但是我没设置到 所以就移不了相
user5994545:
void InitEPwm1Example(void) {EALLOW;//PWM_setSyncMode(myPwm1, PWM_SyncMode_EPWMxSYNC);//CLK_enablePwmClock(myClk, PWM_Number_1);//PWM_enableSocAPulse(myPwm1);//EPwm1Regs.TBSTS.bit.SYNCI = 1;//EPwm1Regs.TBCTL.bit.SWFSYNC = 1;EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;EPwm1Regs.TBCTL.bit.PHSEN = 0;PWM_setCounterMode(myPwm1, PWM_CounterMode_Up);// Count upPWM_setPeriod(myPwm1, 2000);// Set timer periodPWM_setPhase(myPwm1, 0x0000);// Phase is 0PWM_setCount(myPwm1, 100);// Clear counterEPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;PWM_setHighSpeedClkDiv(myPwm1, PWM_HspClkDiv_by_1);// Clock ratio to SYSCLKOUTPWM_setClkDiv(myPwm1, PWM_ClkDiv_by_1);PWM_setShadowMode_CmpA(myPwm1, PWM_ShadowMode_Shadow);PWM_setShadowMode_CmpB(myPwm1, PWM_ShadowMode_Shadow);PWM_setLoadMode_CmpA(myPwm1, PWM_LoadMode_Zero);PWM_setLoadMode_CmpB(myPwm1, PWM_LoadMode_Zero);PWM_setCmpA(myPwm1, 1000);// Set compare A valuePWM_setCmpB(myPwm1, 1000);// Set Compare B valuePWM_setActionQual_Zero_PwmA(myPwm1, PWM_ActionQual_Set);// Set PWM1A on ZeroPWM_setActionQual_CntUp_CmpA_PwmA(myPwm1, PWM_ActionQual_Clear);// Clear PWM1A on event A, up countPWM_setActionQual_Zero_PwmB(myPwm1, PWM_ActionQual_Set);// Set PWM1B on ZeroPWM_setActionQual_CntUp_CmpB_PwmB(myPwm1, PWM_ActionQual_Clear);// Clear PWM1B on event B, up countEDIS;}void InitEPwm2Example() {EALLOW;//PWM_setSyncMode(myPwm2, PWM_SyncMode_EPWMxSYNC);//CLK_enablePwmClock(myClk, PWM_Number_2);//PWM_enableSocAPulse(myPwm2);//EPwm2Regs.TBSTS.bit.SYNCI = 1;//EPwm2Regs.TBCTL.bit.SWFSYNC = 1;EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;EPwm2Regs.TBCTL.bit.PHSEN = 1;PWM_setCounterMode(myPwm2, PWM_CounterMode_Up);// Count upPWM_setPeriod(myPwm2, 2000);// Set timer period//PWM_disableCounterLoad(myPwm2);// Disable phase loading//PWM_enableCounterLoad(myPwm2);EPwm2Regs.TBPHS.half.TBPHS = 500;PWM_setCount(myPwm2, 100);// Clear counterPWM_setHighSpeedClkDiv(myPwm2, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUTPWM_setClkDiv(myPwm2, PWM_ClkDiv_by_1);EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;// Setup shadow register load on ZEROPWM_setShadowMode_CmpA(myPwm2, PWM_ShadowMode_Shadow);PWM_setShadowMode_CmpB(myPwm2, PWM_ShadowMode_Shadow);PWM_setLoadMode_CmpA(myPwm2, PWM_LoadMode_Zero);PWM_setLoadMode_CmpB(myPwm2, PWM_LoadMode_Zero);// Set Compare valuesPWM_setCmpA(myPwm2, 1000);// Set compare A valuePWM_setCmpB(myPwm2, 1000);// Set Compare B value// Set actionsPWM_setActionQual_Period_PwmA(myPwm2, PWM_ActionQual_Set);// Clear PWM2A on PeriodPWM_setActionQual_CntUp_CmpA_PwmA(myPwm2, PWM_ActionQual_Clear);// Set PWM2A on event A, up countPWM_setActionQual_Period_PwmB(myPwm2, PWM_ActionQual_Set);// Clear PWM2B on PeriodPWM_setActionQual_CntUp_CmpB_PwmB(myPwm2, PWM_ActionQual_Clear);// Set PWM2B on event B, up countEDIS; }void InitEPwm3Example() {EALLOW;//PWM_setSyncMode(myPwm3, PWM_SyncMode_EPWMxSYNC);// CLK_enablePwmClock(myClk, PWM_Number_3);//PWM_enableSocAPulse(myPwm3);//EPwm3Regs.TBSTS.bit.SYNCI = 1;//EPwm3Regs.TBCTL.bit.SWFSYNC = 1;EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;EPwm3Regs.TBCTL.bit.PHSEN = 1;PWM_setCounterMode(myPwm3, PWM_CounterMode_Up);// Count upPWM_setPeriod(myPwm3, 2000);// Set timer period//PWM_disableCounterLoad(myPwm3);// Disable phase loading//PWM_enableCounterLoad(myPwm3);EPwm3Regs.TBPHS.half.TBPHS = 99;PWM_setCount(myPwm3, 100);// Clear counterPWM_setHighSpeedClkDiv(myPwm3, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUTPWM_setClkDiv(myPwm3, PWM_ClkDiv_by_1);EPwm3Regs.TBCTL.bit.PRDLD = TB_SHADOW;// Setup shadow register load on ZEROPWM_setShadowMode_CmpA(myPwm3, PWM_ShadowMode_Shadow);PWM_setShadowMode_CmpB(myPwm3, PWM_ShadowMode_Shadow);PWM_setLoadMode_CmpA(myPwm3, PWM_LoadMode_Zero);PWM_setLoadMode_CmpB(myPwm3, PWM_LoadMode_Zero);// Set Compare valuesPWM_setCmpA(myPwm3, 1000);// Set compare A valuePWM_setCmpB(myPwm3, 1000);// Set Compare B value// Set actionsPWM_setActionQual_Period_PwmA(myPwm3, PWM_ActionQual_Set);// Clear PWM2A on PeriodPWM_setActionQual_CntUp_CmpA_PwmA(myPwm3, PWM_ActionQual_Clear);// Set PWM2A on event A, up countPWM_setActionQual_Period_PwmB(myPwm3, PWM_ActionQual_Set);// Clear PWM2B on PeriodPWM_setActionQual_CntUp_CmpB_PwmB(myPwm3, PWM_ActionQual_Clear);// Set PWM2B on event B, up countEDIS; }
代码有点乱 我简单说下 我是把epwm1配置成master 同步设置成 TB_CTR_ZERO 关闭PHSEN开关
把 epwm2 和 epwm3设置成slave 同步设置成TB_SYNC_IN 打开PHSEN开关 并设置一个相位值 (随便设置的)
这些都是按照手册 、论坛里其他人的代码设置的, 但是测试的波形并没有移相
因为我找到的 都是epwm模块的配置例程 我想知道 是不是main函数里也需要设置些什么 但是我没设置到 所以就移不了相