PWM模块仅为输出PWM,对于PWM输入捕捉应使用ICU模块。
MCAL配置
port配置
mcu配置
在MCU模块中配置好PWM的PCLK及相应的McuClockReferencePoint,并在PWM模块的PwmMcuClockReferencePoint 参数中关联,该时钟即为PWM时钟源。
pwm配置
PwmPeriodDefault: 周期,单位秒
代码
初始化
Pwm_Init(&Pwm_Config[0]);
设置占空比,最大为最大为0x8000,即32768
/* set 50% duty */
Pwm_SetDutyCycle(PwmConf_PwmChannel_PwmChannel_0, 0x4000);
设置周期及占空比
/* peroid */
Pwm_SetPeriodAndDuty(PwmConf_PwmChannel_PwmChannel_0, peroid, 0x4000);