An article on the key elements of motor control
Motor control is an engineer can not get around the topic, qualified engineers in the design before, must have a wealth of insight into the entire motor control. In this paper, from synchronization, timing and software three aspects, detailed combing motor control process and composition, and share the experience of engineers in practice.
Synchronization and Timing
The top priorities of every real-time application are proper timing, synchronization and deterministic system response, and special attention must be paid to these aspects when designing motor control software. In essence, the process sounds very simple: the system reads sensor values, processes the control algorithm, monitors system safety and manages the output stage by adjusting the duty cycle of the PWM output.
Small timing errors can lead to serious system response errors, unstable operation and poor performance. To ensure that everything works as expected, it is critical to stay synchronized and ensure system determinism. Here, I would like to emphasize that we are dealing with a “hard real-time system” and meeting tight deadlines is absolutely critical.
The motor controller software can be implemented as a bare-metal solution without an operating system using a suitable RTOS (real-time operating system), or as a multi-core hybrid solution, where some CPU cores run in bare-metal mode while others use an operating system. Bare-metal solutions are always based on an interrupt-driven design, where interrupts handle time-critical tasks and ensure that everything happens at precise intervals.
Whether it’s a bare-metal, RTOS, or hybrid solution, timing analysis, task prioritization, and security analysis must be performed to ensure efficient and reliable system performance.
Timing analysis ensures that all tasks are completed on time. This includes considering the worst-case execution time for each task. Some of the major critical tasks in motor control include sensor data acquisition, execution of control algorithms via PWM signal generation, fault detection and handling, emergency stop and safety functions, real-time communication with other system components, and synchronization with external systems.
Phase-locked ring (electronics)
As mentioned earlier, phase-locked loops (PLLs), whether integrated into the MCU/DSP hardware or implemented as an IP core in an FPGA, are critical for synchronizing critical events. the primary function of a PLL is to synchronize the MCU/DSP/FPGA’s internal clock with an external clock source or signal. this is critical for maintaining timing accuracy in real-time applications. the PLL helps reduce clock jitter, which is critical for accurate timing, especially when controlling motor speed and position. This is critical to maintain timing accuracy in real-time applications.The PLL helps reduce clock jitter, which is essential for accurate timing, and is especially important when controlling the speed and position of motors.The PLL ensures precise timing alignment between the sampling of feedback signals, such as rotor position and current measurements, and the execution of control algorithms, thus ensuring optimal synchronization and accuracy. In multi-core systems, PLLs can be used to synchronize the operation of these cores.
Synchronizing pulse width modulation (PWM) with current measurements and analog-to-digital converters (ADCs) via a phase-locked loop (PLL) is critical to ensuring accurate and efficient system performance in motor control applications. By synchronizing the clock, the PLL ensures that all system components, including the PWM generator, ADC, and other processing elements, run on a synchronized clock. The PWM signals that control the power delivered to the motor are generated based on this synchronized clock. The timing of these signals directly affects motor performance. Current sensors measure the motor’s current. The timing of these measurements is critical, especially in systems such as field oriented control (FOC), where current feedback is used to control motor torque and speed. The analog signal from the current sensor is converted to a digital value using an ADC, and a PLL helps synchronize the ADC samples with the PWM cycle. This synchronization ensures that the ADC samples the current at the optimal time relative to the PWM signal (typically at points where the PWM is neither fully on nor fully off) to obtain an accurate current. The digitized current measurements are then fed into the control algorithm, and the PLL ensures that the measurements are taken at consistent intervals relative to the PWM signal, allowing the control algorithm to accurately modify the PWM duty cycle in response to changes in the state variables, thus ensuring optimal motor performance. By synchronizing the ADC samples with the PWM, the effects of switching noise and distortion are minimized. This is especially important in high-power motor control applications where the PWM signal can generate significant noise.
Current and Position Measurement
It is critical to accurately measure current and synchronize it with the PWM pulse. Techniques such as periodic sampling, current oversampling, and averaging are used to improve accuracy.
Periodic sampling occurs at the same frequency as the PWM, so the challenge is to determine the appropriate sample time. This involves setting the proper delay between the start of the PWM cycle and the analog-to-digital conversion.
Current oversampling involves sampling and averaging measurements at a frequency higher than the PWM frequency (sometimes 8-32 times higher.) The ADC interrupt service routine (ISR) frequency can be much higher than the PWM frequency, allowing detailed data to be collected.
Oversampling is limited by the bandwidth of the current sensor. For example, most Hall sensors typically used for motor control have a bandwidth between 50 kHz and 160 kHz. Proper timing and synchronization is critical to handle the high frequency oscillations affecting phase currents.
Figure 1 shows the timing in one processing cycle. The analog-to-digital converter (ADC) can be configured to sample at high frequencies. This requires setting the ADC clock and adjusting its sample rate. After the samples are taken, the MCU or DSP processes them to calculate their average value. This calculation is usually performed after a specific number of samples have been accumulated. The main processing interrupt service program (ISR) must be configured to trigger when the averaging calculation is complete. In addition, the PWM module needs to be set up in a way that ensures synchronization between the ADC samples, the ISR, and the PWM timing. Modern MCUs and DSPs excel at handling these tasks simultaneously with their powerful processing, real-time operation, and various peripherals designed to manage ADC, PWM, and ISR tasks.
It is critical that the sampling of position sensor data is synchronized with the main processing interrupt service program. And any delays caused by data transmission are considered and can be calculated to maintain timing accuracy. It is important to consider the effect of phase delays when applying any filter. In the case of angular velocity measurements using a resolver, the processing of the resolver data must be synchronized and the point at which the sine and cosine signal amplitudes are minimized must be selected to ensure accurate readings. In addition, the resolver signal is oversampled and a bandpass filter with a cutoff frequency matching the PWM frequency is applied. This method helps filter out unwanted frequencies while maintaining signal integrity.
In high-speed systems, position must be inferred to ensure rotor accuracy so that the stator magnetic field is properly aligned relative to the rotor magnetic field. Accurate angle measurements ensure that the right amount of power is being delivered to the motor at any given time, thereby reducing energy loss, torque pulsations, vibration, and heat generation.
This discussion focuses primarily on field orientation control (FOC) applications that utilize direct rotor position measurements. It does not delve into sensorless FOC applications where the rotor position is not directly measured but estimated by indirect methods.
Safety Functions
Some common safety features common to motor control applications include:
Safe Torque Off (STO): This feature immediately shuts off power to the motor drive, causing the motor to stop producing torque. This is a critical feature in emergency situations when the motor needs to be stopped as quickly as possible to prevent injury.
Safe Direction (SDI): Prevents the motor from running in an unexpected direction.
Safe Operating Stop (SOS): This feature keeps the motor at a stop without disconnecting power.
Safe Speed Range (SSR) or Safe Speed Limit (SLS): Ensures that the motor operates within the safe speed range or below the safe maximum speed.
Overcurrent protection: This feature protects the motor and electronic equipment from overcurrent damage caused by faults such as short circuits or overloads.
Over-voltage and under-voltage protection: These features protect against over- or under-voltage, which can damage the motor or control electronics.
Thermal Protection: Monitors the temperature of the motor and drive, and if the temperature exceeds safe limits, the system can shut down to prevent overheating.
Speed Monitoring and Limiting: Ensures that the motor does not exceed predefined speed limits, which is critical for applications where exceeding a specific speed could be dangerous.
Emergency Stop: A physical button or switch that immediately stops the motor. This is a standard feature necessary for industrial applications.
Safety Brake Control: For brake-equipped motors, this feature safely engages the brake to stop the motor, especially in applications where gravity would move the motor vertically. Before activating the safety brake function, the system first attempts to stop the motor (if feasible) using the electrical brake, during which the energy flow is reversed to decelerate the motor.
The safety function can be implemented in hardware (HW), software (SW) or a combination of both, depending on the specific requirements and limitations of the application. Safety features such as overvoltage and undervoltage protection, overcurrent protection, thermal protection and emergency stops are typically implemented in hardware to ensure robust, fast and reliable system protection.
Speed monitoring and limiting, fault detection algorithms and Safe Operating Stop (SOS) are implemented in software.
Functions such as Safe Torque Off (STO), Safe Direction (SDI), Safe Speed Range (SSR)/Safety Speed Limit (SLS) and Safe Brake Control are typically implemented in a combination of hardware and software. This hybrid approach typically involves software commands for initiation and control, while relying on hardware components for effective implementation and enforcement.
The topic of safe design and functional safety in motor control (including standards such as SIL3) is another specialized topic.
Various manufacturers in the embedded systems and motor control space offer comprehensive design packages and tools designed to facilitate and accelerate the design and certification process in critical areas such as industry, transportation, energy, and healthcare. These packages typically include pre-certified software libraries, detailed safety manuals, and hardware modules designed to comply with stringent safety standards such as IEC 61508, ISO 13849, and others. In addition, they often provide extensive documentation and support for achieving certifications such as SIL (Safety Integrity Level) ratings, which are critical for high-reliability and safety-critical applications. This assistance not only streamlines the development process, but also significantly reduces the time and effort required for compliance and certification in these highly regulated industries.
Real-time operating system (RTOS)
Choosing the right RTOS for your motor control application is critical to ensuring high performance, reliability and safety. Key considerations include the RTOS’s real-time performance, resource efficiency including memory footprint and CPU utilization, and priority-based preemptive scheduling processing. Efficient and fast interrupts, as well as system reliability and robustness, are also key factors. Vendor support and documentation, compatibility with hardware, and the availability of development tools (such as IDEs, debuggers, and analyzers) and ecosystems (including libraries and code samples) play important roles. Finally, the license terms and cost of the RTOS should also be considered.
Considering the various factors and specific requirements of motor control applications, FreeRTOS, a popular open-source real-time operating system known for its efficiency and versatility, is an excellent choice. This choice is particularly beneficial in scenarios where cost-effectiveness, operational efficiency, system flexibility, reliability and robustness, ease of use, extensive hardware support and resource efficiency are key considerations.
Application architecture
The architecture for motor control applications consists of multiple layers and modules:
Hardware Abstraction Layer (HAL): Provides standardized interfaces for accessing hardware peripherals, including ADCs, PWM controllers, and communication interfaces, facilitating portability and scalability. It also contains board support packages (BSPs) and drivers for various hardware peripherals, enabling seamless hardware-software integration.
Core Real-Time Operations Layer: This layer contains the real-time operating system (RTOS) for efficient task scheduling and system resource management. It also includes dedicated memory management with a real-time heap allocator designed to optimize memory allocation in time-critical applications. In addition, the layer integrates powerful inter-core and inter-process communication (IPC) mechanisms that facilitate seamless data exchange and synchronization between different cores and processes within the system. The layer serves as the backbone of the core’s operational functions, ensuring smooth and efficient runtime performance.
Middleware Layer: This layer integrates several key functions as follows:
Communication interfaces: manages interactions with external systems or devices using various communication protocols.
Tracking and data logging: Focuses on tracking and logging specific signals and events, with the ability to output data in real time via DAC, IO, Ethernet, UART, USB and other channels.
Software Upload: Oversees the upload of new software versions or updates to ensure seamless integration and system continuity.
Configuration Management: Handles customer’s system configuration settings optimization and operational adjustments.
Diagnostics and Monitoring: Provides tools for system diagnostics and continuous monitoring, which are critical to maintaining system health and performance.
Built-in Testing (BIT): Includes self-testing capabilities to check the status and functionality of hardware and software components.
Motor Control Application Layer: At the top of all layers is the Motor Control Application, which is the key component that executes the application-specific workflow. This layer encapsulates:
Control and Signal Processing Algorithms: This includes core control algorithms such as PID control and Field Oriented Control (FOC), as well as signal processing algorithms designed to optimize motor performance.
Safety Logic: This component is dedicated to the safety aspects of the system, implementing the necessary protocols for emergency situations and routine safety checks to ensure that the system operates within safe parameters.
Application-specific workflows: This layer also integrates additional, unique workflows customized to the specific requirements of the motor control application, ensuring comprehensive functionality and performance.
Application Workflow
The application workflow typically involves several key steps:
Phase 1 Bootloader (FSBL): This important component is responsible for the initial phase of the boot process, including low-level hardware initialization and loading of major software components. A key part of its role is to load and launch the user application.The FSBL runs separately from the application layer and is usually provided by the MCU or DSP in its SDK. Customization of the BSP, such as adding additional memory checks or diagnostic features, is often required to ensure that the FSBL meets specific system requirements and enhances overall reliability.
Platform Setup: Initialization of Hardware Components: This includes setting up the ADC (analog-to-digital converter), system interrupts, PWM (pulse width modulation) module, communication interfaces (e.g., SPI, I2C, UART), watchdog timer, and any other necessary hardware peripherals. Set up interrupt handling mechanisms to respond to events such as timer overflow/input changes or communications. Configure the system clock, power modes, and ensure efficient power management for the controller and motors.
Application Configuration: This step contains the critical task of defining operating parameters, which is usually accomplished by reading configuration files. These files specify basic details such as motor characteristics, control parameters, and operating limits. In addition, the configuration settings can be adjusted in a variety of ways, including digital inputs, DIP switches, or dynamically via the communication interface of an external PC or master device. This multifaceted approach ensures flexible and adaptable configuration management for a wide range of applications.
This phase also includes:
Defining tasks: creating tasks such as master control tasks, communication tasks, and runtime condition monitoring tasks that are critical to the functionality of the application.
Setting priorities: Assigning priorities to these tasks based on their importance and role in the application. This is critical to ensure that critical tasks, such as the main control task, receive the necessary CPU response over less critical tasks.
Configure task properties: This can include setting stack sizes, specifying task parameters, and configuring any task-specific properties.
Establishing inter-task communication: Establish mechanisms for inter-task communication, such as queues, semaphores, or shared data structures.
Sensor Calibration: In applications where sensors are integrated, their calibration is critical to ensure accurate readings. Specifically, commonly used Hall effect sensors exhibit initial offsets that must be taken into account. During the calibration phase, these initial offsets are recognized and subsequently subtracted from the current measurement to correct the sensor output. This step is critical to ensure the accuracy of the sensor data.
Communications and Monitoring: Handles communications with external devices or systems for command and control, diagnostics, or remote monitoring.
Human Machine Interface (HMI)
In motor control applications, HMIs can represent simple physical controls and indicators (such as buttons, LEDs, or displays) or remote control interfaces.
This part of the workflow includes:
Sensor Data Acquisition: Real-time reading and processing of data from sensors, which is necessary for control loop feedback.
Real-time control loop execution: This is where the main control algorithm (such as PID control or FOC) is executed, usually in the main controller. Responds to timer interrupts for consistent timing.
Actuator Command Generation: Generates commands for an actuator such as a motor driver based on the output of the control algorithm. It usually involves setting up specific digital outputs and PWM signal generation.
afety and emergency handling: To ensure immediate response to safety and emergency events (e.g., emergency stops), these events should be handled sequentially and with high priority during this dedicated phase. This approach not only minimizes delays in handling critical events, but also enhances the overall safety and reliability of the system. In addition, this phase includes detecting and responding to various types of faults, including overcurrent, overvoltage, and hardware failures. By prioritizing these tasks, the system is better able to resolve and mitigate potential risks in a timely manner, thus ensuring a safer operating environment.
The key principle is to maintain a concise Interrupt Service Routine (ISR) that is primarily used to notify the main control task when further processing is required. Its primary role is not to execute the entire control logic within the ISR, but rather to notify higher-priority tasks about the occurrence of events. For this purpose, FreeRTOS provides various notification methods, such as binary semaphores, task notifications, or queues. The master task is an RTOS task that is responsible for mastering the algorithm. Once an ISR notification is received, the task is activated (or unlocked) and performs all the necessary steps described earlier. It is critical that the master control task be assigned an appropriate priority to ensure that the control algorithm is processed in a timely manner following an ISR.
The operation of the master task should be ensured using a watchdog timer that is designed to reset the watchdog timer periodically, demonstrating its correct operation and preventing the timer from expiring and triggering a system reset or error routine.
System Health Monitoring: Continuously monitors the system for faults such as overheating or other anomalies and takes appropriate action when any problems are detected.
Logging and Data Recording: Record important events, errors and system performance metrics for future analysis or troubleshooting.
Normal Shutdown: Ensures that the motor and controller shut down safely when the application stops.
If the application is running on a multi-core MCU/DSP/FPGA, it is important to ensure proper inter-core communication mechanisms. This can be achieved using on-chip shared RAM and software interrupts, but the approach may vary from platform to platform. Other possibilities include message-passing interfaces, direct memory access (DMA) channels, or the use of dedicated hardware communication blocks specific to the architecture.
A common approach is to have one kernel dedicated to communication tasks and another kernel for the main control loop. An RTOS is often used on both cores for efficient task management, but the main control kernel is usually run in a bare-metal environment for simplified low-level control. Dedicated processing units are available to enhance the performance of specific embedded system applications, including Texas Instruments’ (TI) CLA, ARM’s Cortex-M DSP extensions, STMicroelectronics’ ART gas pedals, Microchip’s dsPICs, NXP’s motor control coprocessors, and Infineon’s XMC digital coprocessors. performance for specific embedded system applications. Such extensions increase the overall computational bandwidth and free up the CPU for other tasks such as communication, monitoring and diagnostics.