The MPLAB Device Blocks for Simulink requires a Microchip compiler to generate and build embedded C code from your Simulink model. This guide explains which compilers are supported, how to download and install them, and how to configure MATLAB to use them.
The blockset supports three compiler families from Microchip, each targeting different device architectures:
| Compiler | Target Devices | Architecture | Free License Features |
|---|---|---|---|
| XC16 | dsPIC30F, dsPIC33F, dsPIC33E, PIC24F/H/E | 16-bit | Optimization up to -O2 |
| XC-DSC | dsPIC33C, dsPIC33A, PIC32A | 16-bit / 32-bit DSC | Optimization up to -O2 |
| XC32 | PIC32MK/MZ/MM, SAM (ARM Cortex-M) | 32-bit | Optimization up to -O2 |
-O0, -O1, and -O2. Advanced optimization levels (-O3, -Os) require a paid PRO license.| Device Family | Compiler | Minimum Version | Recommended |
|---|---|---|---|
| dsPIC30F | XC16 | v1.26+ | v2.10+ |
| dsPIC33F | XC16 | v1.26+ | v2.10+ |
| dsPIC33E | XC16 | v1.26+ | v2.10+ |
| dsPIC33C | XC-DSC | v3.20+ | v3.30+ |
| dsPIC33A | XC-DSC | v3.30+ | v3.39+ |
| PIC32A | XC-DSC | v3.30+ | v3.39+ |
| PIC24F/H/E | XC16 | v1.26+ | v2.10+ |
| PIC32MK/MZ/MM | XC32 | v2.40+ | v4.45+ |
| SAM (ARM Cortex-M) | XC32 | v2.40+ | v4.45+ |
Download compilers from the official Microchip website:
Direct download links:
Windows:
C:\Program Files\Microchip\xc16\v<version>\C:\Program Files\Microchip\xc-dsc\v<version>\C:\Program Files\Microchip\xc32\v<version>\Linux:
/opt/microchip/xc16/v<version>//opt/microchip/xc-dsc/v<version>//opt/microchip/xc32/v<version>/MATLAB automatically detects installed Microchip compilers at these default locations. To verify compiler detection:
Step 1: Check Installed Compilers
Run picInfo('check') in the MATLAB Command Window:
>> picInfo('check')
--------------------------------------------
Microchip Blockset 3.xx Installed:
--------------------------------------------
2 Compiler(s) found for dsPIC chip:
- C:/Program Files/Microchip/xc16/v2.10 (XC16 v2.10)
- C:/Program Files/Microchip/xc-dsc/v3.30 (XC-DSC v3.30)
1 Compiler(s) found for 32 bits chip:
- C:/Program Files/Microchip/xc32/v4.45 (XC32 v4.45)
Step 2: Refresh Compiler Cache (if needed)
If you just installed a new compiler, refresh MATLAB’s toolbox cache:
>> RTW.TargetRegistry.getInstance('reset')
>> rehash toolboxcache
What is a DFP?
A Device Family Pack (DFP) contains device-specific information required for code generation:
DFP Installation
DFPs are automatically installed with MPLAB X IDE. They can also be installed standalone:
Via MPLAB X IDE (Recommended):
Standalone Installation:
<MPLAB X Install>/packs/Microchip/DFP Location:
C:\Program Files\Microchip\MPLABX\<version>\packs\Microchip\/opt/microchip/mplabx/<version>/packs/Microchip/The Compiler Options Block provides control over:
-O0 (none), -O1, -O2, -O3 (PRO only), -Os (size, PRO only)-D defines, -I include paths, etc.Configuration Steps:
-O2 for production)π‘ Optimization Levels:
`-O0`: No optimization (fastest build, largest code, slowest execution)
`-O1`: Basic optimization (balanced)
`-O2`: Full optimization (recommended for production, free license)
`-O3`: Aggressive optimization (requires PRO license)
`-Os`: Size optimization (requires PRO license)
If MATLAB does not auto-detect your compiler (non-standard installation path, custom compiler version, etc.), you can configure it manually:
Method 1: Model Configuration Parameters
Ctrl+E)bin folder:<install path>/xc16/v<version>/bin/<install path>/xc-dsc/v<version>/bin/<install path>/xc32/v<version>/bin/Method 2: Environment Variable
Set the compiler path in your system environment variables:
Windows:
setx MICROCHIP_XC16_PATH "C:\custom\path\xc16\v2.10"
setx MICROCHIP_XCDSC_PATH "C:\custom\path\xc-dsc\v3.30"
setx MICROCHIP_XC32_PATH "C:\custom\path\xc32\v4.45"
Linux:
export MICROCHIP_XC16_PATH="/opt/custom/xc16/v2.10"
export MICROCHIP_XCDSC_PATH="/opt/custom/xc-dsc/v3.30"
export MICROCHIP_XC32_PATH="/opt/custom/xc32/v4.45"
After setting environment variables, restart MATLAB and run RTW.TargetRegistry.getInstance('reset').
Symptom: Build fails with “Compiler not found” or picInfo('check') shows no compilers.
Solutions:
bin folder is in system PATH>> RTW.TargetRegistry.getInstance('reset')
>> rehash toolboxcache
Symptom: Code generation succeeds but build fails with device-specific error.
Solutions:
Symptom: Build fails at linker stage with “undefined reference” or “section overflow” errors.
Common causes:
Solutions:
-O1 or -O2 to reduce code sizeSymptom: Build uses XC16 for dsPIC33C device (should use XC-DSC), or similar mismatch.
Solution:
picInfo('check') to confirm correct compiler is installedCtrl+Shift+B)Home | User Guide | Code Generation | External Mode | PIL Testing | Video Demos | Block Reference