# dspic33ch-curiosityboard-pwmexample-dual-motor-control-pfc
**Repository Path**: magic123cn/dspic33ch-curiosityboard-pwmexample-dual-motor-control-pfc
## Basic Information
- **Project Name**: dspic33ch-curiosityboard-pwmexample-dual-motor-control-pfc
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-04-13
- **Last Updated**: 2026-04-13
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# PWM Peripheral Example:
# PWM Switching Scheme for Dual Motor Control with Power Factor Correction : Curiosity Platform Development Board and dsPIC33CH512MP508 MC DIM.
## 1. INTRODUCTION
This document describes implementation of PWM switching scheme used for the Dual motor control with Power Factor Correction. The example is implemented on the Curiosity Platform Development Board [(DS70005562)](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/UserGuides/Curiosity-Platform-Development-Board-Users-Guide-DS70005562.pdf) and dsPIC33CH128MP508 Motor Control Dual In-line Module [(EV68M17A)](https://www.microchip.com/en-us/development-tool/ev68m17a).This example demonstrates the Synchronization feature of the High Resolution PWM module in the dsPIC33CH Digital Signal Controllers.
The dsPIC33CH512MP508 [(DS70005371D)](https://ww1.microchip.com/downloads/en/DeviceDoc/dsPIC33CH512MP508-Family-Data-Sheet-DS70005371D.pdf) has two Digital Signal Controller (DSC) cores, namely the ‘**Main core**’ and the ‘**Secondary core**’, each capable of independent operation at different device frequencies, providing flexibility to implement multiple power control algorithms on a single dsPIC DSC.
The main core is configured to deliver the PWM signal to control a single-stage boost power factor correction converter. The PWM generators in the secondary core are configured to control two three-phase motor control inverters, each independently driving two three-phase motors. To ensure optimal operation, the PWM generator used for power factor correction in the main core is synchronized with the PWM generators used for motor control in the secondary core, utilizing the PWM PCI feature of the dsPIC DSC.
Synchronization helps in :
- Best utilization of ADC cores in secondary core
Staggers the interrupts for executing motor control algorithms in the secondary core.
- Allows selective sampling to minimize noise in the measured signals due to switching transients of other converters.
- Distributes switching noise across the cycle, compared to peak noise produced if all converters were turned on simultaneously.
### 1.1 PWM Switching Scheme
- In the main core, PG4 is configured to generate a PWM with a switching frequency of 64 kHz to control PFC.
- ADC Trigger1 output of PG4 (main core), which is post-scaled by 4:1, is used to synchronize PG5 of the secondary core at a specified trigger value w.r.t to PFC PWM, maintaining a 4:1 ratio between PFC PWM and Motor Control PWMs. Note that the synchronization point and ratio between switching frequencies can be modified based on application requirements.
- PG5 of the secondary core is dedicated to synchronization, and its output is not used for controlling the converter or inverter in this example.PG5 is configured in edge-aligned mode with a 50% duty cycle.
- In the secondary core, PG1 to PG3 are configured to control three-phase motor control inverter MC1. PG6 to PG8 are used for the second three-phase motor control inverter(MC2). PWM generators PG1 to PG3 and PG6 to PG8 operates at 16kHz ( i.e. 64kHz/4 )
- PG1 to PG3 used for MC1 is synchronized to the rising edge of PG5 output, and PG6- PG8 are synchronized to the falling edge of PG5 output through PCI Sync feature of the PWM, thus interleaving operation of MC1 and MC2 for optimal utilization of the controller resources.
- The figure below depicts the PWMs' generation for PFC, MC1, and MC2. Also, PG5 is utilized to synchronize the PWMs of the main core and secondary core and to interleave the PWM generators for controlling the motors.
## 2. SUGGESTED DEMONSTRATION REQUIREMENTS
### 2.1 Application Example Firmware Required for the Demonstration
To clone or download this application firmware on GitHub,
- Navigate to the [main page of this repository](https://github.com/microchip-pic-avr-examples/dspic33ch-curiosityboard-pwmexample-dual-motor-control-pfc) and
- On the tab **<> Code**, above the list of files in the right-hand corner, click Code, then from the menu, click **Download ZIP** or copy the repository URL to **clone.**
### 2.2 Software Tools Used for Testing the firmware
- MPLAB® X IDE **v6.25**
- MPLAB® XC-DSC Compiler **v3.21**
- DFP: **dsPIC33CH-MP_DFP v1.15.378**
> **_NOTE:_**
>The software used to test the code example during release is listed above. It is recommended, to build the code example using the tool version listed above or later.
### 2.3 Hardware Tools Required for the Demonstration
- Curiosity Platform Development Board [(EV74H48A)](https://www.microchip.com/en-us/development-tool/EV74H48A)
- dsPIC33CH512MP508 Motor Control Dual In-Line Module [(EV02G02A)](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/InformationSheet/dsPIC33CH512MP508-Motor-Control-Dual-In-Line-Module-%28DIM%29-Info-Sheet-DS50003069.pdf)
> **_NOTE:_**
>All items listed under this section Hardware Tools Required for the Demonstration are available at [microchip DIRECT](https://www.microchipdirect.com/).
## 3. HARDWARE SETUP
This section describes the hardware setup required for the demonstration.
> **Note:**
>In this document, hereinafter Curiosity Platform Development Board is referred as **development board**.
1. Insert the **dsPIC33CH512MP508 MC DIM** into the DIM Interface **connector J1** on the development board. Make sure the DIM is placed correctly and oriented before going ahead.
2. The development 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 J24** on the development board.
This USB also powers the development board.
3. PWM signals can be monitored using the oscilloscope. Refer to the following table for the signal mapping.
## 4. BASIC DEMONSTRATION
### 4.1 Firmware Description
The firmware version needed for the demonstration is mentioned in the section [Application Example Firmware Required for the Demonstration](#21-application-example-firmware-required-for-the-demonstration) section. This firmware is implemented to work on Microchip’s dual-core 16-bit Digital signal control-ler (dsPIC® DSC) **dsPIC33CH512MP508**. There are two independent dsPIC DSC cores called **Main Core** and **Secondary Core** in the device. For more information, see the **dsPIC33CH512MP508 Family datasheet [(DS70005371)](https://ww1.microchip.com/downloads/en/DeviceDoc/dsPIC33CH512MP508-Family-Data-Sheet-DS70005371D.pdf)**.
In MPLAB X IDE, the code for two cores is developed as separate projects with the following device selections.
- Device selection in main Project (code for **Main Core**) is **dsPIC33CH512MP508**.
- Device selection in **mcapp_pmsm** Project (code for **Secondary Core**) is **dsPIC33CH512MP508S1**.
Hence the firmware used in this demonstration consists of two MPLAB X projects, **main.X** (**Main Project**) and **mcapp_pmsm.X** (**Secondary Project**).
The Main Project **main.X**, defines the function of the main core. They are:
- Set device configuration bits applicable for both main and secondary cores. Configuration bits for main and secondary cores exist in the main core. Note that the configuration bits decide the I/O port ownership between the main and secondary core.
- Configure Main Core Oscillator subsystem to generate clocks needed to operate Core and its peripherals. In the firmware, Main is configured to run at 90MHz.
- To program and enable the Secondary core by invoking XC16 library (libpic30.h) routines _program_secondary() and _start_secondary().
The function of the Secondary Core (as defined in the Secondary Project **mcapp_pmsm.X**) is:
- Configuring the secondary core oscillator subsystem to generate the clocks needed to operate the secondary core and its peripherals. In the firmware, the secondary core is configured to operate at 100MHz.
- Configuring I/O ports and secondary core peripherals ( PWM generators) to control two three phase motors.
Once the main core is programmed and the secondary core is enabled, the secondary application in the PRAM runs autonomously.
### 4.2 Basic Demonstration
Follow the instructions step-by-step, to set up and run the demo example:
1. Start **MPLAB X IDE** and open the main project **main.X (File > Open Project)** with device selection **dsPIC33CH512MP508.**
2. Set the project **main.X** as the main project by right clicking on the project name and selecting **Set as Main Project** as shown. The project **main.X** will then appear in **bold.**
3. In the **Projects** window, right click on the **Secondaries** folder of the project tree (of Main project **main.X**) and select **Properties**. This will open the **Secondaries** category of the **Project Properties** dialog.
Verify the Secondaries category of **Project Properties** dialog, and ensure details are as follows (see figure):
- **Item** is **mcapp_pmsm.X**
- **Image Name** is **mcapp_pmsm**
- Check Box **Build** is **checked** and
- Check Box **Debug** is **unchecked**
> **Note:**
> May encounter build error if,
> - any of the values are not as mentioned above
> - the secondary project **mcapp_pmsm.X** is moved or deleted from the firmware directory
4. In the **Projects window**, right-click on the **Secondaries** folder of the project tree (of Main project **main.X**) and select the project **mcapp_pmsm**. This will open the Secondary project **mcapp_pmsm.X** in the MPLAB X IDE project window. Alternatively, you can open (**File>Open Project**) the Secondary project from its current location like any other MPLAB X project.
The selected device in Secondary project **mcapp_pmsm.X** can be viewed by opening its **Project Properties** Dialog. As can be seen from the figure below, this **Device** is set as **dsPIC33CH512MP508S1**(as shown in the figure below), representing the secondary core of the dsPIC33CH512MP508.
5. Right-click on the main project **main.X** and select **Properties** to open its **Project Properties** Dialog. Click the **Conf:[default]** category to reveal the general project configuration information. The development tools used for testing the firmware are listed in section [2.2 Software Tools Used for Testing the firmware.](#22-software-tools-used-for-testing-the-firmware).
In the **Conf:[default]** category window:
- Ensure the selected **Device** is **dsPIC33CH512MP508.**
- Select the **Connected Hardware Tool** to be used for programming and debugging.
- Select the specific Device Family Pack (DFP) from the available list of **Packs.** In this case, **dsPIC33CH-MP_DFP 1.15.378** is selected.
- Select the specific **Compiler Toolchain** from the available list of **XC-DSC** compilers.
In this case, **XC-DSC(v3.21)** is selected.
- After selecting Hardware Tool and Compiler Toolchain, Device Pack, click the button **Apply**.
Please ensure that the selected MPLAB® XC-DSC Compiler and Device Pack support the device configured in the firmware.
6. Right click on the associated Secondary Project **mcapp_pmsm.X** and select **Properties** to open its **Project Properties** Dialog. Click the **Conf: [default]** category to reveal the general project configuration information.
In the **Conf: [default]** category window:
- Select the specific Compiler Toolchain from the available list of compilers. Please ensure MPLAB XC16 Compiler supports the device **dsPIC33CH512MP508S1**.
- After selecting Compiler Toolchain, click the button **Apply**.
This step is required to build the Secondary Project with a specific compiler version.
7. To build the main project (in this case, **main.X**) and program the device dsPIC33CH512MP508, click **Make and Program Device Main project** on the toolbar.
Upon this, MPLAB X IDE begin executing the following activities in order:
- Builds Secondary Project **mcapp_pmsm.X** (linked to Main Project **main.X**)
- Builds Main Project **main.X** and
- Programs Main flash memory of dsPIC33CH512MP508 with code generated when building the Main Project and the Secondary Project.
> **Note:**
> In this firmware configuration, the Main Core programs the Secondary Core. When device is programmed, the Secondary core image is placed in the Main flash. When the Main Core is powered on and begins execution of code, it transfers the Secondary image from the Main flash to the Secondary PRAM.
9. If the device is successfully programmed, **RGB LED** will be turned **ON**, indicating that the dsPIC® DSC is enabled.
10. Monitor the PWM signal through oscilloscope as shown below :
## 5. REFERENCES:
For more information, refer to the following documents or links.
1. Curiosity Platform Development Board User's Guide [(DS70005562)](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/UserGuides/Curiosity-Platform-Development-Board-Users-Guide-DS70005562.pdf)
2. dsPIC33CH512MP508 Motor Control Dual In-Line Module (DIM) Information Sheet [(EV76L31A)](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/InformationSheet/dsPIC33CH512MP508-Motor-Control-Dual-In-Line-Module-%28DIM%29-Info-Sheet-DS50003069.pdf)
3. dsPIC33CH512MP508 Family datasheet [(DS70005371D)](https://ww1.microchip.com/downloads/en/DeviceDoc/dsPIC33CH512MP508-Family-Data-Sheet-DS70005371D.pdf)
4. MPLAB® X IDE User’s Guide [(DS50002027)](https://ww1.microchip.com/downloads/en/DeviceDoc/50002027E.pdf) or [MPLAB® X IDE help](https://microchipdeveloper.com/xwiki/bin/view/software-tools/x/)
5. [MPLAB® X IDE installation](http://microchipdeveloper.com/mplabx:installation)
6. [MPLAB® XC-DSC Compiler installation](https://developerhelp.microchip.com/xwiki/bin/view/software-tools/xc-dsc/install/)
7. [Microchip Packs Repository](https://packs.download.microchip.com/)