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.

What You’ll Learn

  • How to create a new Simulink model
  • How to configure the Master block for your target device
  • How to add and connect peripheral blocks
  • How to build and deploy firmware to hardware

Time to complete: ~15 minutes

Prerequisites

Before you begin, ensure you have:

  1. MATLAB + Simulink (R2018b or later)
  2. MPLAB Device Blocks for Simulink installed (installation guide )
  3. XC-DSC or XC16 compiler installed
  4. A Microchip development board (e.g., dsPIC33CK Curiosity, dsPIC33CK Curiosity Nano, dsPIC33AK Curiosity Nano, MCLV-2, or similar)
  5. MPLAB X IDE (for programming, if not using auto-programming)

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:

  • dsPIC33CK Curiosity: 33CK256MP508
  • dsPIC33CK Curiosity Nano (EV88G73A): 33CK64MC105
  • dsPIC33AK Curiosity Nano (EV17P63A): 33AK512MPS506
  • MCLV-2 with dsPIC33CK PIM: 33CK256MP508
  • MCLV-48V-300W + Perseus DIM: 33AK128MC106
  • MCLV-48V-300W + BlueRidge DIM: 33AK256MPS306
  • MCLV-48V-300W + Sagitta DIM: 33CK256MP508
  • MCLV-48V-300W + Andromeda DIM: 33CK64MC105
  • MCHV-230VAC-1.5kW + Perseus DIM: 33AK128MC106
  1. Launch MATLAB
  2. Open Simulink by typing simulink in the command window and pressing Enter
  3. In the Simulink Start Page, click Blank Model
  4. Save the model immediately:
    • Press Ctrl+S (or File β†’ Save)
    • Name it my_first_blink.slx

Step 2: Add the Master Block

The Master block is required in every MPLAB Blockset model. It configures the target device and system clock.

  1. Open the Simulink Library Browser:

    • Press Ctrl+Shift+L or click the Library Browser button in the Simulink toolbar
  2. Navigate to MCHP_Blockset β†’ System Configuration

  3. Drag the Microchip Master block into your model

Alternatively, click anywhere in an empty area of the model canvas and start typing the block name β€” for example, Master. Simulink’s quick-add finder offers matching blocks; press Enter to drop the selected one.
  1. Double-click the Master block to open its configuration dialog

  2. Select your target device:

    • In the Target dropdown, search for and select your chip (e.g., 33CK256MP508 for the dsPIC33CK Curiosity board) β€” see the device list at the top of this page.
    • Click Apply β€” the dialog will close and reopen with device-specific settings
  3. Verify the oscillator settings:

    • Switch to the Oscillator tab
    • For most development boards, the default Internal Fast RC (FRC) oscillator works out of the box
    • If your board has an external crystal, select Crystal / Ceramic resonator and enter the frequency
  4. Note the Time-Step synchronisation field on the General tab β€” we’ll set this in Step 6

  5. Click OK to close the dialog

Step 3: Add a Digital Output Write Block

This block controls a GPIO pin to drive an LED.

  1. In the Library Browser, navigate to MCHP_Blockset β†’ Digital IO

  2. Drag the Digital Output Write block into your model

  3. Double-click the Digital Output Write block to configure it

  4. Select the LED pin for your board:

    • Port: Select the port (e.g., E for Port E)
    • Pin: Enter the pin index (e.g., 0 for RE0)

Common LED pins by board:

  • dsPIC33CK Curiosity: RE0 (Port E, Pin 0)
  • dsPIC33AK Curiosity Nano (EV17P63A): RD0 (LED0)
  • dsPIC33CK Curiosity Nano (EV88G73A): RD10 (LED0)
  • MCLV-2: Varies by PIM β€” check your board’s schematic
  • MCLV-48V-300W: Board-specific LED on M1_LED1 / M1_LED2 (see template PINOUT)
  • MCHV-230VAC-1.5kW: RD5 (M1_LED1)

If you’re unsure, consult your board’s user guide or schematic.

  1. Set Initial Output to 0 (LED starts OFF)

  2. Leave Output mode as Push-Pull (default)

  3. Click OK

Step 4: Add a Pulse Generator

The Pulse Generator creates a square wave to toggle the LED.

  1. In the Library Browser, navigate to Simulink β†’ Sources

  2. Drag a Pulse Generator block into your model

  3. Double-click the Pulse Generator to configure it:

    • Amplitude: 1
    • Period (secs): 1 (toggles every 1 second β†’ 1 Hz blink rate)
    • Pulse Width (% of period): 50 (LED ON for 50% of the time)
    • Phase delay: 0
  4. Click OK

Step 5: Add Data Type Conversion

The Digital Output Write block expects a boolean input, but the Pulse Generator outputs a double. We need to convert it.

  1. In the Library Browser, navigate to Simulink β†’ Signal Attributes

  2. Drag a Data Type Conversion block into your model

  3. Double-click the Data Type Conversion block

  4. Set Output data type to boolean

  5. Click OK

Step 6: Connect the Blocks

Now connect everything together:

  1. Draw a signal line from Pulse Generator output to Data Type Conversion input

    • Click the output port (right side) of the Pulse Generator
    • Click the input port (left side) of the Data Type Conversion block
  2. 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)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Note: The Master block does not connect to other blocks. It configures the system globally.

Step 7: Configure Model Settings

Set up code generation and solver settings:

  1. Open Model Configuration Parameters:

    • Press Ctrl+E or click Modeling β†’ Model Settings
  2. Navigate to Solver:

    • Type: Select Fixed-step
    • Solver: Select discrete (no continuous states)
    • Fixed-step size: Enter 0.001 (1 ms time step)
  3. Click Apply, then OK

Important: The fixed-step size (1 ms in this example) determines how often the model executes. For a simple LED blink, 1 ms is more than adequate. For fast control loops (e.g., motor control), you might need 50 Β΅s (0.00005) or faster.

Step 8: Time-Step Synchronisation

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.

Step 9: Build, Deploy & Start

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:

  • Microchip tab β†’ Build, Deploy & Start
  • Simulink Hardware tab β†’ Build, Deploy & Start (or press Ctrl+B)

What happens:

  1. Code generation starts; the Diagnostic Viewer at the bottom of the Simulink window streams the build log.
  2. C code is created in a folder named 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.
  3. The XC compiler compiles the code.
  4. After a successful compilation, the board is programmed automatically using either the .elf or the .hex produced in my_first_blink.X/dist/.
  5. If everything succeeded, the Diagnostic Viewer ends with Build succeeded.
Build failed? Check the Troubleshooting section below.

If everything went well:

  • The LED on your development board should now blink at 1 Hz (1 second ON, 1 second OFF)
  • If it doesn’t blink, see Troubleshooting

Congratulations! You’ve successfully created, built, and deployed your first MPLAB Blockset model.

Troubleshooting

Build Fails

  • Compiler not found:

    • Verify XC-DSC or XC16 is installed
    • Run picInfo('check') in MATLAB to verify compiler detection
    • Restart MATLAB after installing compilers
  • Device Family Pack (DFP) missing:

    • Install the DFP from MPLAB X IDE: Tools β†’ Packs β†’ MPLAB Packs
  • Wrong pin selected:

    • Verify LED pin from your board’s schematic or user guide
    • Check the pin assignment in the Digital Output Write block
  • Oscillator misconfigured:

    • If using an external crystal, verify the frequency matches your hardware
    • Try switching to Internal Fast RC (FRC) in the Master block’s Oscillator tab
  • Code didn’t program:

    • Verify the programmer is connected and recognized by MPLAB X IPE
    • Check power supply to the board

Pulse Generator Output is Wrong

  • Ensure Data Type Conversion is set to boolean
  • Verify Pulse Generator Amplitude is 1 (not 0)

What’s Next?

Now that you’ve mastered the basics, explore these next steps:

Learn More Configuration

Add Real-Time Tuning

  • External Mode & PIL β€” Change parameters while the model runs on hardware
  • Adjust LED blink rate in real-time without reprogramming

Understand the Generated Code

Try More Complex Examples

  • PWM Output β€” Drive a motor or servo with pulse-width modulation
  • ADC Input β€” Read analog sensors (potentiometers, temperature sensors)
  • UART Communication β€” Send/receive data over serial
  • Motor Control β€” Implement field-oriented control (FOC) algorithms

Explore Pre-Built Examples

The 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.

See Also