[N32L43X Review] 4.Timer&MultiTimer Hardware Timer and Software Timer
[Copy link]
N32 has rich timer resources
There are two advanced timers (TIM1, TIM8) with PWM complementary output
5 normal timers (TIM2, TIM3, TIM4, TIM5, TIM9)
2 basic timers (TIM6, TIM7)
There is also a low power timer and 2 watchdog timers, and a basic Systick
Systick asked me to use it for Delay application, so I chose a normal timer as the system time base timer.
First of all, we need to understand that the clock bus of TIM belongs to APB1, which is 1/4 of the main frequency by default, that is, when the main frequency is set to 108MHz, the APB bus is 27MHz. In order to use the USB function in the future, the main frequency is set to 96MHz
If you use the advanced timer (TIM1, TIM8), please note that the APB2 clock is 1/2 of the main frequency.
Once the clock frequency is determined, the frequency can be divided according to this configuration.
1/4 of 96MHz is 24MHz, and dividing by 24 times is exactly 1MHz
Then if the load value is set to 1000, it will be 1mS
Such a normal timer function is completed
Usually the hardware timer configuration and calling are a bit complicated. Occasionally, I saw the open source MultiTimer, so I was excited.
After testing, it is indeed very convenient and very easy to transplant.
There are now two versions, a development version more suitable for Linux systems, and a Master version more suitable for microcontrollers.
There are two versions of the port here. Use whichever you like.
Let me first talk about how to use development
1. Continuously ++ system timing variables through time base timer interrupt
2. Write a function that returns the system timer
3. Configure the required timers
4. Loop and execute MultiTimerYield();
Of course, the functions of the two versions are the same
In this way, one hardware timer can be used to expand N timers, and the calling method is also very simple, which is very suitable for microcontrollers with limited resources.
In addition, the author also has a button driver MultiButton
It is also very easy to use. It can recognize functions such as pressing and releasing, double-clicking and long pressing. If you are interested, I will find time to port it to N32.
|