各位大佬好,以上是管脚重映射,实现PWM输出的代码,TIM3_CH2完全重映射到PC7以及部分重映射到PB5和CH1部分重映射到PB4都是下载之后没反应,主程序正常,用CH1映射到PC6有效,请指教
- #include "pwm.h"
- void TIM3_CH1_PWM_Init(u16 per,u16 psc)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7; //重映射管脚选择
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
- GPIO_Init(GPIOC,&GPIO_InitStructure);
-
- GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE); //完全重映射
- // GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE); //部分重映射
-
- TIM_TimeBaseInitStructure.TIM_Period=per;
- TIM_TimeBaseInitStructure.TIM_Prescaler=psc;
- TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
- TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
-
- TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;
- TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
-
-
- TIM_OC2Init(TIM3,&TIM_OCInitStructure); //定时器通道选择 通道二
- TIM_ARRPreloadConfig(TIM3,ENABLE);
- TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable); //定时器通道选择 通道二
-
- TIM_Cmd(TIM3,ENABLE);
-
- }
复制代码
|