前言:直接开讲,请耐心看完 :

首先,OPM模式的波形可以通过主从模式进行触发,其次,OPM模式的波形本身可以进行波形定制。


1 OPM定义和功能说明

One-pulse mode (OPM) is a particular case of the previous modes. It allows the counter to be started in response to a stimulus and to generate a pulse with a programmable length after a programmable delay.

OPM 模式是一个比较特殊的模式,该模型的参数包括:可以定制的长度和Delay(相位)的波形

Starting the counter can be controlled through the slave mode controller. Generating the waveform can be done in output compare mode or PWM mode.

定时器的触发可以通过主从模式的定时器来控制,而输出波形可以是CC模式或者PWM模式。

Select One-pulse mode by setting the OPM bit in the TIMx_CR1 register. This makes the counter stop automatically at the next update event UEV.

在TIMx_CR1选择OPM模式使能OPM,同时定时器的计数器在下一个Event UEV停止计数


2 OPM设定的定时器通道相关控制寄存器:

2.1 OPM-使能-定时器控制寄存器:

TIM1 and TIM8 control register 1 (TIMx_CR1)

OPM模式,其实就是在一个脉冲波形后暂停计数,就这么简单,后面也方便你定制。

Bit 3 OPM: One pulse mode

0: Counter is not stopped at update event

1: Counter stops counting at the next update event (clearing the bit CEN)


2.2 OPM-波形的设定:

使能OPM之后,后面就是对OPM的输出波形进行设置:波形的设定,用CC(捕捉比较)的方式, 就是用定时器的计数去比较你的各种设定,然后,各种翻转逻辑,最后实现波形的定制。

A pulse can be correctly generated only if the compare value is different from the counter initial value.

后面要做的事情就是CNT(counter的计数)和CCRx \ ARR进行比较,当然在比较之前,如下:

Before starting (when the timer is waiting for the trigger), the configuration must be:

(向上计数的时候)CNT的计数应该小于CCRX或 ARR这样才能产生波形。

• In upcounting: CNT < CCRx ≤ ARR (in particular, 0 < CCRx)

• In downcounting: CNT > CCRx

2.2.1 设定输出波形的细节

The OPM waveform is defined by writing the compare registers (taking into account the clock frequency and the counter prescaler).

• The tDELAY is defined by the value written in the TIMx_CCR1 register.

我们知道CCR为CC模式的比较值,这个值来决定Delay也就是相位

• The tPULSE is defined by the difference between the auto-reload value and the compare value (TIMx_ARR - TIMx_CCR1).

自动装载值和比较值之间的差值用了决定脉宽


• Let us say the user wants to build a waveform with a transition from ‘0’ to ‘1’ when a compare match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload value.

我们假设我们的波形在CC模式比较匹配时候为高电平翻转,而当定时器计数达到自动装载值的时候为低电平翻转。所谓CC模式比较匹配,就是CNT = CCRx,这时候电平翻转到高,定时器计数达到自动装载值,就是CNT = ARR的时候,高电平变成低电平下图做了一些修改,原图遗失CCR1的横坐标线

对于输出的波形有多种选择,

To do this, enable PWM mode 2 by writing OC1M=111 in the TIMx_CCMR1 register.

111: PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT<TIMx_CCR1
else active. In downcounting, channel 1 is active as long as TIMx_CNT>TIMx_CCR1 else
inactive.

The user can optionally enable the preload registers by writing OC1PE=’1’ in the TIMx_CCMR1 register and ARPE in the TIMx_CR1 register.

Bit 3 OC1PE: Output Compare 1 preload enable
0: Preload register on TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the
new value is taken in account immediately.
1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload
register. TIMx_CCR1 preload value is loaded in the active register at each update event.

Bit 7 ARPE: Auto-reload preload enable
0: TIMx_ARR register is not buffered
1: TIMx_ARR register is buffered

In this case the compare value must be written in the TIMx_CCR1 register, the auto-reload value in the TIMx_ARR register, generate an update by setting the UG bit and wait for external trigger event on TI2.

(STM32手册这里好像有错误,应该是CC2P,不是CC1P)CC2P is written to ‘0’ in this example.

In our example, the DIR and CMS bits in the TIMx_CR1 register should be low.

Bits 6:5 CMS[1:0]: Center-aligned mode selection 00: Edge-aligned mode. The counter counts up or down depending on the direction bit (DIR).

Bit 4 DIR: Direction 0: Counter used as upcounter

The user only wants one pulse (Single mode), so '1’ must be written in the OPM bit in the TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over from the auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0', so the Repetitive Mode is selected. Particular case: OCx fast enable:

OPM模式也可以转成多波复制的模式,只需要OPM 位设为0即可。

In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the counter. Then the comparison between the counter and the compare value makes the output toggle. But several clock cycles are needed for these operations and it limits the minimum delay tDELAY min we can get.

局限性:就是Delay的最小时间是系统局限的,因为上述信号接入需要一点时间:

If the user wants to output a waveform with the minimum delay, the OCxFE bit in the TIMx_CCMRx register must be set. Then OCxRef (and OCx) are forced in response to the stimulus, without taking in account the comparison. Its new level is the same as if a compare match had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.

注意

要立即响应的得到最小Delay的话,需要使能OCXFE位,改位用来强制OCx对OCXREF的响应加速。

这个代价换来的意义是,多了仅仅两个时钟周期的响应时间。


For example the user may want to generate a positive pulse on OC1 (输出比较)with a length of tPULSE and after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.


2.3 设置触发和时钟通道,定时器信号通道选择:

  • Let’s use TI2FP2 as trigger 1:

选择触发信号:下图为Timer channel的图

我们这样理解定时器通道,定时器通道分成两个部分:输入、输出

输入的部分我们看:

TI1 、TI2这些都是input,输入通道包括输入滤波(可以滤除小的脉冲)和边沿检测,这样就到了TIxFPx(也就是输入经过滤波和预分频检测后的波形,叫做TI2FP2 Filtered Timer2 Input 2)。然后是,

IC1,input capture输入捕捉通道,也属于输入吧,这里又有在预分频后的信号叫,ICx,(每个信号给他定一个名称就是为了后面负责的通道组合做好标识)。然后是,

OC,输出比较通道,现在开始算输出通道。在进入输出通道OC之前,要开始做复杂的波形运算,达到我们想要的波形。就必须通过捕捉比较寄存器。通过设定通道的OCXREF、DTG的给到输出通道。

• Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.

将定时器输入通道TI2连接到TI2FP2,实际上是启用了CH2,

通道设定之后,通道的输出也就设定好了。


• TI2FP2 must detect a rising edge, write CC2P=’0’ in the TIMx_CCER register.

Bit 1 CC1P: Capture/Compare 1 output polarity

CC1 channel configured as output:

0: OC1 active high

1: OC1 active low


• Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=’110’ in the TIMx_SMCR register.

准备将TI2FP2作为从控制器的输入:

TIM1 and TIM8 slave mode control register (TIMx_SMCR)

Bits 6:4 TS[2:0]: Trigger selection

This bit-field selects the trigger input to be used to synchronize the counter.

000: Internal Trigger 0 (ITR0)

001: Internal Trigger 1 (ITR1)

010: Internal Trigger 2 (ITR2)

011: Internal Trigger 3 (ITR3)

100: TI1 Edge Detector (TI1F_ED)

101: Filtered Timer Input 1 (TI1FP1)

110: Filtered Timer Input 2 (TI2FP2)

111: External Trigger input (ETRF)


• TI2FP2 is used to start the counter by writing SMS to ‘110’ in the TIMx_SMCR register (trigger mode).

Bits 2:0 SMS: Slave mode selection

When external signals are selected the active edge of the trigger signal (TRGI) is linked to the polarity selected on the external input (see Input Control register and Control Register description.

000: Slave mode disabled - if CEN = ‘1’ then the prescaler is clocked directly by the internal clock.

001: Encoder mode 1 - Counter counts up/down on TI2FP1 edge depending on TI1FP2 level.

010: Encoder mode 2 - Counter counts up/down on TI1FP2 edge depending on TI2FP1 level.

011: Encoder mode 3 - Counter counts up/down on both TI1FP1 and TI2FP2 edges depending on the level of the other input.

100: Reset Mode - Rising edge of the selected trigger input (TRGI) reinitializes the counter and generates an update of the registers.

101: Gated Mode - The counter clock is enabled when the trigger input (TRGI) is high. The counter stops (but is not reset) as soon as the trigger becomes low. Both start and stop of the counter are controlled.

110: Trigger Mode - The counter starts at a rising edge of the trigger TRGI (but it is not reset). Only the start of the counter is controlled.

111: External Clock Mode 1 - Rising edges of the selected trigger (TRGI) clock the counter.



最后,来一个重点中的重点,相位调节示意图:

STM32 - 定时器的设定 -高级- 08 - One-pulse mode - 触发波的实现 - 可变长度和相位相关推荐

  1. STM32 - 定时器的设定 - 基础- 07 - 6-step PWM generation - 6步长PWM的产生 - COM Event的解释

    前言:本节主要讲互补输出的步长设定问题,同时引入了一个重要的参数COM,这个再诸多STM32的手册里面都过于分散,在本文有一个比较完备的小结: When complementary outputs a ...

  2. STM32 - 定时器的设定 - 基础- 06 - OCxREF signal - Clearing the OCxREF signal on an external event

    OCxREF signal 作为捕捉比较的定制化参考波形在对输出波形的配置上占有巨大的影响.如何将这个信号和外部输入的事件联系起来,能给系统的设计带来更多的可选择性. The OCxREF signa ...

  3. STM32 - 定时器的设定 - 基础 01.1 - Repetition counter

    前言:Repetition counter是一个STM32增强的计数器功能,有很多用途,本文尝试进行简单阐述: 我们理解为,就是定时器溢出再增加一个倍率rate 的控制.注意是倍率,也就是如果是定时1 ...

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

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

  5. STM32 - 定时器的设定 - 基础-04 - 输出波形控制 - PWM 模式

    PWM为诸多应用的基本波形,如何实现和如何定制,首先要了解STM32中PWM的实现方法. 在STM32中,PWM的实现主要通过控制 OCxRef (active high).:output compa ...

  6. STM32 - 定时器的设定 - 基础- 0A - Timers and external trigger synchronization - 定时器和外部触发的同步

    四种同步方式: The TIMx Timers can be synchronized with an external trigger in several modes: Reset mode, G ...

  7. STM32 - 定时器的设定 - 基础-03 - 输出波形控制 - Output compare mode

    1 简介: This function is used to control an output waveform or indicating when a period of time has el ...

  8. STM32 - 定时器的设定 - 基础 01 - Timer Base - Prescaler description - Upcounting mode

    前言:时基是定时器的最基本的功能: 本节详细叙述STM32的时基的功能. 1 Time-base unit The main block of the programmable advanced-co ...

  9. STM32 - 定时器的设定 - 基础- 02 - Capture/compare channels 和相关设置寄存器 - 和STM32缩写词条解释

    前言:捕捉比较通道: STM32丰富的定时器的变化,就在这个模式,所以,复杂是必然的:当然,也可以简单来理解,就是通过选择定时器的输入的配置同时配置定时器的输出来获取我们需要的各种波形: 几个重要的缩 ...

最新文章

  1. 连麦互动直播方案全实践3:网易云信连麦互动的实现方案
  2. Nginx的官方简介
  3. Example-based volume illustrations
  4. E:Three Blocks Palindrome(hard and easy)(树状数组 ? 前缀和?)
  5. ftp改为sftp_科普!一文详解 FTP、FTPS 与 SFTP 的原理
  6. layui自定义ajax左侧三级菜单
  7. (1)鼠标单独移动两个actor
  8. date类before()方法的主要作用是_过程(Sub)、函数(Function)、集合(Collection)作用范围...
  9. python求解给定一字符串列表判定每个字符串可以构成的所有序列中回文序列的数目
  10. 阶段3 3.SpringMVC·_07.SSM整合案例_07.ssm整合之编写MyBatis框架测试保存的方法
  11. 香农编码,哈夫曼编码与费诺编码的比较
  12. java简单实现购物车添加,查询,修改,结算商品程序
  13. 苹果手机相机九宫格怎么设置_用苹果手机拍照,这3个媲美单反的设置不会用,就别说自己用苹果...
  14. 山东科技大学计算机学院奖学金,山东科技大学:一份特殊“奖学金”
  15. 万能RecyclerView分割线扩展
  16. 鸿蒙生态菁英难,重磅!华为联合西工大开设“鸿蒙生态菁英班”!
  17. 单位根检验、航空模型、季节模型
  18. 中国香茅醇行业研究与投资预测报告(2022版)
  19. 例题3-6 环状序列(Circular Sequence)
  20. Oracle经典书籍

热门文章

  1. C语言,利用一维数组中选择法对成绩高低排序和输出对应的学号及利用顺序查找查找学生成绩
  2. Springmvc 返回html视图解决
  3. 常用系统级加压工具简介
  4. mysql view在测试过程的应用
  5. python标准库之socket
  6. javascript功能_最新版本JavaScript仅具有2个新功能。 这是他们的工作方式。
  7. 大数据自学——Spark
  8. 当年一道python面试题的失利让我错过心仪公司,希望你不会
  9. Python这五个坑,80%你不知道(对的,五个你知道1个就达到一般水平了)
  10. ASP.NET自定义错误页面