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.
Previous article:In the application of programmable measurement and control network design
Next article:Design and implementation of a frequency coded keyboard
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Application of Field Effect Transistor
- What is overshoot? How to solve the problem of overshoot in high-speed circuit signals
- Where can I find the development environment for the domestically produced aerospace-grade CPU of the BM3803MGRH model?
- What is the difference between using * and ? in the day of the week in cron expressions? I checked some information but it's not clear.
- GD32E231 DIY Contest Brushless Motor Driver
- FAQ Power Management, Battery Management
- Together wow: Smart soldering iron based on domestic chip, portable soldering iron system IronOS (FreeRTOS)
- How to add code to ardunio ide
- Blackboard with 24 touch keys, 9 customizable LEDs
- TI DLP Pico micro-projection technology makes smart speakers more powerful