前言:

如何实现复杂的不同频率、相位、波形脉宽的波形就在这个章节:


This application example is split into two parts describing two similar application examples.(两个例子)

Both examples use of the inter-timers synchronization to generate an N-pulse waveform but with a small difference:

• Within the first application example, covered by the part 1 of this section, an N-pulse waveform is generated on the output and the complementary output of TIM1 timer channel 1. At the end of the N-pulse waveform generation, the TIM1 timer channel 1 outputs keep their last (互补)where the channel 1 output is low and its complementary output is high.

• Within the second application example, covered by the part 2 of this section, an Npulse waveform is generated on the output and the complementary output of TIM1 timer channel 1. At the end of the N-pulse waveform generation, the TIM1 timer channel 1 outputs should be both low. This can be achieved by using the commutation feature built-in the STM32 timers. This feature is detailed in the second part of this chapter.


1 Timer synchronization overview(定时器同步方法)

Some of the STM32 timers are linked together internally for inter-timer synchronization or chaining.

一些定时器可以内部级联,达到内部定时器同步和定时器链。

The STM32 timer peripherals featuring the inter-timers synchronization capability have only one synchronization output signal named TRGO (abbreviation for “Trigger Out”).

STM32的定时器分离器器件有内部同步的功能,只有一个同步输出信号。

They also have four synchronization inputs (named ITRx where x ranges from 1 to 4) connected to the other STM32 timers synchronization outputs. The reference manual for any STM32 microcontroller lists the inter-timers connection matrix.

有4个同步的输入,ITRX,连接到定时器同步的输出上。

Note that only the timers featuring the master/slave controller unit support the inter-timer synchronization (with only few exceptions). For example, the TIM2 timer peripheral features a master/slave controller unit and it can be synchronized with other STM32 timer peripherals.

注意,只有标识有master/slave控制单元的定时器,支持内部定时器同步。

The TIM2 can trigger events inside other timers through its synchronization TRGO output signal. In this case the TIM2 timer peripheral is acting as a master timer. TIM2 timer peripheral can also be configured to be triggered by other timer synchronization output signals;

TIM2可以通过TRGO输出信号触发内部其他定时器。这种情况下,TIM2定时器作为主控定时器。TIM2也可以配置为被其他定时器同步触发的方式。

in this case the TIM2 timer peripheral is acting as a slave timer. A timer peripheral can act as a slave timer and as a master timer simultaneously.

在这种情况下,TIM2定时器作为从定时器。一个定时器分离器件可以同时充当从、主定时器。

The TIM11 timer peripheral is an example of timer peripheral that does not feature a master/slave controller unit. It does not feature a synchronization of TRGO output signal, but it is able to act as master timer for some other timer peripherals. This is possible through the usage of the TIM11 timer channel output as synchronization output signal. The TIM11 timer channel output is connected to other timer peripherals synchronization inputs.

定时器11 这是没有master/slave的定时器单元。他没有TRGO的同步输出信号。但是,他具备作为master定时的能力。通过TIM11的使用输出一个同步信号,然后,把这个同步信号连接到其他的定时器的输入上。


1.1 Timer-master configuration(主定时器配置和控制的方式)

When a timer peripheral is configured as a master timer, its corresponding synchronization TRGO output signal may output a synchronization pulse next to any of the timer events listed below.

如果一个定时器配置为主定时器,他的同步TRGO的输出信号,将输出同步到下表中的其他任何一个定时器事件.

笔者案:主从定时器的触发同步模式有很多,事件的方式有很多,下面列出的是几种主要的方式。

Note that the presented list is not exhaustive and only the most common modes are listed. The list of master modes may vary from one microcontroller family to another:(本文举例也许对其他版本的MCU并不详尽)

1.1.1EGR(EVENT GENERATE REGISTER)重置

Reset: the UG bit from the EGR register is used as a trigger output (TRGO)

设置UG bit为1 ,

这个设置会把Presscaler重置,同时会分两种情况分别重置Counter的值。

第一种情况,就是主从定时器,通过RESET UG位的方式,重置之前的预设定值。

1.1.2 使能

Enable: the counter enable signal is used as a trigger output (TRGO). It is used to start several timers at the same time, or to control a window in which a slave timer is enabled

Counter 使能信号被用作TRGO。被用于同时启动多个Timer,或者控制一个窗口让从timer使能。

通过控制定时器的使能,

1.1.3 更新

Update: the update event is selected as trigger output (TRGO). For example, a master timer can be used as a prescaler for a slave timer

更新事件作为TRGO,例如,Master timer用于从timer的prescaler

1.1.4 比较脉冲

Compare pulse: the trigger output sends a positive pulse when the CC1IF flag is set (even if it was already high) as soon as a capture or a compare match occurs

比较plus,触发输出一个正脉冲,

OC1Ref: OC1REF signal is used as trigger output (TRGO)

OC1Ref,Output compare 1 Reference. 输出比较查看寄存器。

笔者案:下面为OC1Ref的一个控制例子:

T1设定的OC1REF(输出比较参考)作为触发信号的设定信号给出后到另外一个定时器T2,OC1REF的设定由TIM1的CCMR1完成。(设定连接的Mapping和设定值的装载和清除)

OC2Ref: OC2REF signal is used as trigger output (TRGO)

OC3Ref: OC3REF signal is used as trigger output (TRGO)

OC4Ref: OC4REF signal is used as trigger output (TRGO)

To configure the timer event or internal signal to be used as a synchronization output, the right value should be written to the MMS (master mode selection) control bit-field within the TIMx_CR2 timer control register 2.

要配置定时器事件或者内部信号作为同步的输出,正确的值需要通过MMS寄出去的控制位来进行。


1.2 Timer-slave configuration(定时从模式配置)

Each timer peripheral that embeds a master/slave controller unit features four synchronization inputs already connected to the other timers synchronization outputs.

每个分离的定时器,具备主从控制单元具备上述4中同步输入已经连接到其他定时器的输出。

Note that only one synchronization input can be active at each time and the TS (trigger selection) control bit-field is used to select which synchronization input is the active one.

注意,每个定时器只有一个同步信号的输入可以使能,用TS的控制位去选择哪个同步输入。

我们看一下SMCR的TS设置:

我们看ITR0,这里可以选择被TIM5的TRGO接入。

TIM1 可以被2,3,4,5来作为从timer被触发。

The detection of an active edge on the synchronization input of one timer peripheral may trigger one of timer event inside the peripheral like an “update event” and counter reset, or counter increment.

检测某个定时器输入同步的使能边沿输入可以触发另外一个定时器的事件。

This depends on the configured value into the SMS (slave mode selection) control bit-field within the timer slave mode control register (TIMx_SMCR).

至于触发哪个类型的事件,有SMS控制位来决定。

To select which synchronization input to use, the slave timer is connected to the master timer through the input trigger.


1.3 STM32 timer-commutation feature(定时器的通讯功能 - 预加载设计)

The commutation feature is used in combination with the preload feature to change the timer channel-configuration in perfect synchronization with timer external events that are fed into it through one of its internal or external inputs.

预加载绑定给定时器,这样可以使得定时器的配置通道可以完美的适应于拓展的时间和内部外面的事件输入。

The configuration to which this refer, can be for example channel output mode, channel enabled/disabled or other. ITRx inputs are an example of internal inputs and ETR, TI1, or TI2 are examples of external inputs.

As stated in Section 1: Basic operating modes of STM32 general-purpose timers, the OCxM, CCxE and CCxNE control bit-fields feature the preload capability.

OCxM: output compare mode x:

STM32的功能强大,寄存器的复用也非常多,这个OCXM就是CCMRx里面配置output模式的寄存器:

配置好了之后,是使能寄存器控制:

CCxE 使能

CCxNE

When the preload feature on these bit-fields is enabled, any write access to them does not change the timer channel operating mode. The reason is that the write operation is performed on the preload instances of these control bit-fields. Their active instances, which effectively control the timer channel output mode, remain unchanged.Each ITRx is connected internally to another timer, and this connection is specific for each STM32 product.

当preload功能使能后,对这些寄存器的访问都不会改变定时器配置通道的操作模式。因为,写操作处理的是这些控制位的实例,他们的控制定时器输出通道的有效实例不会被改变。

As soon as a commutation event is generated inside the timer, the content of the preload instances of these control bit-fields is transferred into the active instances and consequentially the channel output mode may be changed.

一旦触发事件发生,设置值就会立即反馈到通道的输出上。

Depending on the configuration of the CCUS control bit-field within the timer control register 2 (TIMx_CR2), the commutation event can be generated after detecting an active edge on the timer trigger input signal (TRGI).

通过配置CCUS,可以将timer trigger input signal (TRGI).设定为边缘触发。

In particular, it can be generated after detecting an active edge on the timer active synchronization ITRx input of the timer peripheral (ITRx inputs are part of the sources of TRGI signal).

再特殊一点,就是当探测到一个ITRX 定时器的活动边沿的时候,产生输出。

This capability may be used to make one timer control when a commutation event on a second timer should be triggered through inter-timers synchronization. Alternatively, the commutation event may be generated by software through the setting of the COMG control bit-field within the TIMx_EGR timer register.

这个功能可以把两个定时器串起来,软件设定事件产生寄存器,可以拿到

STM32 - 定时器高级应用说明 - 多触波的实现 (N-pulse waveform generation using timer synchronization)- 01相关推荐

  1. STM32 - 定时器高级应用说明 - 多触波的实现 (N-pulse waveform generation using timer synchronization)- 02

    上一节讲了基础,本节实做: The main features described are: • TIMER 2 is configured as master trigger mode to tri ...

  2. STM32 - 定时器的设定 - 基础 - 05 - Arbitrary waveform generation using timer DMAburst feature - 任意波形的序列产生

    DMA的功能不说了,如何产生任意序列的波形,我们仔细看看: 本节叙述了同DMA的方法,在不占用MCU资源的情况下,通过提前编辑一组任意定制的波形参数,实现复杂的波形输出. STM32 DMA-burs ...

  3. STM32 - 定时器高级应用说明 - 01 - Filtering stage - 波形输入的过滤

    Filter Stage 理解为定时器的采样时钟源. Timer inputs (like ETR input or channel inputs) feature a filtering stage ...

  4. STM32 TIM高级定时器死区时间的计算

    STM32 TIM高级定时器的互补PWM支持插入死区时间,本文将介绍如何计算以及配置正确的死区时间. 文章目录 什么是死区时间? 数据手册的参数 如何计算合理的死区时间? STM32中配置死区时间 什 ...

  5. STM32 TIM1高级定时器RCR重复计数器的理解

    STM32 TIM1高级定时器RCR重复计数器的理解 TIMx_RCR重复计数器寄存器,重复计数器只支持高级定时器TIM1和TIM8,下面看标准外设库的TIM结构体的封装: typedef struc ...

  6. STM32定时器配置(TIM1、TIM2、TIM3、TIM4、TIM5、TIM8)高级定时器+普通定时器,定时计数模式下总结

    STM32定时器配置(TIM1.TIM2.TIM3.TIM4.TIM5.TIM8)高级定时器+普通定时器,定时计数模式下总结 文章结构: --> 一.定时器基本介绍 --> 二.普通定时器 ...

  7. 【STM32】高级定时器、通用定时器和基本定时器---配置寄存器产生PWM

    文章目录 1.高级定时器和通用定时器 2.配置产生PWM 1.高级定时器和通用定时器   高级定时器:TIM1.TIM8   Tips:黄色词条为高级定时器相对于通用定时器的功能.   通用定时器:T ...

  8. stm32定时器输出pwmIO口模拟pwm——呼吸灯

    文章目录 前言 一.pwm(脉冲宽度调制) 1.基本原理 2.PWM的优点 3.PWM波的控制方法 二.定时器的相关介绍 1.stm32定时器 2.通用定时器计数模式 3.定时器的基本工作原理 三.定 ...

  9. stm32定时器实验

    目录 1.定时器简介 2.软件设计 3.代码 main timer.c timer.h 1.定时器简介 stm32定时器可以被用于:测量输入信号的脉冲长度(输入捕获)或者产生输出波 形(输出比较和 P ...

最新文章

  1. IoC容器Autofac(1) -- 什么是IoC以及理解为什么要使用Ioc
  2. numpy库学习 向量 矩阵 均为有两个[[ ,而秩为1的数组只有一个[ np.array([[]]) 与np.array([])的区别
  3. leetcode 136. Single Number
  4. “百度智能云”下,群星璀璨,照亮百度世界2020
  5. 经典C语言程序100例之五五
  6. 微信小程序前后端配合的支付代码
  7. numpy中两个array数值比较,在IDE中显示完全相同,但是bool判断两个array是否相等却返回False
  8. java提取文章摘要内容
  9. 人类长非编码RNA表达数据库,整合9种重要生物学场景(发育、癌症、病毒侵染等)...
  10. 连通子图什么意思_为什么海洋科学家说:地球是“漏”的?
  11. 我的手机,被“探针”了吗?
  12. url参数拼接 php,js URL参数的拼接方法比较_javascript技巧
  13. FileZilla Server多实例监听
  14. java实现qq登录界面_java实现简单的QQ登录界面
  15. YY语音CTO赵斌的技术创业
  16. [英文邮件写作技巧] 表达感谢,提出问题,描述附件
  17. liunx安装jdk报A fatal exception has occurred. Program will exit
  18. 设计模式-装饰器模式 C++
  19. 哪些著名软件是用C、C++编写的?
  20. XML中DTD,XSD的区别与应用

热门文章

  1. 【Nginx那些事】nginx配置实例(一)反向代理
  2. 递归计算二叉树的高度_如何使用递归方法计算二叉树的高度
  3. 如何使用Python的Flask和Google App Engine构建网络应用
  4. js/d3.min.js_在5分钟内学习D3.js
  5. 我从Kaggle机器学习竞赛中获得的经验
  6. java springMVC生成二维码
  7. Django查询数据
  8. 用Python手写五大经典排序算法,看完这篇终于懂了!
  9. Apache Flink新场景——OLAP引擎
  10. 并发服务器模型——单进程服务器