1. Determination of “water volume”
We already know how to choose a "test tube", but how to fill it with "water" to determine the duration of the timing. First, let's take the "big test tube" as an example. Timer 0 has two registers, TH0 and TL0. Let's think of TH0 and TL0 as two 8-bit variables. Because we are using a "big test tube", these two 8-bit variables are equivalent to a 16-bit variable, TH0 is the high 8 bits (H: High), and TL0 is the low 8 bits (L: Low). If one more scale time passes, it will overflow.
Then at this time we will have "TH0 equals 255" and "TL0 equals 255", because the binary 11111111111111111 equals 65535 in decimal. 65535 plus 1 will overflow.
But we don't know how long it takes to increase one scale of water.
Here I will tell you the answer directly. Because we are using a 11.0592M crystal oscillator, the time it takes to increase the water level by one scale is (12/11059200) seconds.
If I want to explain all the principles of the above "(12/11059200)" knowledge point to everyone, it will take a lot of words. I suggest that you look for some related knowledge materials and video explanations such as machine cycles, clock cycles, etc. to have a deeper understanding of timers, or refer to Section 5.2 of the document "Hand-in-hand teaching you to learn 51 single-chip microcomputers".
However, we try to do more questions and gradually understand the results first. After you learn more related knowledge, you will naturally understand the reasons. This is also a teaching feature of this tutorial, which encourages everyone to find more related knowledge for mixed learning.
2. Timing milliseconds
If we use the "big test tube" to trigger an interrupt after 20 milliseconds, how can we achieve it?
First, we fill these two registers with values (fill them with a certain amount of water)
It can be seen that the two "8-bit variables" are combined from high to low to become a 16-bit variable. As for why the 20ms timing is filled in this way, we will first use the reverse method to demonstrate it to you.
The hexadecimal value of 0XB800 converted to decimal is 47104, so the timing duration is (65536-47104) = 18432 scale unit time.
18432*(12/11059200) = 0.02 seconds = 20 milliseconds.
Let's go back to the previous example. How do we assign initial values to TH0 and TL0 if we want a timing of 50 milliseconds?
Assume there are x scales left before overflow, x*(12/11059200)=0.05
The solution is x=46080.
Therefore, you need to fill the "large test tube" with 65536-46080=19456 scales of water in advance.
That is, the value of the "16-bit variable" filled in TH0 and TL0 is 19456.
19456 is converted to hexadecimal as 0x4C00.
So if you want a timing of 50 milliseconds, then "TH0=0x4C;", "TL0=0x00;".
3. Brief summary
We conclude that if the timing time is set to x seconds, then the initial value of the "16-bit variable" filled in the synthesis of TH0 and TL0 is 65536-(x/(12/11059200)).
Because (12/11059200) represents the time of one scale. If we want to time it to 0.05 seconds, then (0.05/(12/11059200)) represents the number of scales.
And 65536-(0.05/(12/11059200)) is the scale of water that we need to fill in advance.
If after reading this, the reader still cannot understand the principle of the timer after these three lectures, just put aside the theoretical understanding first, and use the following questions to vaguely understand the functions of this hardware module. Later, you can learn more about other people's comprehensive analysis of this knowledge point, so that you can thoroughly understand this knowledge.
I would like to express my deep emotion here: how important is the role of mathematics in our lives!
Previous article:51 MCU-Timer working mode
Next article:51 single chip microcomputer-simple application of timer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Update pyboard firmware using STM32CubeProgrammer
- Battery Characteristics Analysis and Design Scheme in Smart Home
- Technical Title
- 【Renovation of old things】 Graffiti desk lamp——lugl4313820
- Share the silkscreen search method of TI device models
- Some thoughts on the development of embedded technology
- Uncover the secrets of Shenzhou XII’s journey home!
- [Telink's new generation low power consumption, high performance, multi-protocol wireless kit B91 review] Unboxing + lighting
- Seek guidance from the experts and find routines.
- Qorvo at CES 2020: Innovative Solutions for 5G, IoT, Wi-Fi 6 and V2X