Main Content

Program Control Flow of Motor Control Blockset Examples

This section describes the control flow of the field-oriented control (FOC) algorithm that the Motor Control Blockset™ examples use. The control flow operates using the hardware events along with the triggered software and hardware interrupts. This figure describes the interactions between the hardware modules and software subsystems.

The FOC based examples generally use the data speed of 20KHz for the Current Control triggered software subsystem. Similarly, the examples use the data speed of 2KHz for the Speed Control triggered software subsystem. The ADC end of conversion (EOC) interrupt (a hardware interrupt) triggers the current control subsystem. The PWM-ADC synchronization controls the rate of this trigger. Similarly, a software interrupt triggers the speed control subsystem.

The entire system uses external inputs for motor position, motor speed, motor currents, and the desired motor speed. The preceding figure shows the interactions between these data points and the enclosed subsystems.

Motor Control Blockset provides the Algorithm-Export Workflows for Custom Hardware example that include Simulink® models for current control and speed control systems. The example provides instructions to generate code for these models. To create a FOC algorithm that can run on any motor control hardware, integrate this generated code with the hardware peripheral code (either auto-generated or manually written). Ensure that you activate the Current Control and Speed Control systems at appropriate times for the prescribed time intervals as shown in the preceding figure.

The following figure shows the entire structure of the integrated code.

ADC-PWM Synchronization

The interaction between the PWM and ADC modules controls the rate of triggering of the Current Control subsystem. To reduce harmonics in the system, the PWM counter runs in center-aligned or up-down mode. We configure the PWM such that when PWM counter reaches the PWM counter period value, it triggers the ADC start of conversion (SOC) event. This ensures that the currents available at the ADC inputs are updated currents, and therefore, helps to measure the ADC currents correctly. Usually when you use shunt current sensors to measure the motor currents, the current-sense resistor is located on the lower legs of the inverter. Therefore, if we ensure to switch on the lower leg of the ADC a little before the instant when ADC SOC is triggered (by configuring the PWM module), we can ensure that the ADC reads the currents correctly and that the measured current values are average values (the current measurements when the current has settled down). This figure shows this interaction.

Motor Speed and Position Measurement

The FOC algorithm needs current position and speed of the motor. Usually either the position sensors or the sensorless estimation techniques help determine these values. The choice of the position sensing method depends on the factors such as cost, available space, required accuracy, and the motor control application itself. Motor Control Blockset supports these position sensing methods.

  • Position sensors:

    • Quadrature encoder sensor

    • Hall sensor

    • Resolver

  • Sensorless position estimation techniques:

    • Sliding mode observer

    • Flux observer

Serial Communication

Motor Control Blockset FOC examples use serial communication protocols for providing commands to the motor and reading debugging-related information from the motor control hardware. For details about this protocol, see Fast Serial Data Monitoring.