As the main control unit of the embedded system-single-chip microcomputer, its software is often a micro real-time operating system, and most of them are specially designed for a certain application. The system program is capable of real-time process control or real-time information processing. It must be able to respond to random external events in a timely manner and quickly process the events. However, the time-sharing operating system divides the CPU time into a time interval that is basically the same as the growth period, that is, the "time slice". Through the management of the operating system, these time slices are distributed to each user in turn. If the entire task is not completed before the time slice ends, the job will be paused and the CPU will be abandoned, waiting for the next cycle to continue. In this case, the CPU is allocated to another job. Because the processing speed of the computer is very fast, as long as the time slice is obtained at an appropriate interval, a user job will pause from the time slice allocated to it to the next CPU time slice "; however, the user is unaware that the entire system is "exclusive. The time-sharing operating system has the following three features: ① multi-channel. You can use a system at the same time through their respective terminals. ② Timeliness. The various requirements put forward by the user can be responded to and processed in a short or tolerable time. ③ Dedicated. In a time-sharing system, although multiple users are allowed to use one CPU at the same time, operations between users are independent and do not interfere with each other.
The time-sharing operating system is mainly proposed for computers of minicomputers and above. Generally, for a general-purpose computer driven by a microprocessor (MPU), system designers do not know the final application of each processor. Therefore, when the price permits, the hardware design ensures that the CPU clock is as fast as possible; the computing and management capabilities are as strong as possible; the capacity of programs and data storage is as large as possible; and various computer peripherals are as detailed as possible, in particular, machines that use a time-sharing operating system have higher requirements because they are a management system with multiple users. Comparatively speaking, a microcontroller (MCU) is a single-chip integrated system that combines the peripherals required by these or those computers, such as programs and data storage, ports, and related subsystems are integrated into a chip. In terms of hardware, the single-chip microcomputer system and the computer system using the time-sharing operating system are incomparable. However, in the design of the single-chip microcomputer system, the designers have a clear understanding of its specific application, and its use environment is relatively single and fixed. The predictability of the controlled process provides the possibility for the realization of the time-sharing system idea. Specifically, although the CPU speed of a single-chip microcomputer is low, its tasks are predictable. In this way, Job Scheduling becomes simple without occupying a lot of CPU time, at the same time, the "time slice" design is specific and targeted, so it can be quite effective.
I. Design of time-sharing system for Single Chip Microcomputer
The single-chip microcomputer system is usually an embedded control system. Therefore, most single-chip microcomputer systems are real-time systems. What truly embodies the design philosophy of the time-sharing system is usually the multiple-channel repetitive detection control system. Even in these multi-channel repetitive detection control systems, its real-time performance is also very important. That is to say, the time-sharing system design concept is applied in the single-chip microcomputer system, but its timeliness should be considered first.
1. Suggestions on the hardware design of the time-sharing system for Single-Chip Microcomputer
With the improvement of single chip microcomputer performance, some hardware functions in the design of single chip microcomputer system become the trend of the times. At the same time, however, the chip technology is also possible for low-cost hardware to complete high-performance features. Whether a function is implemented through hardware or software cannot be generalized. It is only through system design that the performance-to-price ratio of the entire system is the goal pursued by each single-chip microcomputer system designer.
In the hardware design of single-chip time-sharing system, the requirements for system timeliness cannot be reduced, while the processing speed of most single-chip computers is relatively slow. Therefore, the design of interface hardware should adopt some devices that can retain the information, such as triggers and latches. At the same time, these devices must be output in a three-state gate, because they are a multi-channel time-sharing system. When the CPU is not accessed, the output of the device is high-impedance, which facilitates the access of the bus to other devices. In addition, some time-consuming operations on software should be transferred to hardware for completion. For led dynamic display, there is no need to use intel 8155 or Intel 8255 hardware interfaces to make the software suffer from time to display numbers, you can use Intel 8279, max7218, and max7219 programmable peripheral devices to make the display both beautiful and simple. Of course, the specific design should be based on the system's specific design for the hardware and software. In short, we should consider the pursuit of the highest performance-price ratio.
2. Software Design of time-sharing system for Single Chip Microcomputer
A sound scheduling mechanism is required to reasonably implement the time-sharing system of single-chip microcomputer. A complete scheduling mechanism consists of scheduling pointers and scheduling tables. The scheduling of the system is divided into two levels. One is the "path" scheduling, which is equivalent to directing the program to perform horizontally: from a first job to a second job, from a second job to a third job ...... From the last to the first, the cycle repeats. The change rule of the "path" scheduling pointer is fixed, and the algorithm is simple, that is, increasing or decreasing by one, and then returning to the start after the loop is reached. The corresponding "path" scheduling pointer should also construct the "path" scheduling table. Each item in the "path" scheduling table represents the entry address and jump instruction of each "path" program. Taking MCS-51 single-chip microcomputer as an example, using ajmp addr11 as the content of each item, each table item of the scheduling table occupies 2 bytes; when the program is longer than 2 K bytes, ljmp addr16 is used as the content of each item, which occupies three bytes. The number of "Routes" in the single-chip microcomputer system and the number of items in the scheduling table. The second is job scheduling, which is equivalent to directing the program to perform vertical operations: From the first job of a channel to the second job, and the second job to the fourth job ...... The sixth job also refers to the third job. Because the flow of a slightly complex task cannot be a single direction, the flow from the previous job to the next job must be determined based on the system detection or calculation results, therefore, changes in Job Scheduling pointers are randomly determined. The job scheduling table is in the same form as the "path" scheduling table. Each item represents the program entry address and jump instruction of each job module. The job scheduling table indicates the general sequence of execution of each job. The number of table items is equal to the maximum number of jobs in a single job. To identify each task process, the single-chip microcomputer system must control the number of Job Scheduling pointers and corresponding job scheduling tables. The above two pointers are all 1-byte integer variables. The connection between the scheduling pointer and the scheduling table is implemented through the command JMP @ A + dptr. Dptr is the first address of the scheduling table. The content in accumulators A is an integer multiple of the scheduling pointer. If the table item content is ajmp addr11, the value of a is the scheduling pointer multiplied by 2. If the table item content is ljmp addr16, then the value of A is the scheduling pointer multiplied by 3.
In addition to the scheduling design of the above main program, the common functions of each job should be implemented in the interrupt mode, mainly in the timer interrupt mode. For example, the timing function should be implemented in the timer interrupt. The timing parameter should be selected taking into account the various timing requirements in various operations of the system. The timing frequency is generally an integer multiple of the minimum timing frequency. Any software latency is not allowed. The key to implementing time-sharing control is to reasonably break down the functions of the system into various job modules. The finer the job module, the better the real-time performance of the system. Although the clock frequency of a single-chip microcomputer is low, the real-time performance of the time-sharing system can be guaranteed when each module is subdivided into various "actions" and simple operations in actual application. The disadvantage is that the control and processing procedures of each "road" are broken down, and modularization is not guaranteed.
II. Application Instances
1. system hardware and working principles
In the VOD (Video On Demand) system for a hotel, the upstream signals sent from the fixed boxes of each machine are transmitted using DTMF code over a telephone line to the upstream signal acquisition card in the main control cabinet of the data center. In order to receive on-demand operations by multiple users at the same time, the uplink signal acquisition card must have the function of receiving multiple telephone transmission information. Therefore, the author designs eight telephone acquisition cards, 8-channel user on-demand operations are acceptable at the same time, as shown in figure 1 of the system hardware.
Figure 1 telephone acquisition card hardware Diagram
The main program for each line is: after the ringing signal is detected (that is, after the ringing detection pin is reduced and maintained for more than 8 ms), the relay is sucked together, at the same time, set the box to return the one-on-one signal -- # key (keep 400 ms ). Then, wait for the fixed box to send the on-demand information: room number and on-demand program number, with a total of four DTMF codes; if no DTMF code is received within 1 s (the DV foot of the decoder chip is increased), the operation is incorrect, the relay is disconnected, the status bit is restored, and the job pointer is returned to 0. After receiving the 4-bit DTMF code, sort it out and carry the mark of this path, convert it into 3 bytes, send it to the serial sending buffer, and send it in the timer interrupt service program. Wait for the video server to send a response message. Different messages are sent back to the machine's fixed Box Based on different response information. If no response is received upon timeout, a code is sent back to the machine's fixed box (the sending time is 100 ms ). Finally, the relay is disconnected, the status mark is restored, the buffer is cleared by 0, and the job pointer is returned to 0. A process is completed.
2. Job Flow
In order to achieve 8 time-based work, the main task is to divide the process into jobs. The author divides it into eight jobs by design, as shown in process 2 of each job. After each job returns, the path pointer is automatically added with 1 and returns to 0 after 8 to ensure reasonable time-based work.
Figure 2 processes
3. Tips
In programming 8-way telephone information acquisition card, in order to make the program more refined, the author applies the following three skills:
① Because the 8-way work is the same, the program can be shared, and only one "-Way" address table must be constructed, each table item contains its own input lock address, output lock address, DTMF code storage RAM address, and timing unit address. In this way, the "path" scheduling table can be saved because the entry addresses of the same jobs are the same. Depending on the path pointer, you can use the same program to control each of the eight paths.
② The timer interruption is set to 4 Ms once. This is because the telephone ringing frequency is 25Hz and the detection pin remains low for 10 ms, which is the lowest time value. It can be considered as interference when the low-level hold time of the zhenling detection pin is less than 8 ms. Each path has its own timer unit. After each timer is interrupted, each timer Unit automatically adds 1 in the timer Service self-program. In the previous job, set the timer unit to 0. In the next job, read the value of the timer unit. The latency value is multiplied by 4 ms. In this way, no latency will occupy the CPU.
③ Serial data is sent and received in a total of eight ways, using a common module. Data links are implemented by opening up the buffer zone, including the sending buffer zone and the receiving buffer zone, with a baud rate of 4800baud. Generally, when sending the serial data of a program, it is necessary to detect the Ti-bit changes to determine whether the 1-byte data transmission is complete, thus determining whether the next byte data can be sent. It is not feasible to apply to the time-sharing system, which occupies the CPU. Because the baud rate of 4800baud is adopted, the sending time of each byte is less than 4 ms. When the sending buffer has data, it can be sent from the program in the timer interrupt service. One byte of data is sent during each scheduled interruption. When a scheduled interruption occurs, the previous byte of data must have been sent and the next byte of data can be sent. When Ti-bit detection is not required or the CPU is not used. Data reception is interrupted in a serial mode. The received data is stored in the receiving buffer for various queries.
Conclusion
This paper introduces the thought of time-sharing operating system into the single-chip microcomputer system, and proposes a software programming of Single-chip Microcomputer System for Multi-channel detection control. This greatly reduces the system design cost, increases the system performance and price ratio, and achieves success in practical applications.