STM32 timer self-study notes

Publisher:算法之手Latest update time:2017-10-29 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I have been studying STM32 timers for more than a week, and it is really confusing. The various modes are mainly because we don't know much about the application of the various modes of the timer. However, we can get started quickly with the basic part of the timer. That is, the update event interrupt after the timer is completed. Capture and comparison are acceptable, but the slave mode, trigger, Hall sensor and encoder are directly confusing, not to mention the brake, dead zone, complementation, etc. in the advanced timer.

When I looked at timers, I looked at general timers, mainly brakes, encoders, etc. These are rarely used by me, and even if I use them one day, I forget them. I looked at the general timer no less than 4 times. Finally, I can sort it out. Let me talk about it slowly below.

The general timer has the following modes:

Counting mode (count up, count down, center-aligned count)

Capture comparison mode: (Capture) 1. Input capture mode

2. PWM input mode

(Comparison) 1. Forced output mode

2. Comparison output mode

3. PWM mode

4. Single pulse mode

Encoder Mode

Slave mode 1, reset mode

2. Gated mode

3. Trigger mode

4. External clock mode + trigger mode

Main Mode

Clock: 1. Internal clock

2. External clock 1

2. External clock 2

This is just for a better understanding, and more details can be found in the data sheet. And the timer does give you a new understanding every time you look at it, so I'm not sure it's completely correct.

First, the correspondence between all modes can be seen in the internal diagram given by the timer. When you have a certain understanding of the timer, you can understand the diagram more clearly.[Repost] [Original] STM32 timer self-study notes


In order to avoid clutter, we only analyze the graph.

The shaded parts in the figure have a shadow register and are enabled. In PWM mode, the shadow register must be enabled.

Looking at the left side of the picture, there are TIMX_ETR, TIMX_CH1, TIMX_CH2... These pins are input pins, and TIMX_ETR is a trigger pin. Regardless of what they do for now, look at TIMX_CH1 on the right, these are comparison output pins.

Generally, the clock in the data manual starts to get confusing backwards. The timer has three types of clocks (the book says four, but in fact the fourth is one of the second). You can see the rectangle above the picture, which contains "trigger controller, slave mode controller, encoder".

1. You can see that the internal clock (CK_INT) is connected to this rectangle.

2. The external trigger pin TIMX_ETR pin is filtered and processed to form the ETRF signal, which is also connected here (it can provide the clock mentioned in external clock mode 2, and it can also trigger)

3. ITR0, ITR1 and other signals are also connected to this rectangle. These signals are the output signals of other timers. (This is also what the manual says about using a timer as a pre-scaling of another timer. Then the timer driving this timer is the master timer. The MMS bit in TIMX_CR2 must be configured to determine what kind of signal it outputs to the slave timer. The TS bit in TIMX_SMCR is set to select which timer to drive the current timer)

4. TIMX_CH1~CH4 can also be configured as trigger input pins and can also provide clocks for the timer.

In TIMX_SMCR (slave mode control register), SMS is set to 000 (slave mode is turned off), and the clock is provided by the internal clock when the timer is enabled. When the SMS bit is configured to a non-zero value, and the input pin is selected in the TS bit, and the related clock is enabled, an edge or a level on the pin will be used to drive the counter to count, and the external clock 2 can only be provided by ETR, and the external clock 1 can also be provided by ETR or other pins.

In addition to the internal clock, other pins connected to the slave mode controller (the encoder is not clear, I didn't see it, and the following is not related to it) can not only provide clocks, but also generate corresponding events. For example, when clock mode 2 is turned off and clock mode 1 is not selected, the external trigger pin (other input pins can also be used) can reset the counter, start the counter, etc.

CH1~CH4 can control the slave mode, and it can also be used as an input for a capture signal. At this time, the slave mode can be turned off, or the clock mode 1 input signal in the slave mode can be turned on to save the current counter value into the CCR register.

The output of CH1~CH4 is set to the set level by setting the value of CCR register. When the timer is set to master mode, the output 0CXREF will be output internally to the slave mode timer, and the slave mode timer will generate the event set by SMS in SMCR.

After talking so much, I am confused. In short, the input pins usually work in slave mode, that is, the timer counter counts or stops by these pins. (My personal understanding)

These pins can be used to make the internal timer count according to a certain polarity of the external pin, that is, external clock mode.

The signals input to these pins can reset, start, stop, etc. the internal counter.

These pins can be provided externally, or they can be outputs generated by an event of other internal timers or comparison outputs to drive the current timer.


Keywords:stm32 Reference address:STM32 timer self-study notes

Previous article:STM32 ADC and serial port
Next article:STM32 learning - low power mode

Recommended ReadingLatest update time:2024-11-16 15:48

The location of interrupt source name and interrupt processing function name in stm32
The two files are respectively in stm32f4xx.h (interrupt name) CORE—startup_stm32f40_41xxx.s (interrupt function name) #if defined (STM32F40_41xxx)   CAN1_TX_IRQn = 19, /*! CAN1 TX Interrupt */   CAN1_RX0_IRQn = 20, /*! CAN1 RX0 Interrupt */   CAN1_RX1_IRQn = 21, /*! CAN1 RX1 Interrupt */   CAN1_SCE_IRQn = 22, / *!
[Microcontroller]
STM32_DAC output voltage
Today we will explain the "STM32F103 DAC output voltage" function.   The software project provided and explained today is modified based on the software project "A0.0.0 (STM32F10x_TIM delay)". If you don't know how it came about, please follow the WeChat public account "EmbeddDeveloper" for more information. Based on
[Microcontroller]
STM32_DAC output voltage
STM32 Core Coupled Memory (CCM)
Written in front Today, when I was working on STM32F4, I used a special memory called CCM. I searched the Internet but didn't find much introduction, so I just looked it up in the manual. Basic Architecture   Without further ado, let's take a look at what is special about this memory. The official basic architectur
[Microcontroller]
STMicroelectronics launches industrial smart sensor evaluation kit
Accelerate application design based on IO-Link transceivers and STM32 MCUs China, December 15, 2021 - Featuring a slim 45.8mm x 8.3mm motherboard, the STMicroelectronics STEVAL-IOD04KT1 industrial sensor kit simplifies the development of compact IO-Link (IEC 61131-9) sensors for fieldbus-independent p
[sensor]
STMicroelectronics launches industrial smart sensor evaluation kit
STM32 TFT learning notes - brush image
Host environment: Windows 7 SP1 Development environment: MDK5.14 Target board: ST NUCLEO-F303RE TFT model: 2.4 inches, with touch, SD card, 240*320 resolution, 260,000 colors Driver IC:ILI9325 ST library version: STM32Cube_FW_F3_V1.1.0 After the screen refresh, it is easy to implement the image refresh ope
[Microcontroller]
STM32 TFT learning notes - brush image
Getting started with BIT_BAND (bit segment/bit band) and alias area in STM32
1. What are bit segments and alias areas? Yes, remember MCS51? MCS51 has bit operations, which take one bit (BIT) as the data object. MCS51 can simply operate the second bit of port P1 independently: P1.2=0;P1.2=1; thus, the third pin (BIT2) of port P1 is set to 0 or 1. Now the bit segment and bit band alias area of
[Microcontroller]
STM32 Experiment 4: Key Interrupt
Port Configuration #include "stm32f10x.h"//PA13 PA15void KEY_Init(void) {     GPIO_InitTypeDef GPIO_InitStructure;     EXTI_InitTypeDef EXTI_InitStructure;     NVIC_InitTypeDef NVIC_InitStructure;     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE); //Enable external clock     GPIO_InitStruct
[Microcontroller]
stm32 startup file description
To put it bluntly, the following are the differences. There are selective differences when choosing the startup file! startup_stm32f10x_cl.s Interconnect type STM32F105xx, STM32F107xx startup_stm32f10x_hd.s Large capacity STM32F101xx, STM32F102xx, STM32F103xx startup_stm32f10x_hd_vl.s Large capacity STM32F100xx star
[Microcontroller]
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号