Application and research of multi-interrupt processing technology based on single chip microcomputer

Publisher:InnovateMindLatest update time:2013-02-17 Source: dzscKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  introduction

  The number of interrupt sources of PIC series microcontrollers has reached 14, which is quite rich; but it also brings some problems: the problem of not being able to handle "high-level priority processing" when handling multiple interrupts, so many interrupt sources are prone to interrupt conflicts when processing, how to effectively handle the timing of interrupt arrival, and how to implement the algorithm have become the first problems that need to be solved.

  1 Interrupt handling technology

  Although the PIC series microcontrollers have many interrupts, they do not specify the priority of interrupts. When an interrupt occurs, no judgment is made, but the pointer is pointed to 0004H (the starting address of the interrupt) first, and the next operation is completely left to the user's "soft processing". The interrupt timing diagram is as follows:

Figure 1 INT pin interrupt timing diagram

  The protection of the interrupt scene is a very important part of the interrupt technology. For the PICl6F87X microcontroller, during the interrupt service program, only the return address, that is, the value of the program counter Pc, is automatically pushed into the hardware stack; and in the interrupt handler, it is generally necessary to back up the contents of these registers at the beginning of the interrupt handler, just like using registers such as WReg and STATUS, that is, to perform the so-called scene protection.

  The PICl6F87X sub-series microcontroller has up to 14 interrupt sources, but only one interrupt vector. There is no priority level between the interrupt sources, and there is no non-maskable interrupt. The PIC microcontroller uses a hardware stack structure, which does not occupy program memory space or data memory space, and does not require the user to operate the stack pointer; but at the same time, it also determines that it does not have the push (PUSH) and pop (POP) instructions in other microcontroller instruction systems. When implementing interrupt scene protection, it cannot be implemented using a stack, but rather through copying and backing up variables. The general implementation method is: first determine the scene to be protected, generally including the contents of registers such as WReg and STATUS, and then define variables corresponding to these registers on each page. To back up the scene. When an interrupt occurs, copy the contents of these scene registers to the backup variables at the beginning of the interrupt processing code, and then copy them back to restore the scene when exiting the interrupt processing:


  2 Design of frequency meter based on PICl6F87X microcontroller

  With the rapid development of electronic technology, control devices with single-chip microcomputer as the core have been fully penetrated into all aspects of test instruments and metrology verification. At the same time, frequency meter, as a common tool, is widely used in engineering technology, radio measurement, metrology and other fields. The designed frequency meter is mainly used to measure pulse frequency.

  2.1 Design Principles

  The PIC16F87X microcontroller has integrated capture, comparison, and pulse width modulation (PWM) modules. When the module works in capture mode, it can capture the rising or falling edge of the external input pulse and generate a corresponding interrupt.

  The PIC16F87X microcontroller also integrates a timer module, which uses TMRI as a timer. The working principle of the timer is to increment from 0000H to FFFFH through the TMR1 "register pair" TMR1H: TMR1L. When it returns to 0000H, a high overflow will occur, and the overflow interrupt flag TMR1IF will be set to 1, causing a CPU interrupt response.

  In a uniform pulse sequence, the pulse frequency value is equal to the number of pulses occurring per unit time. Based on this principle, the built-in timer module TMR1 of the PIC16F87X series microcontroller can be used for timing, and the capture function of the module can be used at the same time. Every n (n=1, 4, 16) pulses are captured once and an interrupt is generated, and the timer timing tl and tm when the first and (m-1)*n+1 pulses arrive can be recorded.

  The pulse frequency value can be obtained by dividing the number of captured pulses by the time interval between the 1st and (m-1)*n+1th pulses. Therefore, the pulse frequency value calculation formula is:

  f=n*(m-1)/(tm-t1)

  If a larger frequency needs to be measured, a frequency divider with a corresponding multiple can be connected between the frequency to be measured and the CPU * port as needed. Each time a 1/n frequency divider is connected, the measurable frequency range can be expanded n times (as shown in Figure 2).


Figure 2 CPU external connection diagram [page]

  2.2 Programming

  (1) Main program

  The main program flow chart is shown in Figure 3.

Figure 3 Main program flow chart

  (2) Interrupt program

  The interrupt program flow chart is shown in Figure 4.

Figure 4 Interrupt subroutine flow chart

  3. Issues to note when handling multiple interrupts

  1) To handle the problem of multiple interrupts, the interrupt handler algorithm can be roughly divided into two categories: weak interrupt priority (using CALL and RETURN method) and strong interrupt priority (using GOTO method).

  2) If multiple interrupt requests occur simultaneously, the order in which the interrupts are processed depends on the order in which the interrupt sources are checked in the interrupt routine.

  3) To prevent interrupt requests from being lost, pay attention to the following two situations: If the interrupt interval of the same interrupt source is less than the processing time of the interrupt service, the interrupt event may be ignored (reflected in the interrupt service process, the flag bit is set twice in succession). For example: the time interval between interrupt events is 30ms, and the time for interrupt service processing plus jump judgment is 50ms, then the situation will be as follows:

  [Number of interruptions______1][Number of interruptions______2][Number of interruptions_____3][Number of interruptions_____4]

  [Number of processings______1][Number of processings______2][Number of processings_____4]

  If IF is cleared at the beginning of interrupt processing, then as shown in the figure above, interrupt events 3 and 4 occur twice during processing time 2. In this case, even if IF is cleared before interrupt time 3 occurs, the third interrupt will be lost.

  In addition, even if the time interval between interrupts is greater than the time interval between interrupt services, if the instruction for clearing the interrupt flag is placed at the end of the interrupt service subroutine, the interrupt request may be lost (i.e., two interrupt flag setting events correspond to only one clearing instruction and one interrupt processing). In other words, if the instruction for clearing the interrupt flag is placed at the end of the interrupt service program, the opportunity to respond to the second interrupt request from the interrupt source during interrupt processing may be lost.

  4) In order to write a concise interrupt program, we should grasp the real-time feature of the interrupt. For the real-time interrupt data acquisition system, the interrupt feature is data acquisition. Therefore, in the interrupt program, only data acquisition and flag bit setting should be processed, and data processing should be placed outside the interrupt. The main program performs data processing through loop detection. The specific approach is: first open up a "storage buffer" as a transmission medium for the collected data, that is, to store the collected data and wait for the main program to process it; the interrupt program is responsible for data collection and assigns the collected data value to the "storage buffer"; the main program repeatedly detects the "storage buffer" through conditional loop statements and processes the collected information in a timely manner. In this way, the processing method can not only effectively realize the function of the interrupt, but also greatly reduce the time of each interrupt and improve the response speed of the entire program.

  5) For applications with strict requirements on interrupt response and processing time, the instruction arrangement for protecting the scene should also consider the delay issue.

  6) The CPU must be prohibited from responding to interrupts when performing table lookup operations to avoid jumping to an undesired address when the interrupt returns.

  4 Conclusion

  Flexible application of interrupts can not only save a lot of CPU resources, but also simplify the program. It has higher real-time performance and stability. After testing, this frequency meter has the advantages of high measurement accuracy, easy use, stability and reliability, and can be used in the field of measurement and testing. At the same time, due to the use of software control, simple circuit structure, less hardware, low cost and easy to carry, it can also be widely used in industrial and agricultural production and residents' lives, and has promotion value.

Keywords:MCU Reference address:Application and research of multi-interrupt processing technology based on single chip microcomputer

Previous article:Common Input/Output Circuit Design Methods for Single Chip Microcomputers
Next article:C language exercises for microcontroller counter

Recommended ReadingLatest update time:2024-11-16 17:43

The concept of timer/counter in MCS-51 microcontroller
1. Concept of timer/counter of MCS-51 microcontroller In a single-chip microcomputer, the relationship between pulse counting and time is very close. Each time a pulse is input, the value of the counter will automatically accumulate by 1, and the time taken is exactly 1 microsecond. As long as the time interval betwe
[Microcontroller]
The concept of timer/counter in MCS-51 microcontroller
Design of harmful gas infrared detection and voice warning system based on AVR microcontroller
The infrared sensing system is used to sense whether there are harmful gases nearby. When the infrared sensing system senses that harmful gases are approaching, it sends a high level that lasts for a period of time; the single-chip microcomputer starts the voice chip by opening the interrupt, and the single-chip microc
[Microcontroller]
Design of harmful gas infrared detection and voice warning system based on AVR microcontroller
Design and implementation of automobile anti-theft alarm system based on single chip microcomputer
With the rapid development of economy, cars have entered thousands of households. At the same time, car thefts are increasing day by day. Car theft is a huge loss for car owners. Therefore, car anti-theft systems and car positioning systems have huge market demand. At present, some vehicle anti-theft systems on the ma
[Microcontroller]
Design and implementation of automobile anti-theft alarm system based on single chip microcomputer
Advantages of PIC series microcontroller applications
1. The biggest feature of the PIC series of microcontrollers is that they do not simply pile up functions, but start from reality, pay attention to the performance and price ratio of products, and develop multiple models to meet different levels of application requirements. In reality, different applications have diffe
[Microcontroller]
Learning 51 MCU - AD sampling and DA output based on PCF8591
     First, let’s think about a question: is our world digital or analog?       Of course it is analog, all quantities change continuously within a certain range. In order to describe these quantities more conveniently, we digitize them. But digital quantities are different, they are discrete values.       For exa
[Microcontroller]
Learning 51 MCU - AD sampling and DA output based on PCF8591
51 MCU drive capability
"When the 51 microcontroller outputs a low level, the maximum current injected into a single pin is 10mA; the maximum total current injected into an 8-bit interface (P1, P2 and P3) is 15mA, and the maximum total current allowed to be injected into P0 is 26mA; the maximum sum of the currents allowed by all four interfac
[Microcontroller]
Compensation design of continuous tamping vehicle based on single chip control
0 Introduction     The development of road maintenance machinery in China started late. For a long time, the electrical control technology of tamping vehicles in China has relied on foreign imports. Due to the monopoly of foreign technology, the development of road maintenance machinery in China has been seriously hind
[Microcontroller]
Compensation design of continuous tamping vehicle based on single chip control
Development of digital controlled constant current source based on PWM function of AVR microcontroller
With the in-depth development of electronic technology, various intelligent instruments are becoming more and more numerous, involving more and more fields, and the requirements of instruments for power supply are becoming higher and higher. Nowadays, power supply equipment has a trend towards digitalization. Howeve
[Microcontroller]
Development of digital controlled constant current source based on PWM function of AVR microcontroller
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号