TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); //使能定时器3外设
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE);//使能复用IO口功能和GPIOB
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE); //使能定时器3的部分重映射
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOB,&GPIO_InitStruct);
//初始化IO口
TIM_TimeBaseInitStruct.TIM_Prescaler=0; //设置时钟预分频值
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInitStruct.TIM_Period=899;//自动装载值
TIM_TimeBaseInitStruct.TIM_ClockDivision=0;//TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);//初始化
TIM_OCInitStruct.TIM_OCMode=TIM_OCMode_PWM2; //选择pwm为模式2
TIM_OCInitStruct.TIM_OutputState=TIM_OutputState_Enable; //输出使能
TIM_OCInitStruct.TIM_OCPolarity=TIM_OCPolarity_High; //输出高极性
TIM_OC1Init(TIM3,&TIM_OCInitStruct);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);//使能预装载寄存器
TIM_Cmd(TIM3,ENABLE); //定时器使能
TIM_SetCompare1(TIM3,400);
while(1);
应该不是程序的问题 我用示波器测量pb4它一直都是高电平。我不用部分重映射 测量PA6 它是正常的
是硬件问题吗?