The indispensable "interruption" basic knowledge in the microcontroller control system

This series explains the basics of microcontrollers that are required for embedded system development technicians. Following the " Basic Composition and Working Principle of Embedded Programming MCU", " Peripheral Function Circuit of Embedded Programming MCU", "Programming Language and Development Environment of Single Chip Microcomputer " and "Basic Knowledge of Circuit Board Peripheral Function Circuit Control" , The final issue will introduce you to the basics of the "interruption" indispensable processing in the microcontroller control system.

"Interrupt" and "Polling"

This issue is the last issue of the serialization of the microcontroller. In this issue, we will explain the indispensable processing method in the MCU programming process, which is also indispensable in the control of the MCU---"interruption".

"Interrupt" processing is not a phenomenon unique to microcontroller control systems, and examples of "interruptions" in our daily lives are everywhere. Let's take a look at the examples around us. For example, although you know that there is a courier delivery today, but you don't know the exact time of the delivery, in this case, you may choose to sit in the living room and read the book, waiting for the delivery. During the reading of the book, when the doorbell rings, it indicates that the courier has arrived (there is an incident). This is an example of "interruption."

Figure 1: Schematic diagram of "interrupt" processing

Figure 1: Schematic diagram of "interrupt" processing

If you do not need to "interrupt" to handle the waiting mode, in the process of reading, you have to go to the door often to confirm whether the courier is coming. Frequently confirming whether or not there is an "event" occurs in this way is done by software programming in the microcontroller control. We call this treatment "polling" (Figure 2).

Figure 2: Schematic diagram of "Polling" processing

Figure 2: Schematic diagram of "Polling" processing

Interrupt processing in the microcontroller

In fact, the interrupt processing of the MCU is more complicated, and it is explained by the above example (while waiting for the fast delivery while reading the book).

While reading the book, waiting for fast delivery to the processing in the microcontroller

1) When the main program is being executed while reading

2) The doorbell that is being delivered quickly has an event, and sends an interrupt signal to the MCU.

3) interrupt the reading process, the microcontroller receives the interrupt signal, and suspends the main program being executed.

4) Record the page number being viewed to save the current state of the microcontroller (save to register)

5) Receive the courier to execute the corresponding interrupt source processing (interrupt program)

6) Confirm that the record you just made returns the status of the MCU you just saved.

7) Continue reading and continue to execute the program from where it left off.

Now, I believe everyone has some understanding of the "interruption". Let's take a look at how the internals of the microcontroller are implemented in the actual "interrupt" processing.

In the microcontroller, the interrupt signal that signals the event is usually from the input signal of the external INT pin or the signal from the internal peripheral function circuit such as timer or serial I/F. It is the interrupt controller that receives the interrupt signal. The interrupt controller sends the priority to the CPU in accordance with the priority of the generated interrupt signals. Of course, interrupt signals transmitted by devices that are set to be invalid are not passed to the CPU, and you can block or ignore them. The CPU executes the corresponding program (interrupt processing) in accordance with the instruction received from the interrupt controller.

Figure 3: "Interrupt" processing inside the microcontroller

Figure 3: "Interrupt" processing inside the microcontroller

Processing interrupts in real time

"Interrupt" and "polling" seem to be able to do the same thing, in fact they are very different. The difference is that when an event occurs, the interrupt mode can immediately perform the processing of the corresponding event. This type of processing of interrupts is referred to as real-time processing.

In the "polling" mode, real-time processing can also be implemented if the monitoring period of the event is short, but in the normal case, there are always multiple events, and sometimes the main program does not allow too short a loop. Therefore, it is difficult to implement real-time processing.

When "interruption" occurs, since only tens to hundreds of clocks are required from the detection of the event to the switching to the interrupt processing, the corresponding event can be processed in a short time.

For example, in the case of a key input or a switch input, it is an unpredictable event for the microcontroller when the switch will be pressed. Therefore, if you monitor it in the main program by "polling", you will waste CPU processing time for no reason, and if you want to perform multiple "polling" processing, the "polling" cycle will become longer. .

If you do not have the hardware knowledge of the microcontroller, it is difficult to understand and apply the "interruption". The content of "interruption" is also somewhat difficult, but it is a kind of processing that cannot be avoided in the control of the single-chip system. Therefore, everyone must deepen the understanding of the knowledge of the microcontroller, and master the basic knowledge and use of "interruption"!

Yuchai ≥1000KW Diesel Generator

Yuchai ≥1000Kw Diesel Generator,Yuchai Shanghai Genset,Yuchai Shanghai Power Generator,Yuchai Power Generator Set

Shanghai Kosta Electric Co., Ltd. , https://www.ksdgenerator.com