如题我使用的STM32F103RCT6,使用高级定时器TIM1进行PWM输出,PWM输出设置为周期设置100um,脉宽为50%。用示波器观察到两个波形,波形照片如下:
上面这个波形的周期、脉宽和我设置的周期脉宽是一致的,但我将示波器时间调为1s,就出现如下的波形,这不是我想要的不知道为什么?
示波器时间为1S,就出现这样一个波形,这是为什么?这个波形周期为3S,脉宽也是50%。
如果我调整上面波形的占空比,下面的波形也会随着变化。可是我程序中就没有配置第二个这个波形,不知道从哪里来的。另外我将IO口上接上一个LED灯,灯也是一闪一闪的,并不是变暗。
各位大神,请问我这是什么情况???下面代码是我的配置代码。
void TIM1_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 7200-1; // 10K
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Output Compare Active Mode configuration: Chan.ynel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable ;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState =TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState =TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
TIM_BDTRInitStructure.TIM_OSSIState=TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_OSSRState=TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel=TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime=0Xab;
TIM_BDTRInitStructure.TIM_Break=TIM_Break_Disable;
TIM_BDTRInitStructure.TIM_BreakPolarity=TIM_BreakPolarity_Low;
TIM_BDTRInitStructure.TIM_AutomaticOutput=TIM_AutomaticOutput_Disable;
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
TIM_ARRPreloadConfig(TIM1, ENABLE);
/* TIM1 enable counter */
TIM_Cmd(TIM1, ENABLE);
}
//PWM输出使用的是如下代码:
TIM_SetCompare1(TIM1,3600);
TIM_SetCompare2(TIM1,3600);
TIM_SetCompare3(TIM1,3600);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
会不会是死区?试试更改死区设置看看有没有变化?
一周热门 更多>