http://www.cs.indiana.edu/~geobrown/book.pdf

An example of a basic timer is illustrated in Figure 10.1.

This timer has four components – a controller, a prescaler (PSC), an “auto-reload” register (ARR) and a counter (CNT).

The function of the prescaler is to divide a reference clock to lower frequency.

The STM32 timers have 16-bit prescaler registers and can divide the reference clock by any value 1..65535.

For example, the 24Mhz system clock of the STM32 VL Discovery

could be used to generate a 1 Mhz count frequency with a prescaler of 23 (0..23 == 24 values). T

he counter register can be configured to count up, down, or up/down and to be reloaded from the auto reload register

whenever it wraps around (an “update event”) or to stop when it wraps around.

The basic timer generates an output event (TGRO) which can be configured

to occur on an update event or when the counter is enabled (for example on a GPIO input).

To understand the three counter modes consider Figure 10.2.

In these examples, we assume a prescaler of 1 (counter clock is half the internal clock), and a auto reload value of 3.

Notice that in “Up” mode, the counter increments from 0 to 3 (ARR) and then is reset to 0.

When the reset occurs, an “update event” is generated.

This update event may be tied to TRGO, or in more complex timers with capture/compare channels

it may have additional effects (described below).

Similarly, in “Down” mode, the counter decrements from 3 to 0 and then is reset to 3 (ARR).

In Down mode, an update “event” (UEV) is generated when the counter is reset to ARR.

Finally, in Up/Down mode, the counter increments to ARR, then decrements to 0, and repeats.

A UEV is generated before each reversal with the effect that the period in Up/Down mode

is one shorter than in either Up or Down mode.

Many timers extend this basic module with the addition of counter channels such as the one illustrated in Figure 10.3.

The “x” refers to the channel number – frequently, timers support multiple channels.

With this modest additional hardware, an output can be generated whenever the count register reaches a specific value

or the counter register can be captured when a specific input event occurs (possibly a prescaled input clock).

An important use of counter channels is the generation of precisely timed pulses.

There are two variations of this use – “one-pulse” pulses,

in which a single pulse is generated, and pulse width modulation, in which a series of pulses is generated with the counter UEV period.

The pulse width is controlled by the Capture/Compare Register (CCR).

For example, the channel output (OCxREF) may tied to whether the CNT register is greater (or less) than the Compare register.

In Figure 10.4 we illustrate the use of two channels for one-pulse and PWM outputs.

Here we assume that the ARR is 7 and the CCR is 3.

In PWM mode, ARR controls the period, and CCR controls the pulse width (and hence the duty cycle).

In one-pulse mode, the pulse begins CCR cycles after an initial trigger event, and has a width of ARR-CRR.

It is possible to use multiple channels to create a set of synchronized, pulses beginning at precise delays from each other.

A timer channel may also be used to measure pulse widths – in effect decoding pwm signals.

There are many other configuration options for the STM32 timers including mechanisms

to synchronize multiple timers both to each other and to external signals.

In the remainder of this chapter we consider two timer applications including PWM output (Section 10.1),

input pulse measurement (Section 10.2).

In Chapter 13 we show how to use a timer to control DMA transfers for an audio player and

in Chapter 14 we use a timer to sample and analog input at regular intervals.

STM32 Timer : Base Timer, Input Capture, PWM, Output Compare的更多相关文章

  1. PIC32MZ tutorial -- Output Compare

    Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...

  2. STM32 System and Timer Clock Configurations

    STM32 System and Timer Clock Configurations I've started writing some software to drive a series of  ...

  3. TIMER门控模式控制PWM输出长度

    TIMER门控模式控制PWM输出长度 参照一些网友代码做了些修改,由TIM4来控制TIM2的PWM输出长度, 采用主从的门控模式,即TIM4输出高时候TIM2使能输出 //TIM2 PWM输出,由TI ...

  4. PIC32MZ tutorial -- Input Capture

    Today I accomplish a simple application for PIC32MZ EC Starter Kit. This application uses Input Capt ...

  5. An Isolated DAC Using PWM Output

    An Isolated DAC Using PWM Output Arduino‘s (ATmega328P) PWM outputs via analogWrite can be convenien ...

  6. 深入比特币原理(三)——交易的输入(input)与输出(output)

    本节内容非常重要,如果你不能很好的掌握本节内容,你无法真正理解比特币的运行原理,请务必要学习清楚. 比特币的交易模型为UTXO(unspend transaction output),即只记录未花费的 ...

  7. Linux部署Django:报错 nohup: ignoring input and appending output to ‘nohup.out’

    一.部署 Django 到远程 Linux 服务器 利用 xshell 通过 ssh 连接到 Linux服务器,常规的启动命令是 python3 manage.py runserver 但是,关闭 x ...

  8. STM32: TIMER门控模式控制PWM输出长度

    搞了两天单脉冲没搞定,无意中发现,这个利用主从模式的门控方式来控制一路PWM的输出长度很有效. //TIM2 PWM输出,由TIM4来控制其输出与停止 //frequency_tim2:TIM2 PW ...

  9. STM32 Seminar 2007 -- Timer

随机推荐

  1. 【两分钟视频教程】如何使用myeclipse在mac本机运行iOS配套的服务器

    如何使用myeclipse在mac本机运行iOS配套的服务器  

  2. HTTP1.0 HTTP 1.1 HTTP 2.0主要区别

      HTTP1.0 HTTP 1.1主要区别 长连接 HTTP 1.0需要使用keep-alive参数来告知服务器端要建立一个长连接,而HTTP1.1默认支持长连接. HTTP是基于TCP/IP协议的 ...

  3. Linux Timer定时器【转】

    转自:https://www.jianshu.com/p/66b3c75cae81 timerfd为Linux为用户程序提供的定时器接口,该接口基于文件描述符,通过文件描述符的可读事件进行超时通知,且 ...

  4. python enumerate用法总结【转】

    enumerate()说明 enumerate()是python的内置函数 enumerate在字典上是枚举.列举的意思 对于一个可迭代的(iterable)/可遍历的对象(如列表.字符串),enum ...

  5. Objective-C 与JAVA的SHA1/HmacSHA1加密算法实现

    最近研究IOS手机上登录的功能.由于加密方式使用SHA1算法.网上也没找到直接的例子,最终参照StackoverFlow上的大神,完成了加密实现. 先上代码: //HmacSHA1加密: +(NSSt ...

  6. 输出联系变化的数字seq

    主要作用:输出联系变化的数字格式:Seq 分割符号 开始 间隔 结束开始默认是1,间隔默认是1,分隔符默认回车一位是结束,两位首末,三位首间隔末,没有四位,开始可以是负数主要参数:-f 指定格式打印- ...

  7. Cover Points

    CF#511 div2 B 现场掉分赛(翻车)...qwq 题目大意: 给定n个点的左边,你需要求出一个腰长最短的等腰直角三角形(顶点为坐标轴原点),是的所有点都在这个等腰直角三角形的内部或者边上. ...

  8. ​学会用各种姿势备份MySQL数据库

    学会用各种姿势备份MySQL数据库 前言 为什么需要备份数据? 数据的备份类型 MySQL备份数据的方式 备份需要考虑的问题 设计合适的备份策略 实战演练 使用cp进行备份 使用mysqldump+复 ...

  9. 中文分词-jieba

    支持三种分词模式: 精确模式,试图将句子最精确地切开,适合文本分析: 全模式,把句子中所有的可以成词的词语都扫描出来, 速度非常快,但是不能解决歧义: 搜索引擎模式,在精确模式的基础上,对长词再次切分 ...

  10. 【转】使用TCP协议连续传输大量数据时,是否会丢包,应如何避免?

    使用TCP协议连续传输大量数据时,是否会丢包,应如何避免? 比如发送文件.记得有人提过可能会发生什么堆栈溢出.怎样避免呢?是不是可以收到数据后发送确认包,收到确认包后再继续发送.或是发送方发送了一些数 ...