Core concepts of microcontroller 1---timers and interrupts

Publisher:码上奇迹Latest update time:2023-01-31 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are two concepts that I personally think are the core of MCU learning:

  • timer

  • interrupt

If we delve a little deeper into the study of microcontrollers, we can't get rid of these two concepts.

Among them, the timer is the basis of interrupts, so the timer is still confused. It can be said that MCU programming and MCU learning have not yet been introduced.

The other way around can be said:

Once you understand the timer, you have completed 90% of the introductory learning of microcontrollers. No matter how much time you spend on the timer, it is worth it. It is the core breakthrough point for getting twice the result with half the effort.

What is a timer: a stopwatch, an hourglass.

animated cover

animated cover


From the name, we can know that the timer is an instrument that determines time.

To realize this function, several key conditions need to be established:

  • container

  • Initial value, initial setting

  • Trigger mechanism

  • end instruction

In fact, the above four conditions are not unique to timers. They need to be set as basic conditions for each component of the microcontroller to realize their functions.

Let’s first use an hourglass as an example to illustrate these four basic conditions:

  • Container: glass bottle filled with sand

  • Initial value: After the hourglass is turned upside down, half of the glass bottle contains the amount of sand. The hourglass usually contains all the sand.

  • Trigger: We turn the hourglass over with our hands

  • Ending indication: Our visual observation was that all the sand flowed into the lower half of the glass bottle.


Key conditions for timer implementation function:

  • Container: timer unit of microcontroller (timer 0, 1, 2 in the picture above)

  • Initial value, initial setting: fill in the initial value of each timer register

  • Trigger mechanism: software trigger, hardware trigger (the hourglass man triggers, as I said many times before, you can also think of the microcontroller as a person)

  • End indication: the initial value is cleared (becomes 0) or the initial value reaches the set value

In fact, timers generally turn off interrupts when initially set, enable interrupts when running, and trigger interrupts when the timer is completed. The term "interruption" will be discussed later, but I will mention it for now.


Reference address:Core concepts of microcontroller 1---timers and interrupts

Previous article:The simplest single-chip state machine model (X-state machine)
Next article:E2.2 Microcontroller open source framework--time slice polling--ideas

Latest Microcontroller Articles
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号