当前位置:网站首页>[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
边栏推荐
- 【飞控开发基础教程1】疯壳·开源编队无人机-GPIO(LED 航情灯、信号灯控制)
- Tdengine landed in GCL energy technology, with tens of billions of data compressed to 600gb
- PXE efficient batch network installation
- ES:Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
- Definition and relationship of derivative, differential, partial derivative, total derivative, directional derivative and gradient
- My SQL is OK. Why is it still so slow? MySQL locking rules
- The first case in Guangdong! A company in Guangzhou was punished by the police for failing to fulfill its obligation of data security protection
- regular expression
- Nacos win10 安装配置教程
- 【Express接收Get、Post、路由请求参数】
猜你喜欢

Win11自动删除文件设置方法

The difference between anonymous methods and lambda expressions

Win11怎么自动清理回收站?

Tao and art of R & D Efficiency - Tao chapter

C#转整型的三种方式的区别以及效率对比

该怎么写单元测试呢

Wechat applet - network data request

【开发教程7】疯壳·开源蓝牙心率防水运动手环-电容触摸

2022 software testing skills postman+newman+jenkins continuous integration practical tutorial

TCP 和 UDP 可以使用相同端口吗?
随机推荐
工作流引擎在vivo营销自动化中的应用实践
How to test the circle of friends (mind map)
Replicationcontroller and replicaset of kubernetes
The process and harvest of developing browser plug-ins with clojurescript
操作系统迁移实战之在openEuler上部署MySQL数据库
Trends in software testing tools in 2021
It turns out that cappuccino information security association does this. Let's have a look.
Quickly learn to configure local and network sources of yum, and learn to use yum
Digital currency of quantitative transactions - merge transaction by transaction data through timestamp and direction (large order consolidation)
Threads and processes
限流对比:Sentinel vs Hystrix 到底怎么选?
Comprehensively design an oppe homepage -- layout and initialization
The Ministry of Public Security issued a traffic safety warning for summer tourism passenger transport: hold the steering wheel and tighten the safety string
【开发教程7】疯壳·开源蓝牙心率防水运动手环-电容触摸
Stop using xshell and try this more modern terminal connection tool
2022 software testing skills postman+newman+jenkins continuous integration practical tutorial
How can win11 system be reinstalled with one click?
如何保证缓存和数据库一致性
6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
【无标题】