Timer with input capture block

A free video tutorial from FastBit Embedded Brain Academy
? Amplify Your Embedded Skills ?
Rating: 4.6 out of 5Instructor rating
11 courses
120,547 students
Timer with input capture block

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 course and I hope you're enjoying this course. And in this lecture on words, let's understand the input capture block of the timer and we are going to understand the input capture with an example. Believe me, this is the easiest way to understand this. Otherwise, if I keep explaining the theory, you will get confused. Now the exercise is actually a frequency measurement application. And here we are going to measure the time period of a signal using a timer and that signal is a continuous square wave and that is actually applied to the timer. OK. So, actually this works something like this. We have a timer, right? timer and we are going to give input signal to this timer and the source for the signal is, we can take from LSE, that is the Low crystal Oscillator, Low Frequency Oscillator, which is present in your board. OK. We actually connect LSE to the timer and then we can measure, what exactly is the time period of that low frequency crystal oscillator. And if we know the time period, it is very easy to calculate the frequency, isn't it? So, I will demonstrate this application with LSE and you can also use HSI as an input signal to the timer and then you can measure the frequency. And we actually know the frequencies of these clock signals, isn't it? So, HSI is 16MHz and LSE is 32.768kHz, right? So, remember that these are not timer clock frequencies. So they don't drive timer. OK, those are external signals. OK, connected to the timer in order to measure the time period of those signal. Great. Now, let's see, how we can do this. So, now let me take you to the reference manual and let's go to the basic timers and here in the basic timer, If you just browse through this, OK, so this is a block diagram of the basic timer, you already know most of the components of this block diagram and if you just observe this diagram you will find that, there are no inputs to the timer, isn't it? So, that also means that, the timer lacks input capture pins. So, input capture pins or channel are actually used to feed external signals to the timer. OK and this timer lacks input channels. OK. it also lacks output channels. So, that's why, it's called as basic timer. So, we cannot use basic timer for this purpose and we have to take a look into some other timers. Now, let's go to the general purpose timers. Now, in the general purpose timers, we have TIM2 to TIM5 and TIM9 to TIM14. So you are free to use whatever timer you like. So, I would go for, let's say TIM2. OK. And if I just browse this document and here it is. We can see that, the block diagram is a little complex in the general purpose timer compare to the basic timer. OK. But remember that general purpose timer also includes basic timer.So when you see a complex block diagram in your reference manual, so don't get intimidated, because most of the time you have to concentrate on only in your those information which you really want, OK. Because the block diagram, It's a generic block diagram for the general purpose timer. And since it is having lots of feature, it looks a little complex. So, don't get intimidated and just concentrate on those things which you really want. That's it. OK. So, now here we don't care about all these details. So, first let's identify the basic time base unit in this general purpose timer and it is very easy to identify, here it is. So, this is actually the basic timebase generation unit. Right? So, you already know this, prescaler, counter and auto-reload register, right? And now, you just see at the left hand side and you can find that this timer has got 4 input channels. . So, if you ask me, what exactly is a channel? So, channel is nothing but inputs to the timer. Later you have to assign a pin of the micro-controller to these channels. OK. So, that's what we did in the case of UART also, isn't it? So, UART has TX and RX lines. OK. You actually did the alternate function configuration in order to assign two pins to those purpose, isn't it? One is for the RX purpose and one is for the TX purpose. So, just like that. You take just some pins of the micro-controller or GPIOs most of the micro-controller and do the alternate functionality configuration as the timer channels. OK. So, that we'll see while we do the programming. So, this timer has got 4 input channels and you can see that those are actually connected to the input filter as well as the edge detector blocks. OK. So, that means the input channels are pre-processed like for de-bouncing etc., And after that, you'll see a capture and compare register for each channel. OK, there is one capture and compare register for every channel and that is just a register OK. Register means a placeholder for some value that will explore later. And this timer also gives you 4 output compare channels or 4 output channels. So, regarding the output channels, we need not to worry, because we have separate discussion for that. OK. So, in this case, these things will not come into picture for our discussion it is not relevant. And so, you can read it as capture register. OK. So, when you are dealing with output compare, you read this register as compare register, OK. So, compare is for output block, capture is for input block. And let me now take you to my PPT and show you the simplified block diagram. All right, so this is the simplified block diagram. So, I removed all the clutters, what we saw in the previous block diagram and this is the timer with input capture block. So, if you just take a look here, this is actually the input capture block which is just attached to the basic time base generation unit, use which you saw in the previous lectures, isn't it? So, this is extra, that's it. OK. And here you apply your external signal to these channels and you can later measure the frequency or time period of these applied signal. So, how to calculate the time period? What is the mechanism involved? We will explore in the next lecture. Alright, so I hope you understood this and if you have any doubts it will get cleared as you make progress. All right. So, I'll see you in the next lecture.