RT1052 具有 4 个 eFlexPWM(eFlexWM1~eFlex_PWM4)。
PWM_A 与 PWM_B 可以独立输出也可以作为互补对输出。
- FLEXPWM 子模块可选的时钟源有 IPBus clock、EXT_CLK。
比较寄存器用于产生 PWM 波,每个 FLEXPWM 拥有 6 个比较寄存器
CLOCK_SetDiv(kCLOCK_AhbDiv, 0x2); /* Set AHB PODF to 2, divide by 3 */
CLOCK_SetDiv(kCLOCK_IpgDiv, 0x3); /* Set IPG PODF to 3, divede by 4 */
CLOCK_SetDiv
/* Set the PWM Fault inputs to a low value */
XBARA_Init(XBARA1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault0);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault2);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault3);
XBAR函数
typedef enum _pwm_chnl_pair_operation
{
kPWM_Independent = 0U, /*!< PWM A & PWM B operate as 2 independent channels */
kPWM_ComplementaryPwmA, /*!< PWM A & PWM B are complementary channels, PWM A generates the signal */
kPWM_ComplementaryPwmB /*!< PWM A & PWM B are complementary channels, PWM B generates the signal */
} pwm_chnl_pair_operation_t;
模式配置。 A产生信号,B互补等。
PWM_Init(PWM2,kPWM_Module_3,&pwm2sm3_config); //初始化PWM2模块3
模块初始化
/* Call the init function with demo configuration */
PWM_DRV_Init3PhPwm();
初始化PWM波的配置
//设置PWM2,中央对齐模式
PWM_SetupPwm(PWM2,kPWM_Module_3,&pwm_ignal,2,kPWM_CenterAligned,fre,sourceclock);//使用了两个通道
PWM_SetPwmLdok(PWM2,kPWM_Control_Module_3,true); //设置PWM的load ok位
PWM_StartTimer(PWM2,kPWM_Control_Module_3); //开启定时器
kPWM_CenterAligned 中央对齐模式
/* Update duty cycles for all 3 PWM signals */
PWM_UpdatePwmDutycycle(BOARD_PWM_BASEADDR, kPWM_Module_0, kPWM_PwmA, kPWM_SignedCenterAligned, pwmVal);
PWM_UpdatePwmDutycycle(BOARD_PWM_BASEADDR, kPWM_Module_1, kPWM_PwmA, kPWM_SignedCenterAligned, (pwmVal >> 1));
PWM_UpdatePwmDutycycle(BOARD_PWM_BASEADDR, kPWM_Module_2, kPWM_PwmA, kPWM_SignedCenterAligned, (pwmVal >> 2));
/* Set the load okay bit for all submodules to load registers from their buffer */
PWM_SetPwmLdok(BOARD_PWM_BASEADDR, kPWM_Control_Module_0 | kPWM_Control_Module_1 | kPWM_Control_Module_2, true);
占空比更新。