This step-by-step tutorial walks you through creating your first MPLAB Blockset project β a simple LED blink application that runs on a Microchip development board.
Time to complete: ~15 minutes
Before you begin, ensure you have:
simulink in the command window and pressing Entermy_first_blink.slxThe Master block is required in every MPLAB Blockset model. It configures the target device and system clock.
Open the Simulink Library Browser:
Navigate to MCHP_Blockset β System Configuration
Drag the Microchip Master block into your model
Double-click the Master block to open its configuration dialog
Select your target device:
33CK256MP508 for the dsPIC33CK Curiosity board)Common target devices:
33CK256MP50833CK64MC10533AK512MPS50633CK256MP50833AK128MC10633AK256MPS30633CK256MP50833CK64MC10533AK128MC106Use the search box to quickly find your device.
Verify the oscillator settings:
Note the Time-Step synchronisation field on the General tab β we’ll set this in Step 6
Click OK to close the dialog
This block controls a GPIO pin to drive an LED.
In the Library Browser, navigate to MCHP_Blockset β Digital IO
Drag the Digital Output Write block into your model
Double-click the Digital Output Write block to configure it
Select the LED pin for your board:
E for Port E)0 for RE0)Common LED pins by board:
M1_LED1 / M1_LED2 (see template PINOUT)M1_LED1)If you’re unsure, consult your board’s user guide or schematic.
Set Initial Output to 0 (LED starts OFF)
Leave Output mode as Push-Pull (default)
Click OK
The Pulse Generator creates a square wave to toggle the LED.
In the Library Browser, navigate to Simulink β Sources
Drag a Pulse Generator block into your model
Double-click the Pulse Generator to configure it:
11 (toggles every 1 second β 1 Hz blink rate)50 (LED ON for 50% of the time)0Click OK
The Digital Output Write block expects a boolean input, but the Pulse Generator outputs a double. We need to convert it.
In the Library Browser, navigate to Simulink β Signal Attributes
Drag a Data Type Conversion block into your model
Double-click the Data Type Conversion block
Set Output data type to boolean
Click OK
Now connect everything together:
Draw a signal line from Pulse Generator output to Data Type Conversion input
Draw a signal line from Data Type Conversion output to Digital Output Write input
Your model should now look like this:
ββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββββββ
β Pulse βββββββΆβ Data Type βββββββΆβ Digital Output β
β Generator β β Conversion β β Write β
ββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββββββ
ββββββββββββββββββββββββ
β Microchip Master β (not connected β system configuration only)
ββββββββββββββββββββββββ
Set up code generation and solver settings:
Open Model Configuration Parameters:
Navigate to Solver:
Fixed-stepdiscrete (no continuous states)0.001 (1 ms time step)Navigate to Code Generation β System target file:
MCHP_dsPIC_PIC24.tlc for dsPIC devicesMCHP_PIC32.tlc for PIC32 devicesNavigate to Code Generation β MCHP Target:
Click Apply, then OK
Return to the Master block to finalize timing:
Double-click the Microchip Master block
On the General tab, locate Time-Step synchronisation
This field should now display the fixed-step size you set (e.g., 0.001)
If it’s blank or different, re-check your Solver settings in Step 7
Click OK
Now generate code and compile:
Click the Build Model button in the Simulink toolbar (or press Ctrl+B)
Watch the Diagnostic Viewer at the bottom of the Simulink window:
my_first_blink_mchp_pic_ert_rtwCheck the output files in the model folder:
my_first_blink.elf β Executable with debug symbolsmy_first_blink.hex β Programming file for MPLAB X IPEIf you have a programmer connected (ICD4/5, PICkit4/5, PKOB4, Snap):
In Model Configuration Parameters β Code Generation β MCHP Target:
Click Build again β the firmware will flash automatically after compilation
If auto-programming is not configured:
Open MPLAB X IPE (not MPLAB X IDE)
Select your Device and Tool (programmer)
Click Connect
Browse to the .hex file in your model folder
Click Program
Wait for Programming/Verify complete message
If everything went well:
Congratulations! You’ve successfully created, built, and deployed your first MPLAB Blockset model.
Compiler not found:
picInfo('check') in MATLAB to verify compiler detectionDevice Family Pack (DFP) missing:
Wrong pin selected:
Oscillator misconfigured:
Code didn’t program:
boolean1 (not 0)Now that you’ve mastered the basics, explore these next steps:
my_first_blink.c in your model folderThe blockset includes dozens of ready-to-run examples. Access them via:
cd(fullfile(fileparts(which('MCHP_dsPIC_stf.tlc')), '../examples'))
Copy an example to your working directory before modifying.