当前位置:网站首页>[basic course of flight control development 2] crazy shell · open source formation UAV - timer (LED flight information light and indicator light flash)
[basic course of flight control development 2] crazy shell · open source formation UAV - timer (LED flight information light and indicator light flash)
2022-07-26 16:49:00 【efans_ Mike】
COCOFLY course
—— Crazy shell · Unmanned aerial vehicle (uav) · series
Timer (LED Flight information light 、 The indicator flashes )

chart 1
One 、 About timer
The timer has a timing function , Similar to life “ alarm clock ”, You can use a timer to generate accurate timing time , Used to delay or process some real-time events .
STM32 Series of timers are divided into basic timers 、 Universal timer 、 Advanced control timer . The latter includes all the functions of the former . Usually ,STM32 Advanced timer yes TIM1、TIM8, The general timer is TIM2、TIM3、TIM4、TIM5, The basic timer is TIM6、TIM7.
And the main core of flight control STM32F103CBT6 Then there are 4 road 16 Bit timers are advanced timers TIM1、 Universal timer TIM2、TIM3 as well as TIM4.
Two 、 Timer register
STM32F103 There are many registers related to timers , Here we will only talk about a few important registers .
(1)TIMx_CR1: Enable register , Switch of the lowest control register , As shown in the figure below :

chart 2
TIM_CR1 The register mainly configures the cycle count of the timer 、 Enable, etc , for example CEN Position as 1 Is enable counting , by 0 Is to turn off counting .
(2)TIMx_DIER: Timer interrupt enable register , The switch of the lowest control event update interrupt , As shown in the figure below :

chart 3
The main function of this register is to configure the timer, which is the interrupt enable bit of the timer , The main use is UIE position ,UIE by 1 Is to enable interruption , by 0 Close interrupt .
TIMx_PSC: Timer clock division register , As shown in the figure below :

chart 4
This register is responsible for dividing the timer clock , Then output to the counter ,PSC[15:0] Is the frequency division coefficient .
(4)TIMx_ARR: The timer automatically reloads the register , As shown in the figure below :

chart 5
ARR[15:0] For automatic reload value , When the timer uses up counting , The count is equal to ARR when , Generate an update event ; When the timer is counting down , In the beginning ARR The value of is assigned to the count value , The count value is reduced downward to 0 when , Generate an update event , Once again ARR The value of is assigned to the count value , Count down for a new round .
(5)TIMx_SR: Status register , Mark the current events related to the timer / Whether the interruption occurs , We only use the flag bit of the lowest bit indicating the interruption of event update , As shown in the figure below :

chart 6
This register is mainly used to view the update interrupt flag bit of the timer , When the count overflows or underflows ,UIF The bit will be set to 1, Mark the completion of one count .
3、 ... and 、 Timer experiment
The experiment in this section is mainly aimed at GPIO Periodically light the flight information light and signal light of the UAV , Deform it , Use a universal timer TIM3 Periodically light and turn off the flight information lights and signal lights of the UAV at precise timing .
It is also known from the schematic diagram that the flight information lights of the UAV are connected together NPN triode Q1 On , And the base of the triode is connected to the single chip microcomputer PA8 On ; Two signal lights are connected to PC13 and PC14 On .

chart 7

chart 8

chart 9
About GPIO This part of the driver code can be inherited and retained , The difference is that you need to add timer initialization and configure timer interrupt , The idea of writing code is shown in the following table .
chart 10
Follow the code idea , Write code ( By calling the official library ) As shown in the figure below GPIO Related driver code :

chart 11

chart 12
Complete the configuration GPIO after , That is to configure the timer , our STM32 It's external 8MHz Crystal vibrating , The main frequency is 72MHz First, let's take a look at the clock tree , As shown in the figure below .

chart 13
The timer is mounted on APB1 Under the clock bus ( From the manual ), It can be seen from the clock tree APB1 The clock frequency used for the timer is not divided 72MHz, Divide the frequency register according to the timer clock (TIMx_PSC) And the timer automatically reloads the register (TIMx_ARR) The relationship between , We can draw , Timing time :
Tout=((arr+1)*(psc+1))/Ft s
among Tout Is the fixed time unit s,arr Is the initial value of the automatic reload register ,psc Is the frequency division coefficient ,Ft by APB The main frequency of , That is to say 72MHz. Then it's time 1s Then just put arr Set to load value 9999,psc Set to 7199 that will do , namely :
Tout=((9999+1)*(7199+1))/72000000
=10000*7200/72000000
=72000000/72000000
=1s
So you can get the timer initialization code, as shown in the following figure .

chart 14

chart 15
After the configuration is completed 1s The cycle enters a timer interrupt , In the timer interrupt, the flight information light and indicator light of the UAV GPIO The port can be flipped , Light up periodically , The code is shown in the following figure .

chart 16
Write the code and save 、 compile 、 download , Then you can see the flight control LED The pilot light and the cycle of the traffic lights under the four propellers 1S flashing , As shown in the figure below .

chart 17
边栏推荐
- JS API summary of Array Operations
- [express receives get, post, and route request parameters]
- 中金证券vip账户找谁开安全啊?
- [e-mr] error recovery record of namenode
- Set up typera drawing bed
- Wechat applet - network data request
- 我的sql没问题为什么还是这么慢|MySQL加锁规则
- srec_cat 常用参数的使用
- 极大似然估计
- Digital currency of quantitative transactions - merge transaction by transaction data through timestamp and direction (large order consolidation)
猜你喜欢

Guetzli simple to use

How does win11 automatically clean the recycle bin?

A preliminary understanding of MVC and ECS design architectures

Marxan模型保护区优化与保护空缺甄选技术、InVEST生态系统中的应用

Application of workflow engine in vivo marketing automation

【飞控开发基础教程1】疯壳·开源编队无人机-GPIO(LED 航情灯、信号灯控制)

如何保证缓存和数据库一致性

匿名方法和lambda表达式使用的区别

vlang捣鼓之路

我的sql没问题为什么还是这么慢|MySQL加锁规则
随机推荐
A preliminary understanding of MVC and ECS design architectures
别用Xshell了,试试这个更现代的终端连接工具
工作流引擎在vivo营销自动化中的应用实践
2022 Niuke summer multi school training camp 2 (bdghjkl)
Final consistency distributed transaction TCC
Docker install redis? How to configure persistence policy?
Tao and art of R & D Efficiency - Tao chapter
2022-2023 信息管理毕业设计选题题目推荐
营销指南 | 几种常见的微博营销打法
【开发教程9】疯壳·ARM功能手机-I2C教程
Win11系统如何一键进行重装?
研发效能的道与术 - 道篇
How to write unit tests
Singleton mode
Marxan模型保护区优化与保护空缺甄选技术、InVEST生态系统中的应用
Linux Installation mysql8.0.29 detailed tutorial
Tcpdump命令详解
微信小程序---网络数据请求
"Green is better than blue". Why is TPC the last white lotus to earn interest with money
Current limiting comparison: how to choose sentinel vs hystrix?