如题我使用的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);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
Hi, Bruce, 谢谢你的回复。
我觉得应该不是死区配置的问题。下图是截取的输出波形。
PWM死区
把死区的配置屏蔽掉,还是一样的现象。
贴出我的配置代码,希望大家有空能帮忙看一下。我用的是STM32F030单片机,时钟频率48MHz.
[mw_shl_code=applescript,true]
void TIM1_CH2_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
/* TIM1 Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 8 - 1;
TIM_TimeBaseStructure.TIM_Period = 80 - 1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 2 in PWM Mode */
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 = 40 - 1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_BDTRStructInit(&TIM_BDTRInitStructure);
TIM_BDTRInitStructure.TIM_DeadTime = 10;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* TIM1 Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}[/mw_shl_code]
一周热门 更多>