Introduction
Electronic control systems are generally real-time systems that often need to process input data streams of many concurrent events. The arrival order and probability of these events are usually unpredictable, and the system must respond accordingly within a pre-set time limit [1].
For how to control the complex behavior of the system, the event-triggered scheme is generally adopted, that is, all the behaviors of the system are executed in response to external events of the system. However, interrupt loss and the overhead of the event-triggered system are often overlooked. Reference [2] discusses such an example: an event-triggered system containing 27 tasks and using the RM scheduling algorithm has an actual CPU utilization rate of only 18%. At the same time, the electronic control system can also be regarded as a real-time system that can collect a set of defined input values in real time and give a correct output at a predetermined time interval. In order to meet the stringent requirements of safety, low cost and as simple a program as possible, the development of electronic control systems eventually moves towards a time-triggered structure [1]. Time triggering means that all actions related to input sampling, calculation and output results are executed before a pre-given time, thus ensuring accurate scheduling time.
1 Task Scheduler of Time-Triggered System
Scheduler is an operating environment for electronic control systems, and can also be seen as a simple operating system. Using schedulers in electronic control systems can shorten development time and improve the modularity of software. Schedulers have two forms: cooperative and preemptive. If a "woken up" high-priority task can interrupt other running low-priority tasks, the scheduler is preemptive; otherwise, it is cooperative. Due to the particularity of its application background, most of the tasks running in electronic control systems are periodic tasks (such as periodic data acquisition tasks, LED display refresh tasks, etc.), and the task's ready time, start time, execution time and deadline information can be known in advance. Therefore, a cooperative scheduler based on time triggering can be used, that is, tasks are scheduled in a periodic or one-time manner at a specific time.
2 Mechanism of Time-Triggered Cooperative Scheduler
Time-triggered cooperative scheduler is usually implemented through a hardware timer. All tasks are triggered by time, which also means that there are no other forms of interrupts except timer interrupts. The hardware timer will be set to generate a periodic interrupt signal with a frequency of about 1kHz.
The main function of the time-triggered cooperative scheduler is to wake up the task to be executed at a predetermined time. During working hours, the scheduler checks the static task list and determines whether there is a task to be executed based on the task cycle. If there is, the task is executed immediately; after the task is executed, the task list is continued to be checked, and the previous process is repeated. After completing the list check, the CPU enters a dormant state due to energy saving until the next clock beat arrives. Its task scheduling mechanism is shown in Figure 1. Since the cooperative scheduler can ensure that only one task is triggered in the system at the same time, and it can be guaranteed that there are tasks executing in the system at any time, the system's utilization efficiency is improved. In a distributed system, there is time drift between nodes (due to differences in the environment in which each node is located and the manufacturing process of the clock crystal oscillator, etc.), so the node clock must be dynamically adjusted to synchronize the clocks of each node in the entire system.
The main reason why cooperative schedulers are reliable and predictable is that only one task is active at any time. This task runs until it is completed and then the scheduler takes control. If preemptive scheduling is used, there are multiple active tasks, and the execution of "context switching" and "critical section protection" will increase the system overhead. Figure 2 [3] compares the use of cooperative schedulers and preemptive schedulers to design cruise systems. It can be seen that the use of cooperative scheduling mode can reduce the number of lines of code required and save program memory and data memory space. At the same time, many studies have shown that in addition to the much faster task-level response time, cooperative schedulers have many advantages over preemptive schedulers. For example, literature [4] points out that compared with preemptive alternatives, cooperative scheduling has the following four advantages: simplicity, reduced system overhead, easy testing, and easier for authorities to accept this form of scheduling. 3 Application Examples The solar tracking system is designed for applications such as solar air conditioning, high-efficiency solar photovoltaic power generation, and high-efficiency solar water heaters that require real-time tracking of the sun. By keeping one side of the device perpendicular to the sun at all times, the maximum solar energy can be obtained. The tracking system involved in this article adopts a mode that combines sensor tracking with astronomical positioning tracking. That is, the sunrise and sunset times are calculated through the local longitude and latitude and the current date, and then a pulse is output at regular intervals to control the device to automatically move westward according to the time difference between sunset and sunrise and the step angle of the motor. At the same time, according to the input of the photoelectric sensor, the motor is controlled to automatically adjust the device in the four directions of east, west, south and north at regular intervals to keep the device perpendicular to the sunlight. Figure 3 shows the context diagram of the solar tracker and gives a simple description of the system interface with sensors and actuators. It can be seen from Figure 3 that the tasks, task cycles and execution times required to realize the system functions are listed in Table 1.
Among the tasks listed in Table 1, Task2 performs a keyboard scan every 120 ms to set the current time, longitude and latitude, and save the input of the manual adjustment device. Task6 adjusts the device orientation according to the input of the manual adjustment device and the input of the photoelectric sensor. Task7 calculates the sunrise and sunset times. Task3, Task4, Task5 and Task6 are executed once every 24 hours. The switch_case structure is used. If it is not within the running time range, the program will jump out directly, otherwise the corresponding task will be executed. Task8 takes effect when the sunset time is reached or the device touches the west limiter to control the motor to align the device with the rising position of the sun.
According to the principle of cooperative scheduler and the cycle of each task, the timer is set to generate a periodic interrupt signal every 4 ms. Because the execution time of multiple tasks exceeds 4 ms, Task1 cannot be executed at the specified frequency. In addition, the worst execution time of multiple tasks exceeds 30 ms, which affects the sensitivity of keyboard scanning. Therefore, the method of directly including Task1 and Task2 into the timer interrupt service subroutine is adopted, so that the cycle and execution time of all tasks can meet the requirements of system task schedulability.
Conclusion
The use of event-triggered mode in engineering will greatly increase the complexity of the system, resulting in a huge code structure. Such code length and complexity are not suitable for ordinary developers to build, and commercial real-time operating systems are often expensive and require a large operating system overhead. The development of systems based on time-triggered mode can meet engineering requirements such as real-time, simplicity, and predictability. It can also be seen in application examples that for tasks with a large difference between task cycle and execution time, in order to meet the requirements of schedulability, the method of adding short tasks that need to be executed frequently to the timer interrupt service subroutine prolongs the interrupt processing time and weakens the system's real-time response capability and predictability. In addition, the task schedulability can also be met by decomposing tasks with long execution time into several tasks with short execution time. Compared with the event-triggered mode, the time-triggered mode has higher requirements for engineering and technical personnel.
Previous article:Design of an Embedded Dual-computer Fault-tolerant Real-time System
Next article:Research on Several Commonly Used Single Chip Microcomputer System RAM Testing Methods
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- How does AD software collect company information?
- [GD32L233C-START Review] 11. GD32 ISP software does not support GD32L233 yet
- Last day! Answer questions to win prizes! Practical sharing | Design a reliable switching power supply from scratch
- How to detect whether the switching power supply transformer is good or bad?
- micropython update: 2021.4
- The battery voltage is pulled down
- Is there any abnormal sound from the common mode inductor?
- There's a problem with the project
- bq27411-g1 (single-cell fuel gauge) bq27541 (single-cell fuel gauge) bq27546-g1 (single-cell fuel gauge)
- Playing with circuits (2) - Killing LM5175