
MATLAB/Simulink Model for Sensorless FOC with SMO and Field Weakening: MCLV-48V-300W Motor Control Development Board and dsPIC33CH512MP508 MC DIM
This document describes the setup requirements to drive a PMSM motor on the hardware platform EV18H47A "MCLV-48V-300W Motor Control Development Board" and EV76L31A "dsPIC33CH512MP508 Motor Control Dual In-line Module(DIM)".
The MATLAB/Simulink model includes Sensorless Field Oriented Control (FOC) with Sliding Mode Observer (SMO) Estimator referenced from AN1078 “Sensorless Field Oriented Control of a PMSM”. It also includes field weakening algorithm to support extended speed operation.- MATLAB/Simulink model can be downloaded as zip file (link).
- MPLAB X IDE and IPE (v6.20)
- XC-DSC compiler (v3.20)
- MATLAB R2024b
- Required MATLAB add-on packages
- Simulink (v24.2)
- Simulink Coder (v24.2)
- Stateflow (v24.2)
- MATLAB Coder (v24.2)
- Embedded Coder (v24.2)
- MPLAB Device blocks for Simulink (v3.59)
- Motor Control Blockset (v24.2)
NOTE: The software used for testing the model during release is listed above. It is recommended to use the version listed above or later versions for building the model.
- MCLV-48V-300W Motor Control Development Board (EV18H47A)
- dsPIC33CH512MP508 Motor Control DIM (EV76L31A)
- 24V Power Supply (AC002013)
- 24V, 3-Phase Brushless DC Permanent Magnet Hurst Motor (AC300022)
NOTE: All items listed under this section Hardware Tools Required for the Demonstration are available at microchip DIRECT.
This section describes hardware setup required for the demonstration.
-
Connect the 3-phase wires from the motor to PHA, PHB and PHC of the J4 connector, provided on the MCLV-48V-300W Development Board.
-
Insert the dsPIC33CH512MP508 Motor Control DIM into the DIM Interface connector J8 on the MCLV-48V-300W Development Board. Make sure the DIM is placed correctly and oriented before going ahead.
-
Plug the 24V power supply to connector J1 on the MCLV-48V-300W Development Board. Alternatively, the Development Board can also be powered through connector J3.
-
The board has an onboard programmer PICkit™ On Board (PKoBv4) , which can be used for programming or debugging the microcontroller or dsPIC DSC on the DIM. To use the onboard programmer, connect a micro-USB cable between the Host PC and connector J16 on the MCLV-48V-300W Development Board.
-
Alternatively, connect the Microchip programmer/debugger MPLAB® PICkit™ 5 In-Circuit Debugger between the Host PC used for programming the device and the ICSP header J9 on the MCLV-48V-300W Development Board (as shown). Ensure that PICkit 4 is oriented correctly before proceeding.
Follow the below instructions step-by-step, to set up and run the motor control demo application:
-
Launch MATLAB (refer the section “2.2 Sofware Tools Used for Testing the MATLAB/Simulink Model").
-
Open the folder downloaded from the repository, in which MATLAB files are saved (refer the section "2.1 MATLAB Model Required for the Demonstration").
NOTE: The dsPIC33CH512MP508 is a dual core dsPIC DSC with a main core and a secondary core. Two independent Simulink models are created for these two cores to support the dual core architecture. These two models need to be build separately in the Simulink and programmed to the device once.
File Name Description pmsm_foc_smo_dsPIC33CH_data.m MATLAB Script with Motor and Inverter paramerters main.slx Main Core Simulink Model secondary_pmsm_smo.slx Secondary Core Simulink Model mcb_host_SMO.slx Simulink Model for Data Visualization -
Follow the steps below to configure and build the secondary core model. This model contains the SMO based sensorless FOC algorithm.
-
Double click and open the .m file. This .m file contains the configuration parameter for the motor and board. By default, the .m file is configured to run Hurst 300 motor and MCLV-48V-300W Development board. Run the file by clicking the “Run” icon and wait till all variables gets loaded on the ‘Workspace’ tab.
-
Double click on the Sensorless FOC Simulink model.
-
This opens the Simulink model as shown below. Click on the "Run" icon to start the simulation.
-
To plot the simulation result, Data Inspector is used (refer to figure below). To observe the additional signals, log them as required. Alternatively, normal Simulink Scope can be used to plot the signals.
NOTE: The Simulation is only possible on each core independentely.
-
From this Simulink model an MPLAB X project can be generated, and it can be used to run the PMSM motor using Development board.
To generate the code from the Simulink model, go to the "MICROCHIP" tab, and enable the tabs shown in the figure below.
-
To generate the code, click on ‘Build’ option under the “Microchip” tab and 'Build, Deploy & Start' drop down.
-
After completing the process, the ‘Build process completed successfully’ message will be displayed on the ‘Diagnostics Viewer’.
-
This will generate the MPLAB X project for the secondary core model and create the secondary image (.s file) which will be used in the main core model. This secondary image will be inside the 'secondary_image' folder in the .X file
-
-
Follow the steps below to configure and build the main core model and program the device. This model contains the LED blinking and secondary core interface feature.
-
Double click on the main core Simulink model.
-
This opens the Simulink model as shown below. From this Simulink model an MPLAB X project can be generated, and it can be used to run the PMSM motor using Development board.
-
Double click on the Secondary image block to select the secondary image. Click on the 'Select secondary core image' from the drop down option. Select the secondary core image "secondary_image.s" from the path secondary_pmsm_smo.X/secondary_image.
-
From this Simulink model an MPLAB X project can be generated.
To generate the code from the Simulink model, go to the "MICROCHIP" tab, and enable the tabs shown in the figure below.
-
To generate the code and run the motor, click on ‘Build’ option under the “Microchip” tab and 'Build, Deploy & Start' drop down. This will generate the MPLAB X project from the Simulink model and program both the cores of dsPIC33CH512MP508 device.
-
After completing the process, the ‘Operation Succeeded’ message will be displayed on the ‘Diagnostics Viewer’.
-
-
If the device is successfully programmed, LED1 - LD1 and LED2 - LD2 will be blinking.
-
To Run the motor, press the push button SW1.
-
The motor speed can be varied using the potentiometer (labeled “POT”). Approximately, after 70% of the full potentiometer value (approximately at 3000 RPM), the motor enters into field weakening region.
-
Press the push button SW1 to stop the motor. Make sure motor is reduced to minimum potentimeter value before stopping the motor.
The Sensorless FOC model comes with the initialization required for data visualization using Motor Control Blockset Host Model (MCB Host Model). The MCB Host Model is a Simulink model which facilitates data visualization through the UART Serial Interface.
-
To establish serial communication with the host PC, connect a micro-USB cable between the host PC and the MCLV-48V-300W Development Board (J16 connector). This interface is used for programming as well.
-
Ensure the sensorless FOC model is programmed and running as described under section "4. Basic Demonstration" by following steps 1 through 13.
-
Open the MCB Host model and double click on the “Serial Setup” block. Then select the appropriate COM port connected to the hardware from the drop-down menu and set the baud rate as 460829. Please note that the same baud rate is required to be chosen in the Sensorless FOC model (the baud rate can be viewed on the “UART Configuration” block inside “MOTOR CONTROL DEVLOPMENT BOARD Template”).
-
Open the “UART_Rx” subsystem to configure the COM port. This can be done by configuring the “Host Serial Receive” block of the “UART_Rx” subsystem. Ensure to select the same COM port configured in step 3.
-
Click the run icon of the MCB Host model to open the scope window and monitor the signals.
-
In the figure below, one example is shown where two signals (estimated and reference speeds) have been plotted.
For more information, refer to the following documents or links.
- AN1078 Application Note “Sensorless Field Oriented Control of a PMSM”.
- MCLV-48V-300W Development Boards User’s Guide (DS50003297)
- dsPIC33CH512MP508 Motor Control DIM Information Sheet (DS50003069)
- MPLAB® X IDE installation
- MPLAB® XC-DSC Compiler installation
- Motor Control Blockset
- MPLAB Device Blocks for Simulink :dsPIC, PIC32 and SAM mcu