Understanding Interrupts in Embedded Design (Part 1)

Understanding Interrupts in Embedded Design (Part 1)
Click the blue text to follow, grateful for your presence

Welcome everyone to followHao Xushuang Electronic Design Team, this public account will regularly update related technical materials, software, etc., interested friends can browse othermodules of this public account, hope everyone can gain something they want from this public accountthings.

This article mainly discusses the understanding of interrupts in embedded design (Part 1)

Understanding Interrupts in Embedded Design (Part 1)

The internal structure of the MCU is similar to a core control center, controlling many peripheral functional modules.

Understanding Interrupts in Embedded Design (Part 1)

Their communication method is similar to a teacher giving a lecture and students listening to the lecture. The teacher is the CPU, and the students are the peripheral functional modules. The teacher can ask a certain student to perform certain actions, and the teacher can lead the progress of the entire class.

In this communication mode, the teacher is called the master, and the students are called the slaves. The teacher lets the students work in an orderly manner according to their teaching ideas, which we call polling mode (taking turns to ask).

In polling mode, the slave cannot actively initiate any events and can only wait for the master to access or control.

If all peripheral functions are outputs, the above mode is still relatively okay, that is, the master controls all outputs according to its own will. But what if the peripheral functions also have certain input functions?

For example, when an external button is pressed, an action needs to be taken. The master needs to know in time whether the peripheral circuit is pressed. If polling mode is used, then the master reads the status of the external button according to its own will.

First, let’s think about it, if we keep reading the button’s status, the master will not be able to perform other functions. If we read the button’s status after a while, then the master may not be able to respond in time to the button press event.

So how should we handle it at this time?

The CPU was designed with this situation in mind, so the CPU gives the peripheral circuit a permission, which is to interrupt the normal operation of the CPU under certain circumstances.

For example: the teacher gives the students a permission, which is the right to raise their hands. The teacher normally teaches, and when students encounter certain problems, they raise their hands; the teacher records where they are in the lecture, and then asks the students why they raised their hands and addresses the issue; after handling the issue, the teacher resumes the lecture from where they left off.

This mode is called interrupt mode;

Understanding Interrupts in Embedded Design (Part 1)

Interrupt request: students raise their hands;

Interrupt response: the teacher puts down what they are doing and prepares to address the students’ raised hands.

Executing the interrupt handler: the teacher asks the students why they raised their hands and solves the problem.

Interrupt return: the teacher solves the students’ problem and finds the previous progress.

Interrupt mode can effectively improve the CPU’s execution efficiency: polling mode requires access every once in a while, and most of the time the peripheral circuit has no situation, so a lot of time is wasted; with interrupts, the peripheral circuit needs to handle events before an interrupt is generated, improving the CPU’s efficiency.

Interrupt mode can effectively improve the CPU’s timely feedback: polling mode requires access every once in a while, and when the peripheral circuit has events that need to be handled, that event may have already occurred for some time; with interrupts, the peripheral circuit needs to handle events, and an interrupt signal will be generated in time, allowing the CPU to receive the interrupt signal and process it immediately, improving the CPU’s ability to handle events in a timely manner.

When designing the MCU, if there is a need, you can use interrupt mode to achieve your needs.

Some resources in this content are sourced from the internet. If there is any infringement, please contact the author.

If you think this public account is good, you can share it with your friends, thank you and best wishes!

Leave a Comment

×