想利用STM32F103RC实现24路PWM输出,但是最终结果只能实现22路,TIM3的CH3和CH4出现的波形不正常,看起来像是跟TIM8的CH2N和CH3N叠加后的波形(但实际上TIM8上四个输出通道的极性都是High)。只有在关闭TIM8的CH3和CH4后,TIM3的所有输出波形才恢复正常。是我配置有问题吗,还是这本来就是个BUG?
TIM3 部分复用( CH1~CH4 分别对应的IO为: PB4~PB5,PB0~PB1)
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE);
TIM8没有复用(CH1~CH4分别对应的IO为: PC6~PC9)
TIM_GenerateEvent(TIM8, TIM_EventSource_Update);
TIM_CtrlPWMOutputs(TIM8,ENABLE);
TIM_Cmd(TIM8, ENABLE);
定时器配置也基本相同(如下):
TIM_TimeBaseStructure.TIM_Period = 20;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM8,0x8C9F,TIM_PSCReloadMode_Immediate);
TIM_ARRPreloadConfig(TIM8, ENABLE);
通道设置基本都一样(如下):
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_Pulse = 10;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC4Init(TIM8, &TIM_OCInitStructure);
就是不知道问题出在了哪里?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
论坛上已经有过类似的帖子了。
添加下面三行代码可解决问题:
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset ;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
一周热门 更多>