Among these parts, counters/timers are easy to confuse for beginners. Below I will talk about some of my views on this aspect based on my own learning experience.
The essence of counters and timers is the same, they both count the pulses generated in the microcontroller, but the counter is the pulse triggered by the microcontroller's external trigger, and the timer is the pulse generated by the microcontroller's internal triggering of the crystal oscillator. When their pulse intervals are the same, the counter and timer are the same concept.
There is a concept of overflow in both timers and counters, so what is overflow? Haha, we can get the answer from a little common sense in life. When a bowl is placed under the faucet to collect water, after a while, the water in the bowl is full and overflow occurs. In the same way, assuming that the water from the faucet drips into the bowl drop by drop, there will always be a drop of water that causes the water in the bowl to overflow. The water overflowing in the bowl is wasted, but the overflow in the timing counter of the microcontroller will cause an interrupt. As for what an interrupt is, we will talk about it next time. Here is just a preliminary concept. An interrupt is a process that can interrupt the normal operation of the system and run the interrupt service program. When the service program is finished, it automatically returns to the interrupted place to continue running.
In the timer counter, we have a concept called capacity, which is the maximum count. Mode 0 is 2 to the 13th power, mode 1 is 2 to the 13th power, mode 2 is 2 to the 8th power, and mode 3 is 2 to the 8th power. If we compare the water droplets to pulses, then the last drop of water that causes the water in the bowl to overflow is the last pulse of the overflow of the timer counter.
In various microcontroller books, when introducing the timer counter, they all talk about an initial count value. So what is the initial count value? Here we still assume a water drop bowl. Assuming that the 100th drop of water can make the water in the bowl overflow, we know that the capacity of this bowl is 100. Question 1, how can I make the bowl overflow after receiving 10 drops of water? Haha, I can imagine that if we take an empty bowl to receive water, it still takes 100 drops of water to overflow, but if we take a bowl that is already filled with water, then it doesn't take 100 drops. So far, we can calculate that in order to make 10 drops of water make the water in the bowl overflow, then the bowl must first be filled with 90 drops of water.
In the timing counter, these 90 drops of water are what we call the initial value. Question 2: How can we use a single-chip microcomputer to count 100 products in a workshop and automatically pack them?
We can use the counter to count to 100 and perform an automatic packaging action in the interrupt.
Here, there are three initial count values. Assume that there is method 0: initial count value = 8912 (2 to the 13th power) - 100 = 8812. Method 1: initial count value = 65536 (2 to the 16th power) - 100 = 65436. Method 0: initial count value = 256 (2 to the 8th power) - 100 = 156.
According to the initial value obtained, it can be converted into hexadecimal or binary, and then counting or timing can be performed. Of course, in order to make the program run completely, the corresponding registers need to be set. These can be found in various microcontroller tutorials.
Previous article:Design and implementation of intelligent taxi meter
Next article:C8051FXX encryption method
- Popular Resources
- Popular amplifiers
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
- 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
- Recently, there have been frequent incidents of electric vehicle explosions and fires. What do you think about this? ?
- Explanation of several clock frequencies in LPC2478
- (Transfer) Detailed explanation of the CC2640R2F BLE5.0 BLE connection parameter update process
- Real-time Zooming Module of Digital X-ray Image Based on FPGA
- 【LAUNCHXL-CC1350-4】- 5: A method to install XDCTools on Windows 10 has also been found. . .
- There are several packaging issues in PCB components
- Read the good book "Operational Amplifier Parameter Analysis and LTspice Application Simulation" + First Reading Experience
- The arrogant math master will lower her pride when she meets a master
- MSP430 Comparator
- Basic questions about capacitors