如题,
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //pb53õê¼»ˉ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO¿úËù¶èÎa50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //pb43õê¼»ˉ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO¿úËù¶èÎa50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE);
TIM_TimeBaseInitStrue.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStrue.TIM_CounterMode = TIM_CounterMode_Up; //¼ÆêyÆ÷ÏòéϼÆêy
TIM_TimeBaseInitStrue.TIM_Period = arr;
TIM_TimeBaseInitStrue.TIM_Prescaler = psc;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStrue);
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC2Init(TIM3,&TIM_OCInitStruct);//¼Æê±Æ÷3í¨μà23õê¼»ˉ
TIM_OC1Init(TIM3,&TIM_OCInitStruct);//¼Æê±Æ÷3í¨μà13õê¼»ˉ
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_Cmd(TIM3,ENABLE);
都是按照原子大哥的步骤来的,我用串口发送不同的占空比控制舵机,TIM_SetCompare2(TIM3,res);,PB5测试正常但是用TIM——SetCompare1(TIM3,res);的时候PB4没反应,不能输出PWM(用LED和舵机测试都没反应)
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>