Discussion on the expansion of STM32 timer from 16-bit to 32-bit

Publisher:SparklingRiverLatest update time:2016-10-18 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The general-purpose timer of STM32 can realize many functions, such as timing counting, measuring the pulse width of external signals, generating PWM waveforms, measuring input PWM waveforms, etc. In all these operations, the number of bits of the timer mainly affects two parameters, one is the accuracy of timing or measurement, and the other is the length of timing. Let's take a look at the accuracy and length of timing in a list below:

Please refer to the right half of the figure below for the functions of each prescaler:

As can be seen from the table, at the highest accuracy (14ns), the timing length is only 0.91ms, and at an accuracy of 250ns (i.e. 4MHz), the timing length can reach 16.38ms. This is the case when only the independent working mode of the timer is used.

For applications that require high precision and long delay, 16-bit timing (the above-mentioned precision and time length) is not enough. There are two solutions to this problem; the first method is to complete it through software relay. The feasibility of this method lies in the long timing time, allowing the software to have enough time to intervene in the counting. This method is very convenient and can be used in most cases. The second method is to use the timer cascade function unique to STM32 to achieve a 32-bit counting effect, because the cascade is triggered by hardware. After setting up the various registers, the software does not need to intervene midway, and the requirements of high precision and long delay can be achieved. Furthermore, STM32 has a maximum of four timers. If connected in series, it can even achieve a 4*16=64-bit counting effect.

Simply put, the cascade function means that when the timing condition of one timer is met, a trigger signal can be generated to start the timing operation of another timer.

There is an application note and corresponding example program on the ST website, which details and demonstrates how to use the cascade function of STM32 to achieve 32-bit input capture and 32-bit output comparison functions. You can study it:

Application note download address: http://www.st.com/stonline/products/literature/an/13711.pdf

Demo program download address: http://www.st.com/stonline/products/support/micro/files/an2592.zip

Here is a summary of the application note:

[AN2592 How to use the clock chaining function of STM32F101xx and STM32F103xx to achieve 32-bit timer precision] (August 2007)

  Many applications require 32-bit accuracy for measuring the period of external signals exceeding several hundred seconds and for generating delayed or periodic signals with larger intervals.

  The STM32F101xx and STM32F103xx provide the ability to link two 16-bit timers to obtain 32-bit precision, using a special configuration and linking mechanism of the timers.

  This article gives the basic principles of simulating a 32-bit timer and introduces two basic operation modes: input capture mode and output compare mode. Each mode is introduced separately with examples.

Finally, I hope that all friends can help us understand the application requirements more deeply. For industrial control and embedded control instruments, because the applications we are exposed to are limited, we are not very clear where such high-precision timing is needed. If it is convenient, we can do a few case analyses, which will be more conducive to our future product upgrades and positioning.

Postscript: You are a serious and responsible moderator, and the information you provide is very complete. STM32 has many TIMs, and I believe it will also show its power in occasions such as PWM motor control. Under specific design requirements, expanding 16 bits to 32 bits is also a very important skill.
Keywords:STM32 Reference address:Discussion on the expansion of STM32 timer from 16-bit to 32-bit

Previous article:Encrypting embedded code programs running on STM32
Next article:CAN bus debugging of STM32

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号