This guide will walk you through creating your first MCHP Blockset project in 10 minutes.
Step 1: Open Simulink Library Browser
- Launch MATLAB
- Type
simulink in the command window and press Enter - In the Library Browser, find MCHP Blockset
Step 2: Create a New Model
- Click File â New â Model (or Ctrl+N)
- Save the model as
my_first_mchp_project.slx
Open Model Configuration Parameters (Ctrl+E)
Navigate to Code Generation â System target file
Select one of the MCHP target files:
MCHP_dsPIC_PIC24.tlc - For dsPIC/PIC24 devices
MCHP_PIC32.tlc - For PIC32 devices
MCHP_SAM.tlc - For SAM devices
Click Apply
Step 4: Select Device and Compiler
- In Configuration Parameters, go to Code Generation â MCHP Target
- Select your target device (e.g., dsPIC33AK128MC106)
- Select compiler version (auto-detected if installed correctly)
- Click OK
Tip: Use the search box to quickly find your device in the list.
Step 5: Add Master Block
- From MCHP Blockset library, drag Master block to your model
- Double-click to configure:
- Set system clock frequency
- Configure oscillator settings
- Set sample time (e.g., 0.0001 for 100Ξs)
Important: The Master block is required in every MCHP Blockset model. It initializes the device and configures the system clock.
Step 6: Add Peripheral Blocks
Example: Toggle a Digital Output
Add Digital Output block from MCHP Blockset â GPIO
Double-click the block:
Select output pin (e.g., RB0)
Set initial value (0 or 1)
Add a Pulse Generator from Simulink â Sources
Connect Pulse Generator output to Digital Output input
Configure Pulse Generator:
Period: 2 (toggle every second)
Sample time: Inherited (-1)
Step 7: Build the Model
- Click the Build button (or press Ctrl+B)
- Wait for code generation and compilation
- Check for successful build in the Diagnostic Viewer
- Verify output files are created:
*.hex - Programming file*.elf - Executable with debug symbols
Step 8: Program the Device
Option A: Using MPLAB X IPE
Open MPLAB X IPE
Select device and programmer
Browse to .hex file in model folder
Click “Program”
Option B: From Simulink (if configured)
In model configuration, enable auto-programming
Click “Build Model” - device will be programmed automatically
Example Models
The blockset includes example models to help you get started:
- Basic Examples - GPIO, timers, interrupts
- Motor Control - FOC, BLDC, sensor interfaces
- Communication - UART, SPI, I2C, CAN
- Power Conversion - SMPS, inverters, PFC
How to Access Examples:
- In MATLAB, click Home â Open
- Navigate to blockset installation folder â examples
- Copy example to your working directory before modifying
Common First Projects
1. LED Blink
Digital output + pulse generator (as shown in Step 6)
2. PWM Output
- Add PWM block from MCHP Blockset
- Configure frequency and duty cycle
- Add Constant block for duty cycle input
- Build and test on hardware
3. ADC Read and Serial Output
- Add ADC block to read analog input
- Add UART Tx block for serial output
- Add Display block for simulation
- Monitor ADC values via serial terminal
Next Steps
- [Learn External Mode] - Real-time parameter tuning
- [Learn PIL Testing] - Code verification on hardware
- [Explore Block Reference] - Detailed block documentation
- [Advanced Examples] - Complex motor control applications
Troubleshooting
- Build fails - Check compiler installation and paths
- Device not found - Verify Device Family Pack (DFP) is installed
- Code doesn’t run - Check oscillator configuration matches hardware
- Simulation error - Set proper sample times for all blocks
See Also
[Overview] | [Supported Devices] | User Guide