A method and controller for controlling periodic scheduling

By combining the foreground/background system and real-time operating system in the controller for context switching, the problems of load fluctuation and execution time instability in control cycle scheduling are solved, improving processing efficiency and logic processing stability, and adapting to multi-task execution requirements.

CN114428672BActive Publication Date: 2026-03-03SUPCON TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111601697.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2026-03-03
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

In existing technologies, when using a front-end or back-end system alone, the control cycle load fluctuates greatly when the user program executes multiple tasks. If a single program is too large or too small, the execution time becomes unstable. When using a real-time operating system alone, it is not suitable for sequential logic processing such as input/output, and the implementation is complex and highly uncertain.

Method used

The controller combines a front-end system and a real-time operating system for context switching. The front-end system processes input module data and outputs results, while the real-time operating system processes user program tasks. A time-slice polling scheduling method is used to achieve switching between systems.

Benefits of technology

It solves the problems of load fluctuation and execution time instability in the control cycle, improves processing efficiency, adapts to different task load requirements, simplifies input/output logic processing, and reduces uncertainty.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114428672B_ABST
    Figure CN114428672B_ABST
Patent Text Reader

Abstract

This invention relates to a method and controller for controlling cycle scheduling. Both a foreground / background system and a real-time operating system are located within the controller. The method includes: S1, the foreground / background system receives data from an input module connected to the controller and performs sequential logic execution processing on the data until the data processing is complete, obtaining the corresponding execution result; S2, performing context switching processing between the foreground / background system and the real-time operating system to switch from the foreground / background system to the real-time operating system within the controller; S3, the real-time operating system processes user program tasks until a preset time period is reached; S4, performing context switching processing between the real-time operating system and the foreground / background system to switch from the real-time operating system to the foreground / background system within the controller; S5, the foreground / background system outputs the execution result to an output module connected to the controller.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of control cycle scheduling, and in particular to a method and controller for control cycle scheduling. Background Technology

[0002] Controllers supporting multi-tasking and multi-cycle user programs typically employ foreground / background systems or real-time operating systems. In foreground / background systems, the control cycle is implemented through a background main loop. However, when multiple user programs execute simultaneously, the smallest granularity is the user program segment, and the size (execution time) of each segment is determined by the user. When the controller schedules a user program segment, it cannot exit midway. Significant differences in segment size can lead to large load fluctuations in the control cycle; an excessively large segment can cause the execution time of the current control cycle to exceed the upper limit; conversely, an excessively small segment can result in an insufficient execution time. User program configurations should strive to distribute the load evenly across each segment. Controllers using real-time operating systems implement the control cycle through multiple operating system tasks. However, when multiple tasks execute concurrently, they are unsuitable for sequential logic processing such as input / output, as their implementation is complex and inherently uncertain. Summary of the Invention

[0003] (a) Technical problems to be solved

[0004] In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides a method and controller for control cycle scheduling, which solves the problems in the prior art where, when using a single system, such as a foreground or background system, the controller cannot exit midway when scheduling a user program during multi-tasking execution of the user program; when the size of each program varies greatly, it will lead to large fluctuations in the control cycle load; if a single program is too large, it will cause the execution time of the control cycle to exceed the upper limit; if a single program is too small, it will cause the execution time of the control cycle to be too short; and if a real-time operating system is used alone, it is not suitable for sequential logic processing such as input / output, resulting in complex and uncertain implementations.

[0005] (II) Technical Solution

[0006] This embodiment provides a control cycle scheduling method, in which the foreground / background system and real-time operating system are both located in the controller. The control cycle scheduling method includes:

[0007] S1. The front-end and back-end systems receive data from the input module connected to the controller and perform sequential logic execution processing on the data of the input module until the data of the input module is processed and the corresponding execution result is obtained.

[0008] S2. Perform context switching processing on the foreground / background system and the real-time operating system to enable the controller to switch from the foreground / background system to the real-time operating system.

[0009] S3. The real-time operating system processes user program tasks until a preset time period is reached;

[0010] S4. Perform context switching processing on the real-time operating system and the foreground / background system to enable the controller to switch from the real-time operating system to the foreground / background system.

[0011] S5. The front-end and back-end systems output the execution processing results to the output module connected to the controller.

[0012] Preferably, S1 includes:

[0013] The front-end and back-end systems receive data from the input module based on the front-end interrupt routine.

[0014] The front-end and back-end systems perform sequential logical execution processing on the data from the input module based on the back-end program until the processing is complete and the corresponding execution results are obtained.

[0015] Preferably, the context switching process between the foreground / background system and the real-time operating system in step S2 specifically includes:

[0016] Save the context of the foreground and background systems to the foreground and background stacks, and then restore the user program task context from the task stack in the real-time operating system.

[0017] Preferably, S3 includes:

[0018] The real-time operating system uses a time-slice round-robin scheduling method to process user program tasks until the processing time of the user program tasks reaches a preset time period.

[0019] Preferably, the real-time operating system uses a time-slice round-robin scheduling method to process user program tasks until the processing time of the user program tasks reaches a preset time period, specifically including:

[0020] The real-time operating system performs time-slice processing on the program span of each user program task, obtains the program span time segment corresponding to each user program task, and queries and schedules the processing of the program span time segment corresponding to each user program task until the processing time of the user program task reaches the preset time period and then exits the scheduling.

[0021] Preferably, step S4 performs context switching processing between the real-time operating system and the foreground / background system, specifically including:

[0022] First, the context of the user program task in the real-time operating system is saved to the task stack in the real-time operating system, and then the context of the foreground and background systems is restored from the foreground and background stacks.

[0023] Preferably, S5 specifically includes:

[0024] The foreground and background systems output the execution results to the output module connected to the controller based on the foreground interrupt program.

[0025] Preferred,

[0026] The input module includes AI data and / or DI data.

[0027] Preferred,

[0028] The user program tasks are pre-stored in the controller's memory.

[0029] On the other hand, this embodiment also provides a controller, which, after being connected to the input module and the output module, executes any of the above-mentioned control cycle scheduling methods.

[0030] (III) Beneficial Effects

[0031] The beneficial effects of this invention are as follows: The control cycle scheduling method and controller of this invention, by employing a foreground / background system and a real-time operating system for context switching, compared to existing technologies, can use the foreground / background system to process data from input modules that require sequential execution, and use the real-time operating system to process data when multiple user programs are executing. This combines the advantages of both foreground / background systems and real-time operating systems, solving the problems of: when using only a foreground / background system, the controller cannot exit midway when scheduling a user program during multi-tasking; when the size of each program varies greatly, it leads to large fluctuations in the control cycle load; if a single program is too large, the execution time of the control cycle will exceed the upper limit; if a single program is too small, the execution time of the control cycle will be too short; and if a real-time operating system is used alone, it is unsuitable for sequential logic processing such as input / output, resulting in complex and uncertain implementations. This invention overcomes the disadvantages of both foreground / background systems and real-time operating systems. Attached Figure Description

[0032] Figure 1 This is a flowchart of a method for controlling cycle scheduling according to the present invention;

[0033] Figure 2 This is a schematic diagram of the control cycle in an embodiment of the present invention;

[0034] Figure 3 This is a schematic diagram illustrating the front-end and back-end system of the present invention receiving data from the input module and performing sequential logic execution on the data from the input module;

[0035] Figure 4 This is a schematic diagram illustrating the execution processing results issued by the front-end and back-end systems of this invention.

[0036] Figure 5 This is a schematic diagram illustrating how the real-time operating system of the present invention processes user program tasks using a time-slice round-robin scheduling method;

[0037] Figure 6 This is a schematic diagram illustrating the context switching process between the foreground / background system and the real-time operating system in an embodiment of the present invention;

[0038] Figure 7 This is a schematic diagram illustrating the context switching process between the real-time operating system and the foreground / background system in an embodiment of the present invention. Detailed Implementation

[0039] To better explain and facilitate understanding of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0040] To better understand the above technical solutions, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that the present invention can be understood more clearly and thoroughly, and that the scope of the present invention can be fully conveyed to those skilled in the art.

[0041] See Figure 1 This embodiment provides a control cycle scheduling method, in which the foreground / background system and real-time operating system are both located in the controller. The control cycle scheduling method includes:

[0042] S1. The front-end and back-end systems receive data from the input module connected to the controller and perform sequential logic execution processing on the data of the input module until the data of the input module is processed and the corresponding execution result is obtained.

[0043] S2. Perform context switching processing on the foreground / background system and the real-time operating system to enable the controller to switch from the foreground / background system to the real-time operating system.

[0044] S3. The real-time operating system processes user program tasks until a preset time period is reached;

[0045] S4. Perform context switching processing on the real-time operating system and the foreground / background system to enable the controller to switch from the real-time operating system to the foreground / background system.

[0046] S5. The front-end and back-end systems output the execution processing results to the output module connected to the controller.

[0047] Specifically, the controller implements a control cycle loop, see [link / reference] Figure 2 The control cycle includes front-end system 1 (i.e., front-end system 1 stage) → context switching → real-time operating system → context switching → front-end system 2 (i.e., front-end system 2 stage).

[0048] In practical applications of this embodiment, S1 includes:

[0049] The front-end and back-end systems receive data from the input module based on the front-end interrupt routine.

[0050] The front-end and back-end systems perform sequential logical execution processing on the data from the input module based on the back-end program until the processing is complete and the corresponding execution results are obtained.

[0051] For details, see Figure 3 In the first stage of the front-end and back-end system, the front-end interrupt program of the front-end and back-end system receives data from the input module, and then the back-end program of the front-end and back-end performs sequential logic execution processing on the data from the input module.

[0052] In practical applications of this embodiment, the context switching process between the foreground / background system and the real-time operating system in step S2 specifically includes:

[0053] See Figure 6 The context of the foreground and background systems is saved to the foreground and background stacks, and then the user program task context is restored from the task stack in the real-time operating system.

[0054] In the practical application of this embodiment, S3 includes: the real-time operating system uses a time-slice round-robin scheduling method to process the user program task until the processing time of the user program task reaches a preset time period.

[0055] In the practical application of this embodiment, the real-time operating system uses a time-slice round-robin scheduling method to process user program tasks until the processing time of the user program tasks reaches a preset time period, specifically including:

[0056] See Figure 5 The real-time operating system performs time-slice operations on the program span of each user program task to obtain the program span time segment corresponding to each user program task (i.e., Figure 5 The time slices in the process (one user program task corresponds to multiple time slices) are used to query and schedule the time slices corresponding to each user program task until the processing time of the user program task reaches the preset time period and then exits the scheduling.

[0057] In practical applications of this embodiment, step S4 performs context switching processing between the real-time operating system and the foreground / background system, specifically including:

[0058] See Figure 7 First, the context of the user program task in the real-time operating system is saved to the task stack in the real-time operating system, and then the context of the foreground and background systems is restored from the foreground and background stacks.

[0059] In practical applications of this embodiment, S5 specifically includes:

[0060] The foreground and background systems output the execution results to the output module connected to the controller based on the foreground interrupt program.

[0061] In the practical application of this embodiment, the data of the input module includes: AI data and / or DI data.

[0062] In the practical application of this embodiment, the user program task is pre-stored in the controller's memory.

[0063] User program tasks are stored in the controller's memory, and then the real-time operating system can process these user program tasks in memory.

[0064] On the other hand, this embodiment also provides a controller, which, after being connected to the input module and the output module, executes any of the above-mentioned control cycle scheduling methods.

[0065] The control cycle scheduling method and controller in this embodiment, by using a foreground / background system and a real-time operating system for context switching, can improve the control processing efficiency compared to the prior art. When the controller faces data from input modules that need to be executed sequentially, it can use the foreground / background system for processing, and when facing multi-task execution of user programs, it can use the real-time operating system for processing.

[0066] Since the system described in the above embodiments of the present invention is a system used to implement the method of the above embodiments of the present invention, those skilled in the art can understand the specific structure and modifications of the system based on the method described in the above embodiments of the present invention, and therefore will not be described again here. All systems used in the method of the above embodiments of the present invention fall within the scope of protection of the present invention.

[0067] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0068] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions.

[0069] It should be noted that any reference numerals placed between parentheses in the claims should not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention can be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In claims that enumerate several means, several of these means may be embodied by the same hardware. The use of the terms first, second, third, etc., is merely for convenience of expression and does not indicate any order. These terms can be understood as part of the component names.

[0070] Furthermore, it should be noted that in the description of this specification, the terms "one embodiment," "some embodiments," "embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0071] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the claims should be interpreted to include both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0072] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, then this invention should also include these modifications and variations.

Claims

1. A control cycle scheduling method, characterized in that, The foreground / background systems and real-time operating system are all located in the controller, and the control cycle scheduling method includes: S1. The front-end and back-end systems receive data from the input module connected to the controller and perform sequential logic execution processing on the data of the input module until the data of the input module is processed and the corresponding execution result is obtained. S2. Perform context switching processing on the foreground / background system and the real-time operating system to enable the controller to switch from the foreground / background system to the real-time operating system. S3. The real-time operating system processes user program tasks until a preset time period is reached; S4. Perform context switching processing on the real-time operating system and the foreground / background system to enable the controller to switch from the real-time operating system to the foreground / background system. S5. The front-end and back-end system outputs the execution processing result to the output module connected to the controller. S1 includes: The front-end and back-end systems receive data from the input module based on the front-end interrupt routine. The front-end and back-end systems perform sequential logical execution processing on the data of the input module based on the back-end program until the processing is completed and the corresponding execution results are obtained. The context switching process for the foreground / background system and the real-time operating system in S2 specifically includes: Save the context of the foreground and background systems to the foreground and background stacks, and then restore the user program task context from the task stack in the real-time operating system. S3 includes: The real-time operating system uses a time-slice round-robin scheduling method to process user program tasks until the processing time of the user program tasks reaches a preset time period.

2. The method according to claim 1, characterized in that, The real-time operating system uses a time-slice round-robin scheduling method to process user program tasks until the processing time of the user program task reaches a preset time period, specifically including: The real-time operating system performs time-slice processing on the program span of each user program task, obtains the program span time segment corresponding to each user program task, and queries and schedules the processing of the program span time segment corresponding to each user program task until the processing time of the user program task reaches the preset time period and then exits the scheduling.

3. The method according to claim 2, characterized in that, S4 performs context switching processing for the real-time operating system and the foreground / background system, specifically including: First, the context of the user program task in the real-time operating system is saved to the task stack in the real-time operating system, and then the context of the foreground and background systems is restored from the foreground and background stacks.

4. The method according to claim 3, characterized in that, S5 specifically includes: The foreground and background systems output the execution results to the output module connected to the controller based on the foreground interrupt program.

5. The method according to claim 1, characterized in that, The input module includes AI data and / or DI data.

6. The method according to claim 5, characterized in that, The user program tasks are pre-stored in the controller's memory.

7. A controller, characterized in that, After being connected to the input module and the output module, the controller executes any of the control cycle scheduling methods described in claims 1-6.

Citation Information

Patent Citations

  • Method for realizing multiple operation system synergistic working

    CN101051282A

  • M2 microprocessor-based thread scheduling method and system and computer storage medium

    CN113515359A

  • Graded task switching method based on PowerPC processor structure

    CN1490722A