具体测试代码如下:
// 定义PWM周期时间
#define PWM_PERIOD TIM_CLK_MHz*1000000/PWM_FREQUENCY/2
// 6路互补PWM测试,放置到main函数的while循环前
// 生成占空比为20%的PWM波
void PWM_Test(void)
{
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
__HAL_TIM_SetCompare(&htim1,TIM_CHANNEL_1,0.2*PWM_PERIOD);
__HAL_TIM_SetCompare(&htim1,TIM_CHANNEL_2,0.2*PWM_PERIOD);
__HAL_TIM_SetCompare(&htim1,TIM_CHANNEL_3,0.2*PWM_PERIOD);
}
|