当前位置:网站首页>SCM learning notes 7 -- systick timer (based on Baiwen STM32F103 series tutorials)
SCM learning notes 7 -- systick timer (based on Baiwen STM32F103 series tutorials)
2022-07-24 01:21:00 【Mountains】
Chapter six SysTick Timer
SysTick Timer ( Also known as system tick timer ) It exists in Cortex-M3 A timer for .24 position , It's only decreasing , Nested in NVIC in , be-all Cortex-M The microcontroller of the core has this timer .
As long as it is ARM Cotex-M Series kernel MCU All include this timer .
Using the kernel SysTick Timer to achieve delay , It can not occupy the system timer , Saving resource . stay HAL The millisecond delay function of the library HAL_DRAYE(), It is realized by ticking timer .
SysTick The timer is a 24 Bit decrement timer , That is, the maximum value of the counter is 2^24, Each clock cycle minus 1, When it comes to 0 when , Will produce Systick abnormal , At the same time, it automatically reloads the initial value of timing , Start a new round of counting , once SysTick When the timer works, it will not stop automatically , Unless SysTick Timer control and status bit reset .
SysTick There are two clock sources , One is the clock of the system kernel , One is the external system clock .
6.1STM32 Of SysTick Timer
6.1.1 Clock source
Tick timer and Pu
The workflow of the general timer is the same , But the system timer is not attached APB1 or APB2 On , There are two sources of his clock , One is through AHB The clock 8 From frequency division (9MHz). One is direct connection AHB The clock (72MHz), The specific situation is configured through the register .

By setting SysTick The initial value of the timer and the clock frequency can obtain the desired timing time .
HAL Library provides HAL_SYSTICK_Config() Function to set the initial value .
6.1.2 Related registers
about SysTick There are still relatively few registers , Only 4 individual , Commonly used 3 individual .
1、 Control and status registers (STK_CTRL)

CLKSOUECE Is to choose the clock source of tick timer , You can choose AHB(72MHz) perhaps AHB8 frequency division (9MHz).
TICKINT Is set when the count reaches 0 when , Whether an abnormal interrupt request is generated .
ENABLE Is to enable the timer .
2、 Preload value register (STK_LOAD)

This register has only low 24 The seat can be used , So the maximum initial value of tick timer can only be 2^24. When the timer counts to 0 when , The value in this register will be reloaded , Start a new round of counting .
3、 Current value register (STK_VAL)

This register is used to view the current count value , The timer counts every time , Count the initial value minus 1, The count value in the current register is added 1, Similarly, his maximum value is 2^24.
4、 Quasi calibration value register (STK_CALIB)

This register is used for calibration , Not usually used .
6.1.3 Calculate the initial value of the count
By setting SysTick The initial value of the timer and the clock frequency reach the desired timing time .
Suppose the tick timer clock is 72MHz, That is, counting 1 Secondary use 1/72000000S, That is to say 1S Count 72000000 Time ,1ms Count 72000 Time ,1us Count 72 Time .
Write these initial values into the system tick timer , The timer decreases in each clock cycle 1, Reduced to 0 when , It happens to be the corresponding event , At the same time, an interrupt notification is generated , Load the initial value of the count again, so repeatedly .
HAL Library provides HAL_SYSTICK_Config() Function to set the initial value , The parameters inside are count values .
6.2HAL Library Configuration SysTick Timer
HAL Database alignment SysTick Timer configuration functions are commonly used in the following four .

Next entry HAL_SYSTICK_Config Look at the function HAL How to configure in the Library SysTick Timer .
He called ST Official functions SysTick_Config To configure the .

stay SysTick_Config in , First, put the initial value of the required count in the preload register , Then clear the current value register , Then set the... Of the control and status registers 2、1、0 position , Set the clock source of tick timer as AHB Regardless of the frequency , namely 72MHz, Allow interrupt request , Enable timer . In this way, the clock frequency of the tick timer is determined , The initial value of the count is determined , The timing time of the tick timer is determined .
You can call HAL_SYSTICK_CLKSourceConfig This function modifies the clock source of the tick timer .
Same as the previous interrupt function , Tick timer is also called in the system default interrupt service function HAL The interrupt service function of the library then HAL The interrupt function is calling the callback function .
SysTick_Handler–>HAL_SYSTICK_IRQHandler–>HAL_SYSTICK_Callback–> User's own code .

however HAL The library is highly dependent on tick timers , Tick timers are used in many places , So try not to set and use the tick timer ,STM32F103 The timer has 8 individual , Generally speaking, it's enough .
边栏推荐
- Sword *offer04 rebuild binary tree
- URL query parameter encoding problem (golang)
- How to troubleshoot the problem that VPN server cannot forward
- Parsing yaml configuration files using C language and libcyaml Library
- HCIP,OSPF综合实验
- Socket basic knowledge and various usage scenarios
- Form resume
- Concept, key points and summary of postgraduate entrance examination in Polymer Physics
- Create database table db.create in flask project_ all()
- Idea setting automatic package import and useless package deletion
猜你喜欢
随机推荐
刚开始使用,请教些问题和教程或分享帖子
OSI open system interconnection model and tcp/ip model
Why can't HMI panels of botu V17 and below connect with CPUs of 1500 firmware version 2.9 or 1200 firmware version 4.5?
HCIP中的MGRE GRE OSPF过程
Data warehouse construction - ods floor
Leetcode -- 136. a number that appears only once
C language database: an online dictionary based on TCP multi process, with detailed steps illustrated. Welcome to watch it
Matlab extracts the original data in the illustrations of the paper - fig2data tool
为什么博途V17及以下的HMI面板不能与1500固件版本2.9或1200版本4.5 的CPU建立连接?
Single chip microcomputer learning notes 3 -- single chip microcomputer structure and minimum system (based on Baiwen STM32F103 series tutorials)
使用C语言和libcyaml库解析yaml配置文件
Sublime text 3 Chinese + add common plug-ins
Hcip day 6_ Comprehensive experiment in special areas
Concept, key points and summary of postgraduate entrance examination in Polymer Physics
HCIP第二天笔记
Basic exercises of C language for beginners
Under instruction
BAT代码:批量文件下划线重命名
【FreeSwitch开发实践】专栏简介
Collation of key knowledge of high voltage technology









