Implementation of motor control algorithms using the MCIMX93-EVK development kit. It includes hardware configuration details, setup instructions, and an overview of the software implementation process.
- Software
- Hardware
- Setup
- Application start-up using IAR
- Results
- FAQs
- Support
- Known Issues
- Release Notes
- Download and install IAR Embedded Workbench for ARM v 9.50.1 or above.
- Download and install the latest version of FreeMASTER (3.2.2.2) or above.
- Download and install the latest version of CM33F_RTCESL_4.7.1 or above.
- J-Link FW with the latest available version.
- Download patch for J-Link debug probe to support i.MX93 from here and follow the instructions in README.txt document in downloaded folder.
- MCIMX93-EVK
- FRDM-MC-LVPMSM.
- AdaptBoard_MCXN94LC_MC
- schematic included in the Base Board.zip file.
- Custom base board
- see the board design in the Base Board.zip file.
- Motor MCG IB 23810
- J-Link debug probe
- Personal Computer
The power stage consists of custom baseboard, AdaptBoard, and Freedom LVPMSM board.
The custom baseboard was essential to adapt the LVPMSM pinout to the MCIMX93-EVK GPIO header (J1001) and to step down the ADC voltage. Additionally, DC-Bus overcurrent protection is managed through this board.
This board is utilized for connection of MCIMX93-EVK and Freedom LVPMSM. Schematic and board visualization are shown below.
The boards are interconnected via a cable from connector J9 on the Base Board to GPIO Header J1001 on the MCIMX93-EVK. This header contains PWM outputs, Encoder signals (Ch A, Ch B), 3V3 supply voltage for the Freedom LVPMSM, and GND connection.
For the ADC connection, header J10 is utilized, which is linked to connector J1003 on the MCIMX93-EVK through soldered wires. The ADC voltage from the Freedom LVPMSM board is stepped down to 1V8 using voltage dividers before being connected to connector J10.
Since only 4 ADC channels are available on the MCIMX93-EVK, the measured DC-Bus current is managed by voltage comparator U3. It functions as a fault protection for Over DC-Bus current. When the voltage exceeds the threshold of 6.65 A, GPIO2 pin 0 is set to logic zero, triggering an interrupt and switching the PWMs to the off state. The output is connected to pin 27 on connector J9.
A 3V3 supply is required for the ICs on the Freedom LVPMSM board. This voltage is provided by the MCIMX93-EVK.
The board's connector JC1 is linked to the baseboard connectors J5 and J7, while connector JC2 is connected to J6 and J8. It is important to ensure that the first pin of the JC2 connector aligns with the first pin of the J8 connector.
Note: The Adapt Board was introduced due to limitations of available hardware. This board is not necessary for future use of motor control algorithms with i.MX93, if the Custom Base Board's pins will fit the Freedom LVPMSM board.
The LVPMSM board should be connected directly to AdaptBoard.
The motor phases shall be connected to the connector J7, according to schematic of the board.
The encoder shall be connected to connector J8, according to schematic of the board.
Connect PC to J1401 on MCIMX93-EVK using a USB-C to USB-A cable to enable serial communication. This will be used for real-time control of the application using FreeMASTER.
Connect the J-Link debug probe to the JTAG connector (J1405) on the board.
The boot switches should be set to boot from FlexSPI Serial NOR. Set SW1301 to 1101 [4-1].
Connect the USB-C Power cable to connector J301.
Connect the ADC inputs from custom base board connector J10 (pins 2, 4, 6, 8 ) to connector’s J1003 pins 1, 3, 5, 7, which correspond to SAR_ADC0’s channels 0, 1, 2, 3.
Connect the GPIO header J1001 to the header J9 on the custom base board.
Peripheral drivers for the Timer, PWM, ADC, and GPIO selector (onboard chip) are defined in file Peripherals.h, which can be found in the “source\peripherals” group. FreeMASTER drivers are in the group Freemaster.
-
It is needed to initialize the GPIO Extender on MCIMX-EVK. These ICs act like switches for GPIO outputs.
-
GPIO_SEL_Init()
function shall be used. -
This function utilizes I2C for communication with GPIO Extender.
-
It is mandatory to initialize the GPIO Extender, because PWM signals pass through it.
-
-
Clocks and pins shall be initialized.
- Used GPIO pins are summarized in table below.
- Default clock for TPM4, TPM5 and TPM6 is 24 MHz.
GPIO pin ALT I/O Function GPIO05 TPM4 Ch0 Output PWM AT GPIO21 TPM4 Ch1 Output PWM AB GPIO13 TPM4 Ch2 Output PWM BT GPIO25 TPM4 Ch3 Output PWM BB GPIO19 TPM6 Ch2 Output PWM CT GPIO27 TPM6 Ch3 Output PWM CB GPIO06 TPM5 Ch0 Input Encoder Ch A GPIO22 TPM5 Ch1 Input Encoder Ch B GPIO04 GPIO04 Output LED Blue GPIO12 GPIO12 Output LED Green GPIO00 GPIO00 Input Over DC Bus current protection -
Fault handling is initialized with functions
PWM_GPIO_INIT()
andGPIO_Fault_Handler()
.-
PWM_GPIO_INIT()
initializes all GPIO outputs used for PWM to logic 0 and sets the GPIOs for output. -
GPIO_Fault_Handler()
enables IRQ for pin 0 of GPIO in case of over DC Bus current.
-
-
PWM is initialized using function
InitPWM(TPM_Type *base1, TPM_Type*base2)
. The PWM is initialized for TPM4 and TPM6 in up-down counting mode.- PWM period is set by macro
PWM_PERIOD
in file Peripherals.h. - Deadtime used for PWM generation is set with macro
DEAD_TIME
. - Duty cycle is limited due to timer hardware limitation. This is handled with macro
MAX_DUTY
.
- PWM period is set by macro
-
EncoderInit(TPM_Type *TPM)
initializes the TPM5 Ch0 and Ch1 for encoder input. -
InitADC()
is used for ADC initialization.- Signals are measured sequentially.
- Channels 0 – 3 are used for Motor Control application as shown in table:
ADC Channel Measured signal SAR_ADC Ch 0 Phase A current SAR_ADC Ch 1 Phase B current SAR_ADC Ch 2 Phase C current SAR_ADC Ch 3 DC Bus voltage -
TPM channels will be updated only if there is enough time left for the update. Minimal time needed for
Update3PWM(frac16_t phaseA, frac16_t phaseB, frac16_t phaseC)
execution is 4.25$\mu s$ . If the algorithm is taking longer to compute the TPM registers won't be updated.
Project in IAR is using RTCESL library with version 4.7.1 (CM33F_RTCESL_4.7.1_IAR). For correct functionality of the app the library should be saved in C:\nxp\RTCESL.
Note: To support i.MX93, the patch for IAR and Segger J-Link must be installed. To download, navigate to https://www.nxp.com/webapp/Download?colCode=SDK_MX93_3RDPARTY_PATCH&appType=license.
-
Create new workspace in IAR EW (v. 9.50.1)
-
Project -> Import project files
- Browse for project location (
...\MCIMX93352_PMSM\
). - Open file "iMX93_PMSM_Control.ewp”.
- Browse for project location (
-
In group “source” open file “main.c”.
-
Build project using Project –> Make (F7).
-
Connect the cables and connectors according to Hardware configuration.
-
Turn on the power supply for MCIMX93-EVK using SW301.
-
Download and debug the project:
-
In group source\freemaster you can find FreeMASTER application, double click it to open FreeMASTER.
In FreeMASTER you need to find right COM port. When you connect the board to PC there will be 4 new ports. For Serial Communication with FreeMASTER you need to choose the last port. In this case COM7:
Most of the application control can be done from “foc” subblock located on the left side of the application.
Variables needed for motor control are shown in the “Variable Watch” window located at the bottom of the screen:
The application can be turned on/off by writing 1
or 0
respectively into the variable cntrState.switchAppOnOff
.
Control mode can be switched between scalar control, voltage control, current (torque) control, and speed control.
The switchSensor variable is used to switch between various sensor less methods.
You can watch the variables live using oscilloscopes or recorders located on the left side of the screen.
The current shall not exceed 2 A.
To enable calculation of Back-EMF observer navigate to Back-EMF Obs subblock. It is needed to change variable BemfObs_ON_OFF
to 1
. This will enable the observer. To change the observer dynamics, change the value of variable set_BemfObs_SL
to 1
. You can now change the value of f_BemfObs
E_BemfObs
f_BemfObs_ATO
E_BemfObs_ATO
, and f_BemfObs_LPF
, which will result in change of the observer's dynamics.
To use the speed from the observer as a feedback in the speed control, change variable switchSensor
to 1
or Bemf_SL
.
In scalar and speed control mode, it is possible to set the required speed for the motor using the FOC_n_Mech_Req
variable. After changing the variable value the motor will start to spin at the required speed.
You can check this value in the oscilloscope/recorder “foc->n Mech – i_DQ”.
To use the speed control a sensor (encoder) or sensor less algorithm is needed.
To change the voltage in the d or q axis you need to change the variable foc.uDQReq.fltD
or foc.uDQReq.fltQ
respectively.
To change the current in the d or q axis you need to change the variable foc.i_DQ_Req.fltD
or foc.i_DQ_Req.fltQ
respectively. This will allow you to control the flux and torque-producing components of the motor.
In case you want to run the motor, you need to change the required value of current in the q-axis (torque-producing axis).
The motor will spin at a speed that corresponds to the available voltage value in the axis.
Current and speed loop dynamics can be tuned using the variables f_i_PI
, f_w_PI
, E_w_PI
. Higher values of frequency f make the regulation faster.
To enable controllers' tuning you need to change the value of variables set_i_PI
, set_w_PI
to 1
, respectively.
The application works in various states, when the application reaches a state fault, it is necessary to remove the cause of the fault, otherwise, you won’t be able to turn on the application. Faults can be checked in the “faults” subblock.
To clear the fault, write 1 to the variable cntrState.switchFaultClear
. This will send the application to the “Init” state. In this state, all variables are initialized to default values.
It is now possible to control PMSM using i.MX93. The source code can be updated with additional control strategies.
No FAQs have been identified for this project.
- The ADC interrupt is not working after downloading the source code for second time. It is needed to reset the EVK, either by turning the board off/on or using the Reset button.
- Individual errors are not visible in FreeMASTER application.
Questions regarding the content/correctness of this example can be entered as Issues within this GitHub repository.
Warning: For more general technical questions regarding NXP Microcontrollers and the difference in expected functionality, enter your questions on the NXP Community Forum
Version | Description / Update | Date |
---|---|---|
1.0 | Initial release on Application Code Hub | June 24th 2024 |
NXP, the NXP logo, NXP SECURE CONNECTIONS FOR A SMARTER WORLD, Airfast, Altivec, ByLink, CodeWarrior, ColdFire, ColdFire+, CoolFlux, CoolFlux DSP, DESFire, EdgeLock, EdgeScale, EdgeVerse, elQ, Embrace, Freescale, GreenChip, HITAG, ICODE and I-CODE, Immersiv3D, I2C-bus logo , JCOP, Kinetis, Layerscape, MagniV, Mantis, MCCI, MIFARE, MIFARE Classic, MIFARE FleX, MIFARE4Mobile, MIFARE Plus, MIFARE Ultralight, MiGLO, MOBILEGT, NTAG, PEG, Plus X, POR, PowerQUICC, Processor Expert, QorIQ, QorIQ Qonverge, RoadLink wordmark and logo, SafeAssure, SafeAssure logo , SmartLX, SmartMX, StarCore, Symphony, Tower, TriMedia, Trimension, UCODE, VortiQa, Vybrid are trademarks of NXP B.V. All other product or service names are the property of their respective owners. © 2021 NXP B.V.