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:
Don’t have hardware yet? You can still follow this tutorial and build the model. The code will generate successfully even without a connected board.
Common target devices:
33CK256MP50833CK64MC10533AK512MPS50633CK256MP50833AK128MC10633AK256MPS30633CK256MP50833CK64MC10533AK128MC106simulink 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
Master. Simulink’s quick-add finder offers matching blocks; press Enter to drop the selected one.Double-click the Master block to open its configuration dialog
Select your target device:
33CK256MP508 for the dsPIC33CK Curiosity board) β see the device list at the top of this page.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)Click Apply, then OK
Time-Step synchronisation is set automatically by the blockset for a model this simple β typically using a hardware timer. No manual action is required here.
Now generate code, compile, and flash the board. This is different from Simulation β it produces a binary that runs on the target MCU instead of inside MATLAB.
Trigger it from either ribbon tab β both run the same action:
What happens:
my_first_blink.X next to the model β this is a standard MPLAB X project that can be opened in MPLAB X IDE for inspection or debugging..elf or the .hex produced in my_first_blink.X/dist/.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.