新手上路
- 积分
- 28
- 金钱
- 28
- 注册时间
- 2014-4-24
- 在线时间
- 0 小时
|
5金钱
用STM32F407的TIM1输出一个1M的PWM信号,不用选项的是 TIM_OCMode_PWM2(反极性) 还是 TIM_OCMode_PWM1(正极性),输出的PWM信号都是一样的,都是正负极性的,用示波器的耦合交流来看,大家帮忙看看是怎么回事是哪里设置有问题恩?
TIM_TimeBaseStructure.TIM_Period = 168-1; //查数据手册可知,TIM1与TIM8为16位自动装载
TIM_TimeBaseStructure.TIM_Prescaler =1-1; //分频为168M
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructure); //填入缺省值,其中后几项只对TIM1和TIM8有效
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //PWM1为正常占空比模式,PWM2为反极性模式
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //输出允许
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //互补输出允许
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //High为占空比高极性,此时占空比为20%;Low则为反极性,占空比为80%
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;//互补输出,与以上相反
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_Pulse = 84;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);//CCR自动装载默认也是打开的
TIM_ARRPreloadConfig(TIM1, ENABLE); //ARR自动装载默认是打开的,可以不设置
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_Cmd(TIM1, ENABLE); //使能TIM1定时器
TIM_CtrlPWMOutputs(TIM1, ENABLE);//使能TIM1的PWM输出,TIM1与TIM8有效
,
|
|