ch32v307vct6的PB5引腳重映射為T(mén)IM10_CH3,無(wú)法輸出PWM,麻煩工程師指導(dǎo)一下
貼上代碼
#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};
??? // 開(kāi)啟定時(shí)器時(shí)鐘和PWM輸出引腳時(shí)鐘
??? 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 );
??? // 定時(shí)器配置
??? 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
??? // 輸出比較參數(shù)配置
??? 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 );
}
感謝!已經(jīng)解決,參照給的例程是沒(méi)問(wèn)題的,是我自己配置錯(cuò)了