STM32 Basic Timer Assembly

A free video tutorial from FastBit Embedded Brain Academy
? Amplify Your Embedded Skills ?
Rating: 4.6 out of 5Instructor rating
11 courses
120,562 students
STM32 Basic Timer Assembly

Learn more from the full course

Mastering Microcontroller: Timers, PWM, CAN, Low Power(MCU2)

Learn STM32 Timers, CAN, RTC, PWM, Low Power embedded systems and program them using STM32 Device HAL APIs step by step.

22:01:21 of on-demand video • Updated December 2023

You will learn from scratch about STM32 Timers : Basic and General Purpose Timers
Understand General purpose timer's Input capture and Output compare unit handling and Exercises
Handling of Timer interrupts : Time base interrupts, capture interrupts, compare interrupts
You will learn from scratch CAN Protocol, CAN Signalling, CAN Transceivers , Bus Access procedures
Understand CAN LOOPBACK mode, SILENT mode and NORMAL mode
Understand about CAN filtering
Learn about CAN interrupts
CAN Peripheral programming using STM32 device HAL drivers
You will master Low power modes of the MCU : SLEEP,STOP and STANDBY
You will understand different power domains of the MCU : VDD domain, 1.2V domain, backup domain
Understand Microcontroller Wakeup Procedures using : RTC, wakeup pins,EXTI,etc.
RTC interrupts and wake up procedures
Mastering Microcontroller Clocks Handling : HSE,HSI,LSE,LSI,PLL
Understand phase locked loop (PLL) programming
Learn PWM mode and Master through step by step code exercises
You should be able to quickly develop applications which involves STM32 Device HAL layer
Hey, welcome back to the lecture. So, let's get started working with timers and we'll start with basic timers. Now the basic timers have basic counting engine and they are majorly used for time base generation and these timers are very simple in nature. That's why, they do not have input/output channels associated with them. So, let's not worry about the input/output channels for the time being. And these timers do not have that. Now, let's go further. And here is the timer assembly of Stm32 basic timer. So, we can also call it as block diagram. Now, if you take a look into this block diagram, it is very very simple. So, here you can see that a counter place. This is a counting place, OK. Here the counting takes place and we call it as counter register. So, this is actually of 16 bit. OK. So, for basic timers the count register or counter is of 16 bit. So, this is a place where counting takes place. And here you can see that, that counting is powered by a clock that we call as count clock. So, a counting speed is depending upon Count clock. All right. So, this timer count clock is actually produced by this pre-scaler engine here and you can see that there is a input clock to the pre-scaler engine and that input clock is actually coming from here. That is the control block of the timer. And for the control block of the timer, another clock is coming here. That is the main timer clock. So, for this engine, the main source of the clock is from the RCC engine and that we call as reset and clock control. So, you maybe knowing this point from our earlier courses that the RCC block, that is reset and clock control block of the micro-controller manages clocks to the various peripherals of the micro-controller and it is also true that, it manages clock for the timer peripheral also. So, that's why, timer clock is a clock, which the main clock supply to the timer peripheral, that is here. And that is then processed by the control block of the timer peripheral and that clock is then supplied to the prescaler. And here, you can use the prescaler to slow down this clock. So, you can slow down this clock in order to produce the timer count clock and the counting speed of this counter depends upon this clock. And you can also find one important register. So, please note this register is a very very important that is called as ARR register that is called as Auto-reload register. So, whenever this counter reaches the value, which is stored in this register the counter resets back to 0 and it will start counting again. So, in the previous diagram I have shown some threshold, isn't it? that is some pre-programmed value. So, that value you have to store in the auto reload register. So, when the counter value reaches this value, the counter rolls back to 0 and it generates an event called update event and that update event has the potential to interrupt the processor. Now, let's move to the next slide. All right. So the time base unit includes, the time base unit means, so this whole thing is called as time base unit. So, this is a time base unit of the basic timer and the main parts of the time base units are the up counter. So that is this one, the up counter and the counter register, that is timer underscore count (TIMx_CNT). OK. So, the x you can replace by any timer peripheral number, like timer1 count register, timer6 count register, like that. OK. The counter register holds the value which is there in the counting engine that is the up counter, that means this counter value which is actually accessed by the firmware by using the counter register and then there is also something called as prescaler register that is timer underscore PSC (TIMx_PSC) and that is used to configure this prescaler engine. And after that we have very important register Auto- reload register that is also called as timer ARR (TIMx_ARR), which is used to hold the reload value for the timer. So, when the up counting value reaches the value which is stored in the auto-reload register, the counter will rolls back to the 0 and it will start counting again. That's about the time base unit of the basic timer. Now, let's move forward. All right. So, now we have got the basic overview about the timer clock, the prescaler output clock counter clock, the auto-reload register etc.. But all these things you can only understand by doing one exercise. And these four parameters are really important in order to write a timer application successfully. So, we'll understand all these things by doing one exercise. Now the exercise is very simple. Use the basic timer to generate an interrupt for every 100 ms and toggle the GPIO or LED inside the timer IRQ handler and verify using the logic analyzer. So, we are going to understand so many things by doing this single exercise. So, we are going to understand how to configure the basic timer, how to generate the desired delay, that is the time base generation and how to enable the timer interrupt, how to identify the timer IRQ number, how to implement the IRQ handler and lots of other things, we are going to understand by doing exercise. All right. From the next lecture onwards, let's try to complete this exercise. I'll see you in the next lecture.