没有合适的资源?快使用搜索试试~ 我知道了~
首页STM32实现任意角度移相全桥PWM
资源详情
资源评论
资源推荐

STM32实现任意角度移相全桥实现任意角度移相全桥PWM
最近因某些原因,需要用到任意角度移相的PWM波形来驱动全桥电路,本文记录实现过程。
MCU:STM32F334C8T6
类似于全桥整流器,将四个二极管换成开关器件,就是全桥逆变器,两个桥臂,需要用四路,两组互补的PWM波形来驱动,
但此次的要求中,两组互补PWM波形不是完全相同的,而是有一定的相位差,而且此相位差可能是任意值。
关于互补PWM波的产生,比较简单,上一篇文章中讲了使用通用定时器的方法,本文使用高级定时器或者具有互补输出功能
的通用定时器的TIMx_CHy和TIMx_CHyN通道产生,两个定时器分别产生两组互补PWM,并且占空比和频率都可以调节。
本文重点在于如何产生任意角度的移相。
于是开始翻阅STM32F334的官方手册,寻找相关定时器同步和主从模式的功能!
Slave mode: Gated mode
The counter can be enabled depending on the level of a selected input.
意思就是一个计时器可以利用输入信号来使能或失能
官方手册中给出了一个例子:
Using one timer to enable another timer
In this example, we control the enable of TIM2 with the output compare 1 of Timer 3. Refer
to Figure 205 for connections. TIM2 counts on the pided internal clock only when OC1REF
of TIM3 is high. Both counter clock frequencies are pided by 3 by the prescaler compared
to CK_INT (fCK_CNT = fCK_INT/3).
1. Configure TIM3 master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIM3_CR2 register).
2. Configure the TIM3 OC1REF waveform (TIM3_CCMR1 register).
3. Configure TIM2 to get the input trigger from TIM3 (TS=000 in the TIM2_SMCR
register).
4. Configure TIM2 ingated mode(SMS=101 in TIM2_SMCR register).
5. Enable TIM2 by writing ‘1 in the CEN bit (TIM2_CR1 register).
6. Start TIM3 by writing ‘1 in the CEN bit (TIM3_CR1 register).
Note: The counter 2 clock is not synchronized with counter 1, this mode only affects the TIM2
counter enable signal.
STM32F334C8T6这款芯片中,TIM2和TIM3都没有互补PWM输出功能,有互补输出功能的有高级定时器TIM1,通用定时器
TIM15,16,17,
而要使用主从模式连接两个定时器,需要两个之间有输出和输入信号,只能选用TIM1和TIM15,并且TIM15为主TIM1为从。
使用TIM1和TIM15的CH1和CH1N分别输出一组互补PWM,用TIM15_CH2输出触发信号OC2REF。
确定了选用的定时器,接下来就是写程序,程序大概有以下几个部分:
计算参数//参见上一篇文章 配置输出引脚 时钟基本配置 //参见上一篇文章 输出模式和参数配置 //参见上一篇文章 互补输出配
置 主从模式和触发信号配置 使能时钟 修改触发信号//非常重要,否则输出出错
其中配置主从模式步骤如下:
1. Configure the Master Timers using the following functions:
void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0