Main Content

Prepare Target Hardware

Follow these steps to prepare the target hardware before you deploy the control algorithm developed using Motor Control Blockset™ to it.

Verify Direction of Rotation of Motor

The phase sequence of the motor connection in the target hardware determines the direction of rotation of the motor. The Motor Control Blockset example models consider the direction of rotation during the position ramp-up as a positive direction and the corresponding measured speed as positive. It is recommended that you run the motor in open-loop control with a position ramp from 0 to 1 and ensure that the position feedback is positive. The example models in Motor Control Blockset use this convention for the motor's direction of rotation.

For the supported hardware, the algorithm in the example Quadrature Encoder Offset Calibration for PMSM Motor, runs the motor and finds the offset between the d-axis of the rotor and the encoder index pulse (when the rotor is aligned to the d-axis of the stator). The red LED in the host model for this example turns on when the direction is opposite. When this happens, you should change the phase sequence of the motor wiring (swap any two motor wires).

See the example Hall Offset Calibration for PMSM Motor to identify the direction of rotation of a motor that uses Hall sensors.


When using a Hall sensor, ensure that the Hall sequence updated in the Hall Speed and Position and Hall Validity blocks matches the sequence of the actual Hall signals. If you update an incorrect Hall sequence, the direction read by the target hardware is the opposite of the actual direction.

Calibrate Current Sensor

Signal conditioning circuits for the current sensor introduces an offset voltage in the ADC input when measuring both positive and negative current. For example, an ADC with a voltage reference of 3.3 V can have an offset of 1.65 V (when using Texas Instruments™ BOOSTXL-DRV8305 hardware). This offset value varies due to tolerances of the passive components in the signal conditioning circuit. It is recommended that you measure the ADC offset of the board during initialization.

In the hardware initialization block used in most Motor Control Blockset example models, the system computes the average current sensor ADC values and uses them as ADC offset values for measuring the current. ADC offset values are represented in ADC counts.

See the example Run 3-Phase AC Motors in Open-Loop Control and Calibrate ADC Offset to manually calibrate the ADC offset and update the offset in the script file.

See the Hardware Init subsystem in the example Field-Oriented Control of PMSM Using Quadrature Encoder to calculate the ADC offset before starting closed-loop control.

Calibrate Position Sensor

For PMSM, the position used in the current control algorithm should align with the d-axis position of the rotor. By default, the quadrature encoder position sensor reads the mechanical position of the rotor with reference to its index pulse. The position offset is the position read by the quadrature encoder when d-axis of the rotor is aligned to phase A. To obtain the accurate motor position, correct the position read by the quadrature encoder by using this offset value. Then provide the corrected motor position value as an input to the current control algorithm.

Any delay between the actual rotor position and the position provided to the current controller affects the motor functionality and performance.

For more details, see the examples Quadrature Encoder Offset Calibration for PMSM Motor and Hall Offset Calibration for PMSM Motor.