Timing and counting are the most common and widespread problems in daily life and production.
The timer and counter functions are implemented using essentially the same logic, and both functions involve counting input signals, essentially counting pulses. Counters count and indicate the number of input signals (events) in any interval, while timers count the number of input signals in a specified interval to indicate the elapsed time.
In a single-chip microcomputer, when the timer/counter is used for timing, it counts the machine cycle (obtained by dividing the crystal oscillator of the single-chip microcomputer by 12). Since the cycle of each count is fixed, the counting time can be easily calculated based on the number of counts. As shown in Figure 1.
Figure 1 Counting and timing
Let's start with a routine in life: a basin is under a faucet, the faucet is not closed tightly, and water drips into the basin. The capacity of the basin is limited, the water drops continue to fall, and the water in the basin continues to fill up. Eventually, a drop of water makes the basin full of water, which is "overflow".
If an empty basin needs 10,000 drops of water to be full, you can put some water in before starting to drip, which is called the initial count value. If you want to count 9,000 now, you can put 1,000 drops of water in first, that is, the initial count value is 1,000, and then count 9,000 to overflow and generate an interrupt.
The method of counting initial values is usually used in single-chip microcomputers. If each pulse is 1 microsecond, it takes 256 microseconds to count 256 pulses. If you want to time 100 microseconds, just put 156 in the counter first, and then count 100 to generate an interrupt when the overflow occurs. As shown in Figure 2.
Figure 2 Timer/Counter Overflow
There are three main ways to achieve timing or counting.
(1) Software delay
Software delay is achieved by using a microprocessor to execute a delay program segment. Because it takes a certain amount of time for the microprocessor to execute each instruction, software delay is achieved through the loop of instructions. Software timing has the characteristic of not using hardware, but it takes up a lot of CPU time. In addition, the accuracy of software timing is not high. Under different system clock frequencies, the time to execute an instruction is different, and the timing time of the same software delay program will also be different.
(2) Hardware timing
Hardware timing uses the frequency divider in the digital circuit to appropriately divide the system clock to generate the required timing signal. It can also use a monostable circuit or a simple timing circuit (such as the commonly used 555 timer) to control the timing time by an external RC (resistance, capacitance) circuit. Such a timing circuit is relatively simple, and the timing time can be changed within a certain range by using different frequency division multiples or changing the resistance value and capacitance value.
(3) Programmable hardware timing
The biggest feature of programmable timer/counter is that it can realize the change of timing time through software programming, and complete the timing function or counting function through interruption or query method. This circuit not only can change the timing value and timing range through program, but also has multiple working modes, can output multiple control signals, and has strong functions.
Previous article:Parallel communication and serial communication
Next article:The basic process of single chip microcomputer system interrupt
Recommended ReadingLatest update time:2024-11-16 19:48
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Application of TPS92633-Q1 in automotive LED taillights/small lights
- [AutoChips AC7801x motor demo board review] Unboxing and hardware circuit learning
- More than 90 people from a research institute in Hefei, Chinese Academy of Sciences, resigned collectively. The personnel department said: They were poached
- Offline voice module VB-01/VB-02
- Xiaobai asks for help 555
- Stimulating Intelligent and Continuous Innovation——STMicroelectronics Industry Summit 2022 is just waiting for you
- What are the types of d-sub connectors and how to choose them
- Infrared tube reception problem
- What does nationality have to do with a good entrepreneur?
- Qinheng CH55X online simulation method description - using ISD51 for online simulation