STM32F103芯片 1、控制PWM的开启状态和关闭状态用什么函数??是TIM_Cmd(TIM1, ENABLE)和TIM_Cmd(TIM1, DISABLE)吗? 2、如何在上电开机状态和PWM关闭状态下,使两组互补的PWM都为高电平(H桥电路设计,没有PWM输出时都是高电平)?现在因为是互补的关系,所以两组PWM默认情况下电平都是反向的。 PWM波初始化程序: TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值 TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值 TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; 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_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_OC2Init(TIM1, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable); TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM1, ENABLE); TIM_Cmd(TIM1, ENABLE); //使能TIM1 TIM_CtrlPWMOutputs(TIM1, ENABLE); |
这两句代码是表明空闲时引脚状态的
评分
查看全部评分
设置成这个,还是一样,没有效果??
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; //TIM_OCIdleState_Reset
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Set; //TIM_OCIdleState_Reset
TIM_OCIdleState_Set
TIM_OCNIdleState_Set
这两个还是有点区别的
评分
查看全部评分
你好,想要把两组互补的PWM初始状态和停止状态设置成高电平,要怎么设置?谢谢!!
我直接复制你的代码了,没注意看,下面这样写应该就是默认高电平了。建议多看用户手册
评分
查看全部评分