Development of permanent magnet brushless DC motor control system based on PIC18Fxx

Publisher:清新心情Latest update time:2012-04-07 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

11.jpg

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).

22.jpg

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]

33.jpg

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.

44.jpg

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

1.jpg

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

2.jpg

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.

Reference address:Development of permanent magnet brushless DC motor control system based on PIC18Fxx

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

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号