Implementation and Application of Time Slice Round Robin Scheduling in Microcontroller C8051F020

Publisher:炫酷骑士Latest update time:2012-02-27 Source: 现代电子技术 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the field of microcomputer control, most systems are real-time control systems. Real-time means timely response to and processing of randomly occurring external events. In order to better complete the acquisition, processing, storage of real-time data and the corresponding various real-time control operations, the two factors of real-time and multi-task parallelism must be considered at the same time. It is necessary to ensure that the system responds to and processes external events at a fast enough speed, and can execute multiple tasks in parallel at a macro level. Real-time multi-task systems rely on appropriate task scheduling methods to determine which task in the system can obtain the CPU and other system resources, and which task temporarily exits the running state, so as to achieve the purpose of real-time processing of multiple tasks. The time slice round-robin algorithm is a common algorithm for implementing multi-task scheduling. In this algorithm, if a time slice is assigned to a task, then within this time slice, this task obtains the CPU and runs, and then the CPU is assigned to another task when the next time slice arrives. In this way, concurrent tasks run alternately at the micro level and execute in parallel at the macro level.

1 Implementation of real-time multitasking mechanism

In real-time control systems, multiple real-time tasks are allowed to be executed in parallel. In some measurement and control systems, there are multiple tasks such as data acquisition, port detection, analog output, switch output data processing and storage. In a single-chip microcomputer, the following effect should be achieved: at the micro level, only one task can be run at a time, but at the macro level, these tasks are run simultaneously.

Real-time tasks are implemented through time-sharing processing, which is equivalent to processes in the operating system. Each task has three states, namely, running state, ready state and waiting state. Once a task is established, it is in one of these three states. A task in the running state monopolizes the CPU and some other resources; the ready state means that the task has obtained all the required resources except the processor, and the operating conditions are met, but it cannot run because of the lack of CPU; the waiting state means that a task is temporarily stopped while waiting for an event (such as information from other tasks, waiting for a certain system resource, etc.). The transition between the three states is completed through effective task scheduling. The quality of the task scheduling algorithm in a real-time multi-task system is directly related to the real-time and parallel performance of the system.

The time slice rotation method is a method of scheduling all ready tasks in turn according to the switching of a certain time slice: the CPU's running time is divided into many small time slices, which are assigned to different tasks by the scheduler in a certain order. Each task accesses the CPU in its own time slice. Interrupts enable the system to respond to external information in real time and act as the driving force for time slice switching. Considering that different tasks have different real-time requirements and cannot be divided uniformly, we take the smallest time slice as the benchmark, and other time slices are its multiples, which improves the resource utilization of the system.

In this scheduling algorithm, the selection of time slices is very important, and usually factors such as the number of tasks to be completed, the different real-time requirements of each task, and the processing capacity of the system must be considered.

2 Application of time slice round-robin scheduling in train brake friction coefficient test system
2.1 System analysis

To simulate the train braking process and complete the test of the friction coefficient of the train brake pad, the following steps need to be implemented:

(1) Use the analog output port to output a 0~10 V voltage as the frequency setting value of the inverter, so that the inverter controls the motor to gradually increase the wheel speed according to the acceleration time, and reach the set speed according to the acceleration time.
(2) According to the comparison between the set air pressure and the actual air pressure, decide whether to exhaust or inlet, and perform the corresponding opening/closing of the air intake valve or the air outlet valve to make the air pressure reach the set value. Before testing, the air pressure state should be continuously checked to keep the air pressure stable.
(3) When the test button is pressed, open the pressurization valve and start braking. Because the braking inertia of the train is to be simulated, the motor cannot stop immediately. Therefore, while pressurizing, the inverter controls the motor to gradually decelerate. The system drops to 0 according to the deceleration time. During this deceleration and braking process, the data collected and smoothed from the force sensor is recorded and put into the specified variable area. [page]

In order to ensure the real-time response of tasks and realize the simultaneous execution of multiple tasks at a macro level, we adopt a time slice round-robin scheduling algorithm and divide different time slices based on the different real-time requirements of different tasks and the minimum time slice. The test system needs to realize operations such as data acquisition, analog output, and switch output/reading. The specific tasks corresponding to these operations and their real-time requirements are shown in Table 1.

Real-time requirements for the same tasks are at the same level, and state variables are used to distinguish whether the task is in a ready state or a waiting state, thereby deciding whether to allocate a time slice.

2.2 Selection of time slices

In the time slice round-robin algorithm, the size of the time slice has a great impact on system performance. If the time slice is too large, so large that every task can be completed within the time slice, the time slice round-robin scheduling algorithm loses its meaning and may delay some tasks with strong real-time requirements; if the time slice is too small, some tasks will not be able to respond in time. From the above analysis, it can be seen that in this test system, the benchmark time slice to be selected is 1 ms, and other time slices are multiples of it.

3 Software Design and Implementation
3.1 Software Design

The division of time slices for each subtask is completed by the system clock, and the system scheduler assigns it to each subtask. The system uses its built-in timer to complete this work, and the timing frequency is designed to be an integer multiple of the execution frequency required by each subtask.

Using CYGNAL's C8051F020 microcontroller, the system clock selects f=11.059 2 MHz; using timer interrupts and counting to implement time slices:

 [page]
The real-time requirement of the main test task is 10 ms. 10 ms is divided into 10 blocks, and the execution time of a task is 1 ms. Then every 10 ms, a specific task will be scheduled once, and within this 10 ms, 10 tasks can be executed alternately, which not only meets the real-time requirements, but also realizes multi-task operation. Its scheduling structure is as follows:

Some tasks are based on the completion of other tasks. For example, before the speed reaches the set value, the test operation cannot be performed, and the deceleration task cannot be executed, so the task is in a waiting state. Tasks must be loaded dynamically according to the state of the task.

During the test, the DA value is output once every 10 ms. Each time slice is executed, the number is counted. When n is counted, the DA value increases by 25, that is, with n×10 ms as a cycle, the DA value increases once, so that the inverter controls the motor speed to rise uniformly. The same is true for the decline process. In this way, it can not only ensure that the DA value rises/falls uniformly, but also accurately control the rise and fall time according to the maximum DA value (10 V output corresponds to a DA value of 4,000) and the DA value that falls within each n time slice cycle, and divide the large task into small tasks for execution, thereby improving the utilization rate of system resources and real-time performance.

3.2 Implementation of the test system

The lower computer uses the time slice round-robin scheduling method to realize the real-time multi-task system. The upper computer uses the virtual instrument development platform LabVIEW to realize the human-machine interface, communicates with the lower computer through the ModBUS protocol, writes each setting parameter in the specified data area, performs the test, and stores the test results in the specified data area. After obtaining the data, the friction coefficient is converted by the formula. During the deceleration process, each unit speed (km/h) corresponds to an instantaneous value of the friction coefficient. The obtained curve is shown in Figure 1.

4 Conclusion

For real-time multitasking operating systems, the main task is to respond promptly to various tasks with different real-time requirements.

The introduction of the task allocation method of time-slice round-robin scheduling in the single-chip microcomputer effectively improves the structure of the system. The system can execute various tasks in parallel on a macro level, further improving resource utilization; and enables it to respond within a strict time limit when an event occurs, thus realizing a real-time multi-task measurement and control system.

References

[1] Ma Zhongmei, Ji Shunxin, Zhang Kai, et al. C language application design for single-chip microcomputer [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2001.
[2] Xu Shiliang, Zhu Mingfang. Fundamentals of software application technology [M]. Beijing: Tsinghua University Press, 2000.
[3] Pang Liping. Principles of operating system [M]. Wuhan: Huazhong University of Science and Technology Press, 1987.
[4] Li Gang, Lin Ling. High-performance and high-speed single-chip microcomputer C8051FXXX series compatible with 8051 [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.

Reference address:Implementation and Application of Time Slice Round Robin Scheduling in Microcontroller C8051F020

Previous article:In the application of programmable measurement and control network design
Next article:Design and implementation of a frequency coded keyboard

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号