The difference between 51 single chip microcomputer timer and counter

Publisher:温暖梦想Latest update time:2016-06-20 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
In the process of learning 51 single-chip microcomputers, we often find that interrupts, counters/timers, and serial ports are the difficulties in learning single-chip microcomputers. For beginners, these parts are difficult to understand. But I personally think that these parts are the key points of single-chip microcomputer learning. If you don’t understand these parts in a semester of classroom learning or self-study, it means that you haven’t mastered 51 single-chip microcomputers, let alone the development of single-chip microcomputers. We all know that in the finished single-chip microcomputer projects, many of them are based on these parts as theoretical foundations. The perpetual calendar is based on the timer, the alarm is based on the interrupt, and the online communication is based on the serial port.

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.

Reference address:The difference between 51 single chip microcomputer timer and counter

Previous article:Design and implementation of intelligent taxi meter
Next article:C8051FXX encryption method

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号