NXP Semiconductors MCUXpresso User manual

MCUXpresso SDK Field-Oriented Control
(FOC) of 3-Phase PMSM and BLDC motors
NXP Semiconductors Document identifier: PMSMRT1170
User Guide Rev. 0, 01/2022

Contents
Chapter 1 Introduction........................................................................................... 3
Chapter 2 Hardware setup.....................................................................................4
Chapter 3 RT crossover processors features and peripheral settings.................11
Chapter 4 Project file and IDE workspace structure............................................ 15
Chapter 5 Tools................................................................................................... 17
Chapter 6 Motor-control peripheral initialization.................................................. 18
Chapter 7 User interface......................................................................................20
Chapter 8 Remote control using FreeMASTER...................................................21
Chapter 9 Conclusion.......................................................................................... 45
Chapter 10 Acronyms and abbreviations.............................................................46
Chapter 11 References........................................................................................47
Chapter 12 Useful links........................................................................................48
Chapter 13 Revision history.................................................................................49
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 2 / 50

Chapter 1
Introduction
This user's guide describes the implementation of the sensorless motor-control software for 3-phase Permanent Magnet
Synchronous Motors (PMSM), including the motor parameters identification algorithm, on the NXP i.MX RT series crossover
processors. The sensorless control software and the PMSM control theory in general are described in design reference manual
DRM148
Sensorless PMSM Field-Oriented Control (FOC)
. The NXP Freedom (FRDM-MC-LVPMSM) is used as the hardware
platform for the PMSM control reference solution. The hardware-dependent part of the sensorless and sensored control software,
including a detailed peripheral setup and the Motor Control (MC) peripheral drivers, are addressed as well. The motor parameters
identification theory and algorithms are presented in this document. The last part of the document introduces and explains the
user interface represented by the Motor Control Application Tuning (MCAT) page based on the FreeMASTER run-time debugging
tool. These tools provide a simple and user-friendly way for the motor parameter identification, algorithm tuning, software control,
debugging, and diagnostics.
This document describes how to run and control the Permanent Magnet Synchronous Motor (PMSM) project using i.MX RT
Series Crossover Processors with the Freedom development board. The software provides sensorless/sensored field-oriented
vector position, speed, torque, and scalar control. You can control the application using the board buttons or via FreeMASTER.
The motor identification and application tuning is done using the MCAT tool integrated in the FreeMASTER page. The required
software, hardware setup, jumper settings, project arrangement, and user interface are described in the following sections. For
more information, visit www.nxp.com/motorcontrol_pmsm.
Table 1. Supported devices and control methodes
Possible control methods in SDK example
Device Default motor Scal
ar
Volt
age
Current FOC
(Torque)
Sensorless
Speed FOC
Sensored
Speed FOC
Sensored Position
FOC (Servo)
MIMXRT1170-EVK Teknic M-2310P
motor (with ENC) ✓ ✓ ✓ ✓ ✓ ✓
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 3 / 50

Chapter 2
Hardware setup
The PMSM Field-Oriented Control (FOC) application runs on the FRDM-MC-LVPMSM development platform with the i.MX
RT1170-EVK development tools in combination with the Teknic M-2310P-LN permanent magnet synchronous motor or with the
i.MX RT1010-EVK development tool in combination with the Linix 45ZWN24-40 permanent magnet synchronous motor.
2.1 FRDM-MC-LVPMSM
This evaluation board, in a shield form factor, effectively turns an NXP Freedom development board or an evaluation board into
a complete motor-control reference design, compatible with existing NXP Freedom development boards and evaluation boards.
The Freedom motor-control headers are compatible with the Arduino™ R3 pin layout.
The FRDM-MC-LVPMSM low-voltage, 3-phase Permanent Magnet Synchronous Motor (PMSM) Freedom development platform
board has the power supply input voltage of 24-48 VDC with a reverse polarity protection circuitry. The auxiliary power supply
of 5.5 VDC is created to supply the FRDM MCU boards. The output current is up to 5 A RMS. The inverter itself is realized by a
3-phase bridge inverter (six MOSFETs) and a 3-phase MOSFET gate driver. The analog quantities (such as the 3-phase motor
currents, DC-bus voltage, and DC-bus current) are sensed on this board. There is also an interface for speed and position sensors
(encoder, hall). The block diagram of this complete NXP motor-control development kit is shown in Figure 1.
Figure 1. Motor-control development platform block diagram
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 4 / 50

Figure 2. FRDM-MC-LVPMSM
The FRDM-MC-LVPMSM board does not require a complicated setup. For more information about the Freedom development
platform, see www.nxp.com.
2.2 Teknic M-2310P motor
The Teknic M-2310P-LN-04K motor is a low-voltage 3-phase permanent-magnet motor used in PMSM applications. The motor
has two feedback sensors (hall and encoder). For information on the wiring of feedback sensors, see the datasheet on the
manufacturer web page. The motor parameters are listed in Table 2.
Table 2. Teknic M-2310P motor parameters
Characteristic Symbol Value Units
Rated voltage Vt 40 V
Rated speed - 6000 RPM
Rated torque T 0.247 Nm
Rated power P 170 W
Continuous current Ics 7.1 A
Number of pole-pairs pp 4 -
NXP Semiconductors
Hardware setup
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 5 / 50

Figure 3. Teknic M-2310P permanent magnet synchronous motor
For the sensorless control mode, you need only the power input wires. If used with the hall or encoder sensors, connect also the
sensor wires to the NXP Freedom power stage.
Figure 4. Teknic motor connector type 1
NXP Semiconductors
Hardware setup
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 6 / 50

Figure 5. Teknic motor connector type 2
2.3 i.MX RT1160/1170 Evaluation Kit
The MIMXRT1160-EVK and MIMXRT1170-EVK are two-layer low-cost through-hole USB-powered PCBs. At its heart lies the
i.MX RT11xx crossover MCU. The dual core i.MX RT1160 runs on the Cortex-M7 core at 600 MHz and Arm Cortex-M4 at 240 MHz
and i.MX RT1170 runs on the Cortex-M7 core at 1 GHz and Arm Cortex-M4 at 400 MHz, while providing best-in-class security.
Table 3. MIMXRT1160-EVK and MIMXRT1170-EVK jumper settings
Jumper Setting Jumper Setting Jumper Setting
J5 1-2 J31 1-2 J59 1-2
J6 1-2 J32 1-2 J60 1-2
J7 1-2 J38 5-6 J61 1-2
J8 1-2 J41 1-2 J62 1-2
J21 1-2 J53 1-2
J27 2-3 J56 2-3
All others jumpers are open.
NXP Semiconductors
Hardware setup
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 7 / 50

Figure 6. MIMXRT1170-EVK board with highlighted jumper settings (valid also for MIMXRT1160-EVK)
For a correct connection, the motor-control application requires remove and solder some resistors. Please, solder resistor R1841
and R1842 for encoder and remove resistors R188 and R193 for right ADC measuring. These resistors are located on the top of
the EVK board. For more details, see the schematic.
NXP Semiconductors
Hardware setup
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 8 / 50

Figure 7. Resistor needed for proper operation on the top side of the EVK board
For more information about the MIMXRT1160-EVK or MIMXRT1170-EVK hardware (processor, peripherals, and so on), see the
MIMXRT1160 EVK Board Hardware User’s Guide or MIMXRT1170 EVK Board Hardware User’s Guide.
Hardware assembling
1. Connect the FRDM-MC-LVPMSM shield on top of the MIMXRT1160-EVK or MIMXRT1170-EVK board (there is only one
possible option).
Watch out for unwanted connections between bottom of FRDM-MC-PMSM and jumpers on top of MIMXRT11xx-
EVK.
NOTE
2. Connect the 3-phase motor wires to the screw terminals (J7) on the Freedom PMSM power stage.
3. On the top of FRDM-MC-PMSM shield connect by wires following pins:
Table 4. MIMXRT1170-EVK pin assignment
FRDM-MC-LVPMSM Connection On the MIMXRT1160/1170-EVK is pin
connected to
CUR_A J2, 1 <-> J4, 2 GPIO_AD_10
CUR_B J2, 3 <-> J4, 6 GPIO_AD_12
CUR_C J2, 5 <-> J4, 8 GPIO_AD_13
VOLT_DCB J2, 7 <-> J4, 4 GPIO_AD_11
CUR_DCB J2, 9 <-> J2, 8 GPIO_AD_30
4. Plug the USB cable from the USB host to the Debug USB connector (J11) on the EVK board.
5. Plug the 24-V DC power supply to the DC power connector on the Freedom PMSM power stage.
NXP Semiconductors
Hardware setup
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 9 / 50

Figure 8. Assembled Freedome system
NXP Semiconductors
Hardware setup
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 10 / 50

Chapter 3
RT crossover processors features and peripheral
settings
This chapter describes the peripheral settings and application timing. The i.MX RT1xxx is a new processor family featuring NXP’s
advanced implementation of the Arm Cortex-M7 core.
3.1 i.MX RT1160/1170
The i.MX RT1160/1170 crossover MCUs are setting speed records at 1 GHz. This ground-breaking family combines superior
computing power and multiple media capabilities with ease of use and real-time functionality. The i.MX RT1160/1170 MCU offers
support over a wide temperature range and is qualified for consumer, industrial and automotive markets.
For more information see i.MX RT1160 or i.MX RT1170 Crossover MCU Family web pages.
3.1.1 RT1160/1170 - Hardware timing and synchronization
Correct and precise timing is crucial for motor-control applications. Therefore, the motor-control-dedicated peripherals take care
of the timing and synchronization on the hardware layer. In addition, you can set the PWM frequency as a multiple of the
ADC interrupt (ADC ISR) frequency where the FOC algorithm is calculated. In this case, the PWM frequency is equal to the
FOC frequency.
Figure 9. Hardware timing and synchronization on i.MX RT1160/1170
• The top signal shows the eFlexPWM counter (SM0 counter). The dead time is emphasized at the PWM top and PWM
bottom signals. The SM0 submodule generates the master reload at every opportunity.
• The SM0 generates trigger 0 (when the counter counts to a value equal to the TRIG4 value) for the ADC_ETC (ADC
External Trigger Control) with a delay of approximately Tdeatime/2. This delay ensures correct current sampling at the duty
cycles close to 100 %.
• ADC_ETC starts the ADC conversion.
• When the ADC conversion is completed, the ADC_ETC ISR (ADC_ETC interrupt) is entered. The FOC calculation is done
in this interrupt.
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 11 / 50

3.1.2 RT1160/1170 - Peripheral settings
This section describes the peripherals used for the motor control. On i.MX RT1160/1070, there are three submodules from the
enhanced FlexPWM (eFlexPWM) used for 6-channel PWM generation and two 12-bit ADCs for the phase currents and DC-bus
voltage measurement. The eFlexPWM and ADC are synchronized via submodule 0 from the eFlexPWM. The following settings
are located in the
mc_periph_init.c
and
peripherals.c
files and their header files.
PWM generation - PWM1
• Six channels from three submodules are used for the 3-phase PWM generation. Submodule 0 generates the master reload
at event every nth opportunity, depending on the user-defined macro M1_FOC_FREQ_VS_PWM_FREQ.
• Submodules 1 and 2 get their clocks from submodule 0.
• The counters at submodules 1 and 2 are synchronized with the master reload signal from submodule 0.
• Submodule 0 is used for synchronization with ADC_ETC. The submodule generates the output trigger after the PWM reload,
when the counter counts to VAL4.
• Fault mode is enabled for channels A and B at submodules 0, 1, and 2 with automatic fault clearing (the PWM outputs are
re-enabled at the first PWM reload after the fault input returns to zero).
• The PWM period (frequency) is determined by how long it takes the counter to count from INIT to VAL1. By default, INIT =
-MODULO/2 = -12000 and VAL1 = MODULO/2 -1 = 11999. The eFlexPWM clock is 240 MHz so it takes 0.0001 s (10 KHz).
• Dead-time insertion is enabled. Define the dead-time length in the M1_PWM_DEADTIME macro.
ADC external trigger control - ADC_ETC
The ADC_ETC module enables multiple users to share the ADC modules in the Time Division Multiplexing (TDM) way. The
external triggers can be brought from the Cross BAR (XBAR) or other sources. The ADC scan is started via ADC_ETC.
• Both ADCs have set their own trigger chains.
• The trigger chain length is set to 2. The back-to-back ADC trigger mode is enabled.
• The SyncMode is on. In the SyncMode, ADC1 and ADC2 are controlled by the same trigger source. The trigger source is
the PWM submodule 0.
• After both ADCs conversion is completed, ADC_ETC interrupt is enabled and serves the FOC fast-loop algorithm.
Analog sensing - ADC1 and ADC2
ADC1 and ADC2 are used for the MC analog sensing of currents and DC-bus voltage.
• The ADCs operate as 12-bit with the single-ended conversion and hardware trigger selected. The ADCs are triggered
from ADC_ETC by the trigger generated by the eFlexPWM.
Quadrature Decoder (QD) module
The QD module is used to sense the position and speed from the encoder sensor.
• The direction of counting is set in the M1_POSPE_ENC_DIRECTION macro.
• The modulo counting and the modulus counting roll-over/under to increment/decrement revolution counter are enabled.
Peripheral interconnection for - XBARA1
The crossbar is used to interconnect the trigger from the PWM to the ADC_ETC and to connect the encoder (connected to
GPIO) to the QD.
• The FLEXPWM2_PWM1_OUT_TRIG0_1 output trigger (generated by submodule 0) is connected to
ADC_ETC_XBAR0_TRIG0.
• The encoder signal Phase A and Phase B are configured in
pinmux.c
.
NXP Semiconductors
RT crossover processors features and peripheral settings
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 12 / 50

Slow-loop interrupt generation - TMR1
The QuadTimer module TMR1 is used to generate the slow-loop interrupt.
• The slow loop is usually ten times slower than the fast loop. Therefore, the interrupt is generated after the counter counts
from CNTR0 = 0 to COMP1 = IPG CLK ROOT / (16U * Speed Loop Freq). The speed loop frequency is set in the
M1_SPEED_LOOP_FREQ macro and equals 1000 Hz.
• An interrupt (which serves the slow-loop period) is enabled and generated at the reload event.
FreeMASTER communication—LPUART1
LPUART1 (Low-Power Universal Asynchronous Receiver and Transmitter) is used for the FreeMASTER communication
between the MCU board and the PC.
• The baud rate is set to 115200 bit/s.
• The receiver and transmitter are both enabled.
• The other settings are set to default.
3.2 RT family - CPU load and memory usage
The following information apply to the application built using the MCUXpresso IDE in the debug and release configurations. The
tables below show the memory usage and CPU load. The memory usage is calculated from the
.map
linker file, including the 4-KB
FreeMASTER recorder buffer allocated in RAM. The CPU load is measured using the SysTick timer. The CPU load is dependent
on the fast-loop (FOC calculation) and slow-loop (speed loop) frequencies. In this case, it applies to the fast-loop frequency of 10
KHz and the slow-loop frequency of 1 KHz. The total CPU load is calculated using the following equations:
Where:
CPUfast - the CPU load taken by the fast loop.
cyclesfast - the number of cycles consumed by the fast loop.
ffast - the frequency of the fast-loop calculation (10 KHz).
fCPU - CPU frequency.
CPUslow - the CPU load taken by the slow loop.
cyclesslow - the number of cycles consumed by the slow loop.
fslow - the frequency of the slow-loop calculation (1 KHz).
CPUtotal - the total CPU load consumed by the motor control.
Table 5. i.MX RT1170 CPU load and memory usage (similar for RT1160)
debug configuration release configuration
Board FLASH 113 152 B Usage 0.67% 68 704 B Usage 0.41%
Board SRAM 17 428 B Usage 0.03% 17 404 Usage 0.03%
Table continues on the next page...
NXP Semiconductors
RT crossover processors features and peripheral settings
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 13 / 50

Table 5. i.MX RT1170 CPU load and memory usage (similar for RT1160) (continued)
debug configuration release configuration
SRAM_DTC - - - -
SRAM_ITC 72 B Usage 0.03% 48 B Usage 0.02%
SRAM_OC - - - -
Speed Control Position Control Speed Control Position Control
Maximum CPU load 5.49% 5.22% 4.5% 4.36%
The maximum CPU load is depending on executing functions from RAM or FLASH memory. Executing functions
can be speeding up in RTCESL_cfg.h header file by using macros RAM_OPTIM_HIGH, RAM_OPTIM_MEDIUM
or RAM_OPTIM_LOW.
NOTE
Memory usage and maximum CPU load can differ depending on the used IDEs and settings.
NOTE
NXP Semiconductors
RT crossover processors features and peripheral settings
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 14 / 50

Chapter 4
Project file and IDE workspace structure
All the necessary files are included in one package, which simplifies the distribution and decreases the size of the final package.
The directory structure of this package is simple, easy to use, and organized in a logical manner. The folder structure used in the
IDE is different from the structure of the PMSM package installation, but it uses the same files. The different organization is chosen
due to a better manipulation with folders and files in workplaces and due to the possibility to add or remove files and directories.
The “
pack_motor_board
“ project includes all the available functions and routines, MID functions, scalar and vector control of the
motor, FOC control, and FreeMASTER MCAT project. This project serves for development and testing purposes.
4.1 PMSM project structure
The directory tree of the PMSM project is shown in below.
Figure 10. Directory tree
The main project folder
pack_motor_imxrt1xxx\boards\evkbimxrt1xxx\demo_apps\mc_pmsm\pmsm_enc\
contains these folders
and files:
•
iar
—for the IAR Embedded Workbench IDE.
•
armgcc
—for the GNU Arm IDE.
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 15 / 50

•
mdk
—for the uVision Keil IDE.
•
m1_pmsm_appconfig.h
—contains the definitions of constants for the application control processes, parameters of the motor
and regulators, and the constants for other vector-control-related algorithms. When you tailor the application for a different
motor using the Motor Control Application Tuning (MCAT) tool, the tool generates this file at the end of the tuning process.
•
main.c
—contains the basic application initialization (enabling interrupts), subroutines for accessing the MCU peripherals, and
interrupt service routines. The FreeMASTER communication is performed in the background infinite loop.
•
board.c
—contains the functions for the UART, GPIO, and SysTick initialization.
•
board.h
—contains the definitions of the board LEDs, buttons, UART instance used for FreeMASTER, and so on.
•
clock_config.c and .h
—contains the CPU clock setup functions. These files are going to be generated by the clock tool in
the future.
•
mc_periph_init.c
—contains the motor-control driver peripherals initialization functions that are specific for the board and
MCU used.
•
mc_periph_init.h
—header file for
mc_periph_init.c
. This file contains the macros for changing the PWM period and the ADC
channels assigned to the phase currents and board voltage.
•
freemaster_cfg.h
—the FreeMASTER configuration file containing the FreeMASTER communication and features setup.
•
pin_mux and .h
—port configuration files. It is recommended to generate these files in the pin tool.
•
peripherals.c and .h
—MCUXpresso Config Tool configuration files.
The main motor-control folder
pack_motor_imxrt10xx\middleware\motor_control\
contains these subfolders:
•
pmsm
—contains main PMSM motor-control functions
•
freemaster
—contains the FreeMASTER project file
pmsm_float_enc.pmp
. Open this file in the FreeMASTER tool and use it
to control the application. The folder also contains the auxiliary files for the MCAT tool.
The
pack_motor_imxrt1xxx\middleware\motor_control\pmsm\pmsm_float\
folder contains these subfolders common to the other
motor-control projects:
•
mc_algorithms
—contains the main control algorithms used to control the FOC and speed control loop.
•
mc_cfg_template
—contains templates for MCUXpresso Config Tool components.
•
mc_drivers
—contains the source and header files used to initialize and run motor-control applications.
•
mc_identification
—contains the source code for the automated parameter-identification routines of the motor.
•
mc_state_machine
—contains the software routines that are executed when the application is in a particular state or
state transition.
•
state_machine
—contains the state machine functions for the FAULT, INITIALIZATION, STOP, and RUN states.
NXP Semiconductors
Project file and IDE workspace structure
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 16 / 50

Chapter 5
Tools
Install the FreeMASTER Run-Time Debugging Tool 3.1.2 and one of the following IDEs on your PC to run and control the PMSM
application properly:
•IAR Embedded Workbench IDE v9.20.2 or higher
•MCUXpresso v11.5.0
•ARM-MDK - Keil μVision version 5.36
For pin_mux.c, clock_config.c or peripherals.c modifications is recommended use MCUXpresso Configuration Tool v11 or higher.
For information on how to build and run the application in your IDE, see the
Getting Started with MCUXpresso
SDK
document located in the
pack_motor_<booard>/docs
folder or find the related documentation at MCUXpresso
SDK builder.
NOTE
5.1 Compiler warnings
Warnings are diagnostic messages that report constructions that are not inherently erroneous and warn about potential runtime,
logic, and performance errors. In some cases, warnings can be suspended and these warnings do not show during the compiling
process. One of such special cases is the “unused function” warning, where the function is implemented in the source code with its
body, but this function is not used. This case occurs when you implement the function as a supporting function for better usability,
but you do not use the function for any special purposes for a while.
The IAR Embedded Workbench IDE suppresses these warnings:
• Pa082 - undefined behavior; the order of volatile accesses is not defined in this statement.
• Pa050 - non-native end of line sequence detected.
The Arm-MDK Keil μVision IDE suppresses these warnings:
• 6314 - No section matches pattern xxx.o (yy).
By default, there are no other warnings shown during the compiling process.
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 17 / 50

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 DRM148).
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 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 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
(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, 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

• The available APIs for the PWM are:
—
mcdrv_pwma_pwm3ph_t
—MCDRV PWM structure data type.
—
void M1_MCDRV_PWM_PERIPH_INIT
—this function is by default called during the PWM periphery initialization
procedure invoked by the
MCDRV_Init_M1()
function.
—
void M1_MCDRV_PWM3PH_SET(mcdrv_pwma_pwm3ph_t*)
—this function updates the PWM phase duty cycles.
—
void M1_MCDRV_PWM3PH_EN(mcdrv_pwma_pwm3ph_t*)
—this function enables all PWM channels.
—
void M1_MCDRV_PWM3PH_DIS (mcdrv_pwma_pwm3ph_t*)
—this function disables all PWM channels.
—
bool_t M1_MCDRV_PWM3PH_FLT_GET(mcdrv_pwma_pwm3ph_t*)
—this function returns the state of the over-
current fault flags and automatically clears the flags (if set). This function returns true when an over-current event occurs.
Otherwise, it returns false.
• The available APIs for the quadrature encoder are:
—
mcdrv_qd_enc_t
—MCDRV QD structure data type.
—
void M1_MCDRV_QD_PERIPH_INIT()
—this function is by default called during the QD periphery initialization
procedure invoked by the
MCDRV_Init_M1()
function.
—
void M1_MCDRV_QD_GET(mcdrv_qd_enc_t*)
—this function returns the actual position and speed.
—
void M1_MCDRV_QD_SET_DIRECTION(mcdrv_qd_enc_t*)
—this function sets the direction of the
quadrature encoder.
—
void M1_MCDRV_QD_CLEAR(mcdrv_qd_enc_t*)
—this function clears the internal variables and decoder counter.
NXP Semiconductors
Motor-control peripheral initialization
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 19 / 50

Chapter 7
User interface
The application contains the demo mode to demonstrate motor rotation. You can operate it either using the user button, or using
FreeMASTER. The NXP EVK boards include a user button associated with a port interrupt (generated whenever one of the
buttons is pressed). At the beginning of the ISR, a simple logic executes and the interrupt flag clears. When you press the button,
the demo mode starts. When you press the same button again, the application stops and transitions back to the STOP state.
The other way to interact with the demo mode is to use the FreeMASTER tool. The FreeMASTER application consists of two parts:
the PC application used for variable visualization and the set of software drivers running in the embedded application. Data is
transferred between the PC and the embedded application via the serial interface. This interface is provided by the CMSIS-DAP
debugger included in the boards.
The application can be controlled using these two interfaces:
• The button on the MIMXRT1xxx-EVK development board (controlling the demo mode):
— MIMXRT1170-EVK - SW7
• Remote control using FreeMASTER (chapter Remote control using FreeMASTER):
— Using the Motor Control Application Tuning (MCAT) interface.
— Setting a variable in the FreeMASTER Variable Watch.
If you are using your own motor (different from the default motors), make sure to identify all motor parameters. The automated
parameter identification is described in the following sections.
NXP Semiconductors
MCUXpresso SDK Field-Oriented Control (FOC) of 3-Phase PMSM and BLDC motors, Rev. 0, 01/2022
User Guide 20 / 50
Table of contents