introduction
An embedded system is a special-purpose computer system that is application-centric, based on computer technology, and whose software and hardware can be tailored to meet the strict requirements of the application system on functions, size, cost, reliability, and power consumption. An embedded system is application-oriented, and the system's hardware selection and software development model must be determined based on the specific application.
Permanent magnet brushless DC motor is one of the hot spots in the field of motor control research, which is closely related to its inherent technical advantages: electronic commutation replaces the mechanical commutation of brushed DC motor. It fundamentally eliminates a series of problems such as sparks, noise, and high failure rate caused by brush commutation of ordinary brushed DC motors, while making the performance of the system comparable to that of ordinary brushed DC motors, so it has been widely used. The electronic commutation of permanent magnet brushless DC motors is inseparable from the rotor position signal of the motor. The traditional method is to use Hall devices or other position sensors to detect the position signal, which makes the maintenance and manufacturing of the system inconvenient, and due to the unstable working characteristics of the sensor, it brings some hidden dangers to the safe operation of the system. Therefore, the position sensorless solution has aroused great interest.
This paper combines the development of a sensorless permanent magnet brushless DC motor control system, uses Microchip's PIC18F452 microcontroller as the main control device, and uses the embedded real-time operating system μC/OS-II as the software development platform, and discusses in detail the development model and process of the embedded system.
2. System hardware platform design
The first step in embedded system design is to combine specific applications, comprehensively consider the system's requirements for cost, performance, scalability, development cycle, etc., determine the system's main control device, and build the system hardware platform with it as the core.
The key issue of the position sensorless permanent magnet brushless DC motor control system is position detection. There are many position detection schemes available, among which the back-EMF method is widely used due to its simplicity and practicality. The principle of the back-EMF method is: based on the three-phase terminal voltage of the motor, the three-phase back-EMF zero-crossing signal is obtained through hardware detection circuit or software algorithm, and then the software phase shift is used to obtain the commutation moment, and the commutation is completed according to the commutation logic at the commutation moment, triggering the inverter bridge to work with the appropriate conduction timing, thereby ensuring the normal operation of the motor.
The sensorless control of permanent magnet brushless DC motors based on the back-EMF method places higher demands on the system hardware:
① Three external interrupt input pins, convenient for capturing the three-phase back electromotive force zero-crossing signal;
② At least one PWM module to realize the chopper speed regulation of the motor;
③ Rich timer resources to complete software phase shifting, speed measurement and other functions;
④ Multi-channel AD conversion module, capable of sampling speed setting and current and voltage signals of the main circuit;
⑤ Hardware multiplier to ensure the rapidity of speed and current regulator;
⑥ Sufficient program and data storage to facilitate system expansion;
⑦ High-speed system operating frequency ensures strong real-time performance of the system;
⑧ Rich communication modules facilitate the interconnection between the system and other embedded systems.
There are many special chips available for the design of sensorless permanent magnet brushless DC motor control system, but in order to further improve system performance and enhance design flexibility, smart devices such as DSP or special microcontrollers are often used. However, while improving system performance, this increases system development costs. In order to design a high-performance, low-cost development platform, the PIC18F452 microcontroller is selected as the main control device based on the application's requirements for system hardware and considering its high cost-effectiveness.
PIC18F452 is an enhanced 8-bit microcontroller launched by Microchip. It adopts a reduced instruction set (RISC) design, has a two-stage pipeline, and can run at a maximum frequency of 10MIPS, which can meet the system's real-time requirements; the instruction bus is 16 bits wide and the data bus is 8 bits wide; the microcontroller has 32K bytes of FLASH program memory, 1.5K bytes of data memory and 256 bytes of EEPROM, which is convenient for system expansion; it has a built-in 8×8 hardware multiplier; it has rich interrupt resources, provides 18 interrupt sources, two interrupt priorities, and the interrupt priority is configurable. The PIC18F452 microcontroller is equipped with a wealth of peripheral modules, which greatly simplifies the design of the microcontroller's peripheral circuits. At the same time, Microchip provides a powerful instruction set for the PIC18F series microcontrollers, with a total of 77 instructions. Most of the instructions are stored in single words (2 bytes) and executed in a single cycle. The storage compression rate of the application code is high and the instruction execution efficiency is high. [page]
The system hardware block diagram with PIC18F452 as the main control device is shown in Figure 1.
It is worth mentioning that:
① The commutation logic in the system is completed by programmable logic devices, mainly to improve the reliability of the system. Functionally speaking, it can be completely realized by a single-chip microcomputer;
② The speed detection of the motor can be calculated by software based on the position signal, so the speed sensor is omitted;
③ The analog input is the speed setting signal of the motor.
3. Embedded system software development model
For simple application systems, the system's software development model is usually as shown in Figure 2, which is called the front-end and back-end system (also called an infinite loop system).
In the foreground and background systems, the application is an infinite loop. Functions are called in the loop to complete corresponding operations, which are called background tasks; the interrupt service program handles asynchronous events, which is called the foreground behavior. Because the information provided by the interrupt service program is not processed until the background program runs to process the information, the task response time in the worst case is equal to the execution time of the entire loop. Because the execution cycle of the background loop is not a constant, the application software development based on the foreground and background mode, although the design process is simple, the real-time performance of the system cannot be guaranteed.
In order to improve the real-time performance of the system, a software development model based on an embedded real-time operating system (RTOS) can be adopted. RTOS is divided into two categories: non-preemptive kernel and preemptive kernel. Generally, commercially available kernels are preemptive kernels, so this article only discusses this type of RTOS. Its kernel structure is shown in Figure 3. [page]
RTOS divides the entire application into multiple tasks. Each task completes a specific function and is given a certain priority. It has its own task control block and stack space. Generally, each task is an infinite loop in the program structure. It has multiple states - sleep state, ready state, running state, suspended state and interrupt state. The system kernel always lets the high-priority task in the ready state run first. The interrupt service program can preempt the CPU. When the interrupt service program is completed, the system kernel lets the task with the highest priority in the ready state run (not necessarily the interrupted task). It can be seen that the software development model based on RTOS optimizes the task response time of the system. More importantly, this development model transforms the previous function-oriented application development into task-oriented application development, simplifying the logical structure of the system design; at the same time, due to the RTOS, the visibility of the application software to the underlying hardware is shielded, and the previous two-layer structure of the software system is transformed into a three-layer structure (as shown in Figure 4), which greatly facilitates the software expansion and hardware upgrade of the system.
For PIC18F series microcontrollers, the commonly used embedded real-time operating systems are: μC/OS-II, Salvo, CMX, PIC18OS, etc. They are all preemptive real-time kernels, and the detailed comparison is shown in Table 1.
Table 1 Several embedded real-time operating systems suitable for PIC18F series microcontrollers
Combined with the specific application of this article, taking into account the system hardware resources and the characteristics of the above-mentioned real-time operating systems, the software development model based on the operating system was finally selected, and μC/OS-II was selected as the system software platform. [page]
4. Application software development based on μC/OS-II
μC/OS-II is a portable, curable, customizable and preemptible multi-tasking real-time kernel. When developing applications, it is necessary to first complete its porting to specific hardware. μC/OS-II was fully considered for portability during its writing process. Most of its code is written in ANSI C. The processor-related code is concentrated in the three files OS_CPU.H, OS_CPU_A.ASM, and OS_CPU_C.C. Therefore, as long as these files are rewritten for specific hardware, the porting work can be completed.
After the transplantation is successful, you can start writing the application. RTOS transforms function-oriented application development into task-oriented application development. Therefore, the software development process is to subdivide the application system into multiple tasks according to the function, then implement each task and determine the appropriate priority for the task; for operations with high real-time requirements, it is necessary to write related interrupt service programs.
The basic condition for the normal operation of permanent magnet brushless DC motor is: commutation at the best commutation time according to the best commutation logic. This process has high requirements for real-time performance, so it is completed by the interrupt service program. When the back EMF crosses zero, the program enters the back EMF zero-crossing interrupt service program, which sets the overflow value of the software phase shift timer according to the current motor speed; when the software phase shift timer overflows the interrupt, the program enters the phase shift timer interrupt service program. Obviously, this is the best commutation time. Therefore, completing the commutation according to the best commutation logic in the phase shift timer interrupt service program can ensure the normal operation of the motor. In addition, the handling of emergency faults such as overcurrent, overvoltage, and undervoltage must also be completed by the corresponding interrupt service program. The system also needs to complete the following functions: set the timing sampling speed, and convert the sampling results into the duty cycle of the PWM wave through the regulator; respond to keyboard input; display the system status information such as the motor speed and PWM wave duty cycle; communicate with the upper PC serial port; handle non-emergency faults of the system, etc. These functions do not have high requirements for real-time performance, so they are completed by the task level. The tasks of the application system are shown in Table 2.
Table 2 Application system task list
When the system is running, it first performs system initialization operations and creates tasks. All newly created tasks are set to the ready state, and the operating system kernel first calls the task with the highest priority in the ready state to run. During the operation of the system, it is always ensured that the priority of the running task is higher than that of all tasks in the ready state. When a running task is suspended due to waiting for an event or delay, or a task with a higher priority enters the ready state, the kernel terminates the currently running task and gives the right to use the CPU to the task with the highest priority in the ready state. When an interrupt occurs, the system runs the interrupt service program. When the interrupt returns, the system kernel will perform task scheduling and convert the highest priority ready state task to the running state. For example, during the operation of the system, an AD sampling completion interrupt occurs, and the program enters the AD sampling completion interrupt service program; the interrupt service program sends the AD sampling result to the mailbox ADResult. Since the task TaskAD was previously suspended due to waiting for the mailbox ADResult, the state of the task TaskAD is changed to the ready state at this time; when the interrupt returns, the kernel performs task scheduling. Since TaskAD is the highest priority task in the ready state (the TaskErr task is always in the suspended state when the system is running normally), the system will run the task TaskAD regardless of the task that was originally interrupted, which ensures that the task TaskAD has a sufficiently fast task response speed. After TaskAD executes a cycle, it is changed to the suspended state due to waiting for the mailbox ADResult. The kernel performs task scheduling again and calls the highest priority task in the ready state to run.
5. Conclusion
This paper combines the design of the control system of permanent magnet brushless DC motor without position sensor, and determines the development scheme with PIC18F452 microcontroller as the main control device and μC/OS-II as the software platform according to the specific requirements of the system. The actual development process proves that this development mode can meet the design requirements of high performance and low cost of the system, and at the same time has strong scalability and certain technical foresight.
It is worth noting that the use of RTOS in embedded systems enhances the real-time performance of the system and simplifies the system software design; at the same time, it also increases the development cost of the system. On the one hand, the operating system itself will consume certain hardware resources (such as program memory, data memory, timer resources, etc.), which increases the hardware cost of the system; on the other hand, if you purchase a commercial real-time operating system, additional software expenditures are required. Even if you use a free real-time kernel, developers are required to have an in-depth understanding of the kernel itself and need to invest considerable energy. Therefore, although the use of RTOS will bring certain conveniences to the development process, for specific applications, whether to use RTOS, and if so, which RTOS to choose, are all issues that deserve careful consideration when formulating a system solution.
Previous article:Design of asynchronous serial communication between PIC microcontroller and PC
Next article:Design of hands-free passive keyless access control system based on PIC16F639
- Popular Resources
- Popular amplifiers
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
- mpy's LoRa driver library uPyLora
- Can I create a C program with only a hex file?
- [NXP Rapid IoT Review] Unfinished "IKEA Alarm Clock" and Review Summary
- Will you still go crazy shopping on Double 11 now?
- Answer the questions and get a gift | Rochester Electronics will help you solve the problems of the entire semiconductor cycle
- C language (vd6.0) sleep function usage and delay usage
- Battery applications in medical monitoring and the changing environment
- TI Power Supply Learning and Growth Road: DC-DC/AC-DC Control Circuit
- Thank you + thank you EEWORLD
- msp430 library serial PWM