Chapter 6
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
).
The
mc_periph_init.h
header file provides several macros, which can be 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 n
th
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 are used to 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
•
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, these 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.
—
void M1_MCDRV_ADC_GET(mcdrv_adc_t*)
—this function reads and calculates the actual values of the 3-phase
currents, DC-bus voltage, and auxiliary quantity.
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide
18 / 50