目前使用28027进行开发, 需要使用PWM达到以下两点:
- Rising Edge需要与外部讯号的Falling Edge同步
- Duty Cycle要可以从3%调整到25%之间. PWM frequency是7.5MHZ. SYSCLK是60MHZ, 所以Period是设置成8.
一开始将CMPA设定为2, SyncMode设置为EPWMxSYNC同步. 如此可以达成25% Duty并且Rising Edge与外部讯号同步.
然后开始调整CMPAHR. 调的过程Duty有照预想的缩小, 但是Rising Edge因为移动所以开始跟外部讯号没有同步. 有什么方式可以高分辨率调整Duty并且维持跟外部讯号的同步?
曾经试过去调整TBPHSHR来把相位调整回来成同步, 但是在CPMAHR的模式下似乎无法调整TBPHSHR. 也曾经试过用CMPAHR去调整Falling Edge, 但是在CMPA=1的情况下, Duty只能在12.5%~25%间作调整, 没办法调整到12.5%以下. 请问有什么设定方式可以达成以上两点的PWM要求?
以下是目前设定的Sample Code:
void HRPWM2_Config(period)
{
CLK_enablePwmClock(myClk, PWM_Number_2);
// ePWM2 register configuration with HRPWM
// ePWM2A toggle low/high with MEP control on Rising edge
PWM_setPeriodLoad(myPwm2, PWM_PeriodLoad_Immediate);
PWM_setPeriod(myPwm2, period-1); // Set timer period
PWM_setCmpA(myPwm2, 2);
PWM_setCmpAHr(myPwm2, (1 << 8));
PWM_setCmpB(myPwm2, 2);
PWM_setPhase(myPwm2, 0x0000); // Phase is 0
PWM_setCount(myPwm2, 0x0000); // Clear counter
PWM_setCounterMode(myPwm2, PWM_CounterMode_Up); // Count up
PWM_enableCounterLoad(myPwm2);
PWM_setSyncMode(myPwm2, PWM_SyncMode_EPWMxSYNC);
PWM_setHighSpeedClkDiv(myPwm2, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
PWM_setClkDiv(myPwm2, PWM_ClkDiv_by_1);
PWM_setShadowMode_CmpA(myPwm2, PWM_ShadowMode_Shadow); // Load registers every ZERO
PWM_setShadowMode_CmpB(myPwm2, PWM_ShadowMode_Shadow);
PWM_setLoadMode_CmpA(myPwm2, PWM_LoadMode_Zero);
PWM_setLoadMode_CmpB(myPwm2, PWM_LoadMode_Zero);
PWM_setActionQual_Zero_PwmA(myPwm2, PWM_ActionQual_Set);
PWM_setActionQual_CntUp_CmpA_PwmA(myPwm2, PWM_ActionQual_Clear);
PWM_setActionQual_Zero_PwmB(myPwm2, PWM_ActionQual_Set);
PWM_setActionQual_CntUp_CmpB_PwmB(myPwm2, PWM_ActionQual_Clear);
//MEP control on Rising edge
PWM_setHrEdgeMode(myPwm2, PWM_HrEdgeMode_Rising);
PWM_setHrControlMode(myPwm2, PWM_HrControlMode_Duty);
PWM_setHrShadowMode(myPwm2, PWM_HrShadowMode_CTR_EQ_0);
}