ch32v307vct6的PB5引脚重映射为TIM10_CH3,无法输出PWM,麻烦工程师指导一下
贴上代码
#define MOTOR_1_PWM_PIN GPIO_Pin_5
#define MOTOR_1_PWM_GPIO_PORT GPIOB
#define MOTOR_1_PWM_PORT_CLK RCC_APB2Periph_GPIOB
#define MOTOR_1_PWM_TIM TIM10
#define MOTOR_1_PWM_TIM_CLK RCC_APB2Periph_TIM10
#define MOTOR_1_PWM_TIM_IRQn TIM10_UP_IRQn
#define MOTOR_1_PWM_TIM_IRQHandler TIM10_UP_IRQHandler
void Motor_1_PWM_TIM_Config( u16 arr, u16 psc, u16 ccp )
{
GPIO_InitTypeDef GPIO_InitStructure={0};
TIM_OCInitTypeDef TIM_OCInitStructure={0};
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};
NVIC_InitTypeDef NVIC_InitStructure={0};
// 开启定时器时钟和PWM输出引脚时钟
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE );
RCC_APB2PeriphClockCmd( MOTOR_1_PWM_PORT_CLK | MOTOR_1_PWM_TIM_CLK, ENABLE );
GPIO_PinRemapConfig(GPIO_Remap_TIM10 , ENABLE);
GPIO_InitStructure.GPIO_Pin = MOTOR_1_PWM_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( MOTOR_1_PWM_GPIO_PORT, &GPIO_InitStructure );
// 定时器配置
TIM_TimeBaseInitStructure.TIM_Period = arr;
TIM_TimeBaseInitStructure.TIM_Prescaler = psc;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit( MOTOR_1_PWM_TIM, &TIM_TimeBaseInitStructure);
// PWM模式配置
#if (PWM_MODE == PWM_MODE1)
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
#elif (PWM_MODE == PWM_MODE2)
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
#endif
// 输出比较参数配置
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = ccp;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC3Init( MOTOR_1_PWM_TIM, &TIM_OCInitStructure );
// PWM输出使能
TIM_CtrlPWMOutputs(MOTOR_1_PWM_TIM, ENABLE );
TIM_OC3PreloadConfig( MOTOR_1_PWM_TIM, TIM_OCPreload_Enable );
TIM_ARRPreloadConfig( MOTOR_1_PWM_TIM, ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = MOTOR_1_PWM_TIM_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(MOTOR_1_PWM_TIM, TIM_IT_Update, ENABLE);
TIM_Cmd( MOTOR_1_PWM_TIM, ENABLE );
}
感谢!已经解决,参照给的例程是没问题的,是我自己配置错了