需要在ARD D10(PI0,TIM5-CH4)输出PWM方波,好像没有输出,查了两天,没有查出问题,请大侠帮忙看看,程序如下:
1)GPIO-CONFIG
GPIO_InitTypeDef gpio_init_structure;
__HAL_RCC_GPIOI_CLK_ENABLE();
gpio_init_structure.Pin = GPIO_PIN_0;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
gpio_init_structure.Alternate = GPIO_AF2_TIM5;;
HAL_GPIO_Init(GPIOI, &gpio_init_structure);
/* Set TIMx instance */
TimHandle.Instance = TIM5;
PWM_Width = (uint32_t) ((SystemCoreClock /2) / Ferequency_SetValue) - 1;
TimHandle.Init.Period = PWM_Width;
TimHandle.Init.Prescaler = 1;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
{
while(1){ }
}
TIMOC_Config.OCMode = TIM_OCMODE_PWM1;
TIMOC_Config.Pulse = PWM_Width>>1;
TIMOC_Config.OCIdleState = TIM_OCIDLESTATE_SET;
TIMOC_Config.OCPolarity = TIM_OCPOLARITY_HIGH ;
HAL_TIM_PWM_ConfigChannel(&TimHandle,&TIMOC_Config,TIM_CHANNEL_4);
HAL_TIMEx_PWMN_Start(&TimHandle, TIM_CHANNEL_4);
if(HAL_TIM_Base_Start(&TimHandle) != HAL_OK)
{
while(1) {}
}
//在void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)里
__HAL_RCC_TIM5_CLK_ENABLE();
|