
NXP Semiconductors PMSMRT1060C
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC Motors
5 Motor-control peripheral initialization
The motor-control peripherals are initialized by calling the MCDRV_Init_M1() function during MCU startup
and before the peripherals are used. All initialization functions are in the mc_periph_init.c source file and
the mc_periph_init.h header file. The definitions specified by the user are also in these files. The features
provided by the functions are the 3-phase PWM generation and 3-phase current measurement, as well as the
DC-bus voltage and auxiliary quantity measurement. The principles of both the 3-phase current measurement
and the PWM generation using the Space Vector Modulation (SVM) technique are described in Sensorless
PMSM Field-Oriented Control (document DRM148).
The mc_periph_init.h header file provides the following macros defined by the user:
•M1_MCDRV_ADC_PERIPH_INIT: this macro calls ADC peripheral initialization.
•M1_MCDRV_PWM_PERIPH_INIT: this macro calls PWM peripheral initialization.
•M1_MCDRV_QD_ENC: this macro calls QD peripheral initialization.
•M1_PWM_FREQ: the value of this definition sets the PWM frequency.
•M1_FOC_FREQ_VS_PWM_FREQ: enables you to call the fast-loop interrupt at every first, second, third, or
nth PWM reload. This is convenient when the PWM frequency must be higher than the maximal fast-loop
interrupt.
•M1_SPEED_LOOP_FREQ: the value of this definition sets the speed loop frequency (TMR1 interrupt).
•M1_PWM_DEADTIME: the value of the PWM dead time in nanoseconds.
•M1_PWM_PAIR_PH[A..C]: these macros enable a simple assignment of the physical motor phases to the
PWM periphery channels (or submodules). You can change the order of the motor phases this way.
•M1_ADC[1,2]_PH_[A..C]: these macros assign the ADC channels for the phase current measurement.
The general rule is that at least one-phase current must be measurable on both ADC converters, and the two
remaining phase currents must be measurable on different ADC converters. The reason for this is that the
selection of the phase current pair to measure depends on the current SVM sector. If this rule is broken, a
preprocessor error is issued. For more information about the 3-phase current measurement, see Sensorless
PMSM Field-Oriented Control (document DRM148).
•M1_ADC[1,2]_UDCB: this define is used to select the ADC channel for the measurement of the DC-bus
voltage.
In the motor-control software, the following API-serving ADC and PWM peripherals are available:
•The available APIs for the ADC are:
–mcdrv_adc_t: MCDRV ADC structure data type.
–void M1_MCDRV_ADC_PERIPH_INIT(): this function is by default called during the ADC peripheral
initialization procedure invoked by the MCDRV_Init_M1() function and should not be called again after the
peripheral initialization is done.
–void M1_MCDRV_CURR_3PH_CHAN_ASSIGN(mcdrv_adc_t*): calling this function assigns proper ADC
channels for the next 3-phase current measurement based on the SVM sector.
–void M1_MCDRV_CURR_3PH_CALIB_INIT(mcdrv_adc_t*): this function initializes the phase-current
channel-offset measurement.
–void M1_MCDRV_CURR_3PH_CALIB(mcdrv_adc_t*): this function reads the current information from
the unpowered phases of a stand-still motor and filters them using moving average filters. The goal is to
obtain the value of the measurement offset. The length of the window for moving the average filters is set to
eight samples by default.
–void M1_MCDRV_CURR_3PH_CALIB_SET(mcdrv_adc_t*): this function asserts the phase-current
measurement offset values to the internal registers. Call this function after a sufficient number of
M1_MCDRV_CURR_3PH_CALIB() calls.
PMSMRT1060C All information provided in this document is subject to legal disclaimers. © 2023 NXP B.V. All rights reserved.
User guide Rev. 0 — 20 April 2023
15 / 63