This page provides solutions to common issues encountered when using the MPLAB Device Blocks for Simulink. Issues are organized by category for quick reference.

Compilation Errors

Problem: Compiler Not Found

Symptom: Build fails with error message: "Compiler not found" or "xc16-gcc is not recognized"

Solutions:

  1. Verify compiler installation:

    • Run picInfo('check') to check detected compilers
    • Ensure compiler is installed in default location:
      • XC16: C:\Program Files\Microchip\xc16\
      • XC-DSC: C:\Program Files\Microchip\xc-dsc\
      • XC32: C:\Program Files\Microchip\xc32\
  2. Refresh MATLAB compiler cache:

    >> RTW.TargetRegistry.getInstance('reset')
    >> rehash toolboxcache
    
  3. Manual configuration: See Compiler Setup โ†’ Manual Configuration

  4. Reinstall compiler: Download from microchip.com/compilers

Problem: Wrong DFP (Device Family Pack)

Symptom: Build fails with: "Device not supported" or "Cannot find device header file"

Solutions:

  1. Install correct DFP:

    • Open MPLAB X IDE
    • Tools โ†’ Packs โ†’ Device Family Pack Management
    • Select your device family, click “Install Latest”
  2. Update DFP to latest version: Older DFPs may not support newer devices

  3. Verify device name: Check Master block device selection matches exactly (case-sensitive)

Problem: Linker Errors - Undefined Reference

Symptom: Build fails with: "undefined reference to 'functionName'" or "undefined symbol"

Common Causes:

  • Missing compiler library
  • Wrong compiler version (too old)
  • Missing DFP peripheral library

Solutions:

  1. Check compiler version: Ensure minimum version requirements are met (Compiler Setup )
  2. Update DFP: Install latest Device Family Pack
  3. Check function name spelling: Verify block parameter values are correct
  4. Enable required libraries: Some blocks require additional compiler libraries

Problem: Linker Errors - Memory Overflow

Symptom: Build fails with: "section overflow", "program memory exceeds available space", or "data memory exceeds available space"

Solutions:

  1. Enable optimization:

  2. Reduce model size:

    • Remove unused blocks
    • Simplify algorithms
    • Use external code/libraries for large functions
  3. Select larger device: Consider microcontroller with more Flash/RAM

  4. Check memory allocation:

    • Review linker script memory regions
    • Verify stack and heap sizes are appropriate

External Mode Issues

Problem: Cannot Connect to Target

Symptom: Simulink shows: "Cannot connect to target" or connection timeout after clicking “Connect to Target”

Solutions:

  1. Check physical connection:

    • Verify USB/UART cable is connected
    • Try different USB port
    • Check cable quality (replace if needed)
  2. Verify COM port:

    • Open Device Manager (Windows)
    • Check which COM port is assigned
    • Update External Mode settings to match
  3. Verify UART configuration:

    • Ensure UART block baud rate matches External Mode setting
    • Check UART TX/RX pins are connected correctly
    • Verify UART peripheral is not used by other code
  4. Check target is running:

    • Add LED toggle in initialization code
    • Verify code is executing after programming
  5. Restart devices:

    • Unplug/replug USB cable
    • Press reset button on target board
    • Close and reopen Simulink model

Problem: Connection Drops Randomly

Symptom: Connection works initially but drops during operation or parameter tuning

Solutions:

  1. Reduce logged signals: Too many signals saturate communication bandwidth

  2. Increase baud rate:

    • Try 230400 or 460800 instead of 115200
    • Ensure UART block matches External Mode setting
  3. Check electrical noise:

    • Use shielded cable
    • Keep cable away from motor power lines
    • Add ferrite bead to cable
  4. Disable USB power management:

    • Device Manager โ†’ USB Controllers โ†’ Properties
    • Power Management tab
    • Uncheck “Allow computer to turn off this device”

Problem: Baud Rate Mismatch

Symptom: Garbled data, connection timeouts, random characters in Simulink

Solution:

Ensure these three settings match exactly:

  1. External Mode baud rate (Model Configuration Parameters โ†’ Code Generation โ†’ Interface)
  2. UART block baud rate parameter
  3. Physical UART hardware register (auto-configured, but verify)

Common baud rates: 115200, 230400, 460800

Hardware Connection Issues

Problem: Programmer Not Detected

Symptom: Build succeeds but programming fails: "No tool connected" or "Programmer not found"

Solutions:

  1. Check USB connection: Ensure programmer (ICD, PICkit, etc.) is plugged in

  2. Verify programmer is powered: Some programmers have power LED

  3. Install MPLAB X IDE: Required for programmer drivers

  4. Update programmer firmware:

    • Open MPLAB X IDE
    • Tools โ†’ Options โ†’ Embedded
    • Check “Update firmware automatically”
    • Connect programmer and allow firmware update
  5. Run picInfo check:

    >> picInfo('check')
    

    Should list detected programmers

Problem: Device ID Mismatch

Symptom: Programming fails with: "Device ID mismatch", "Target device not detected", or "Device ID: 0x00000000"

Solutions:

  1. Check target power: Ensure microcontroller is powered (3.3V or 5V depending on device)

  2. Check programmer connections: Verify ICSP pins (PGC, PGD, MCLR, VDD, GND) are connected

  3. Verify device selection: Ensure Master block device name matches physical chip

  4. Check for damaged chip: Try programming with MPLAB X IDE to verify hardware

  5. Check ICSP voltage: Some programmers provide power, some require external power

Model Configuration Issues

Problem: Missing Master Block

Symptom: Build fails immediately: "Model must contain MCHP_Master block"

Solution:

Add the MCHP Master Block to your model:

  1. Open MCHP Blockset library
  2. Drag MCHP_Master block to model
  3. Double-click to configure target device
  4. Rebuild model

Problem: Sample Time Conflicts

Symptom: Simulation or build fails with: "Sample time conflict" or "Inconsistent sample times"

Solutions:

  1. Check all block sample times: Ensure blocks have compatible sample times

    • Right-click block โ†’ Block Parameters โ†’ Sample time
    • Use inherited (-1) where possible
  2. Review model hierarchy: Subsystem sample times must be compatible with parent

  3. Use multi-rate scheduler: If model has multiple sample times, enable multi-tasking (Scheduler Guide )

Problem: Code Generation Fails

Symptom: Simulink code generation step fails before compiler is invoked

Solutions:

  1. Check block parameters: Some blocks have parameter constraints (e.g., PWM frequency limits)

  2. Verify license: Ensure Embedded Coder license is active:

    >> license('test', 'RTW_Embedded_Coder')
    
  3. Clear cache and rebuild:

    >> bd close all
    >> clear all
    >> rehash toolboxcache
    

    Then reopen model and rebuild

  4. Check MATLAB version compatibility: See Installation Requirements

Performance Issues

Problem: Model Runs Slow on Hardware

Symptom: Control loop frequency is lower than expected, or CPU utilization is near 100%

Solutions:

  1. Enable optimization:

  2. Profile execution time: Use PIL Testing to identify slow functions

  3. Optimize algorithm:

    • Reduce sample rate for non-critical tasks
    • Simplify calculations
    • Use lookup tables instead of real-time calculations
  4. Switch to multi-tasking scheduler: See Scheduler Guide

  5. Check MCU load: Add MCU Load Block to monitor CPU utilization

Problem: Real-Time Deadline Missed

Symptom: "MCU Overload" indicator triggers, or timing violations in PIL test

Solutions:

  1. Increase sample period: Reduce execution frequency if possible

  2. Enable multi-tasking: Allows preemption of slow tasks by fast tasks

  3. Optimize code: Follow Performance Issues solutions above

  4. Upgrade microcontroller: Consider faster device (e.g., dsPIC33C โ†’ dsPIC33A)

Problem: Blocks Not Visible in Library

Symptom: MCHP Blockset library appears empty or blocks are missing

Solutions:

  1. Refresh toolbox cache:

    >> rehash toolboxcache
    >> sl_refresh_customizations
    
  2. Verify installation:

    >> picInfo
    
  3. Reinstall blockset: Uninstall and reinstall from MATLAB Add-On Manager

Problem: Documentation Not Found

Symptom: Clicking “Help” on a block shows “Page not found”

Solution:

Rebuild documentation search index:

>> builddocsearchdb(fullfile(fileparts(which('MCHP_dsPIC_stf.tlc')), '../', 'doc'))

Then restart MATLAB.

Getting Additional Help

If your issue is not listed here or solutions don’t resolve the problem:

1. Check Model Configuration

Run comprehensive diagnostics:

>> picInfo('check')

2. Review Documentation

3. Search Support Forums

Microchip MATLAB Forum:

๐Ÿ”— forum.microchip.com - MATLAB Section

MathWorks File Exchange Discussion:

๐Ÿ”— MPLAB Device Blocks Discussion Panel

4. Report an Issue

When reporting issues, include:

  • MATLAB version
  • Blockset version (picInfo)
  • Compiler version (picInfo('check'))
  • Target device family and part number
  • Error message (full text)
  • Steps to reproduce
  • Screenshots if applicable

Diagnostic Commands Summary

CommandPurpose
picInfoShow blockset version and installation path
picInfo('check')Check compilers, programmers, paths
RTW.TargetRegistry.getInstance('reset')Refresh compiler detection
rehash toolboxcacheRefresh MATLAB toolbox cache
sl_refresh_customizationsRefresh Simulink customizations
bd close allClose all models and clear memory
builddocsearchdb(...)Rebuild documentation index

See Also