金牌会员
- 积分
- 1011
- 金钱
- 1011
- 注册时间
- 2021-7-26
- 在线时间
- 184 小时
|
楼主 |
发表于 2022-12-18 20:06:11
|
显示全部楼层
本帖最后由 精英板 于 2022-12-19 22:18 编辑
用的这个TIM_SetCompare1(TIM3,700);TIM_SetCompare2(TIM3,700);
TIM的设置:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê1Äü¶¨ê±Æ÷3ê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //ê1ÄüGPIOíaéèoíAFIO¸′óÃ1|ÄüÄ£¿éê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); //Timer32¿·ÖÖØó3éä TIM3_CH2->PB5
// 通道二PB5没问题正常输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //TIM_CH2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIO
//PB5μĸ′óÃêÇTIM3 CH2
// 通道一PB4照猫画虎但不能正常输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //TIM_CH1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIO
// //PB4μĸ′óÃêÇTIM3 CH1
////êμÑé2¿·Ö
//然后这里OC1,2也都设置了
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_Cmd(TIM3, ENABLE);
但
TIM_SetCompare1(TIM3,100);就是不输出pwm,非复用引脚TIM3的PA67也试过但都不好使,只有PB5好使 |
|