User Guide Topics

External Mode enables real-time parameter tuning and signal monitoring on running hardware through a bidirectional communication link between Simulink and the target device. While your embedded application is running, you can modify parameter values and observe their effects immediately without rebuilding or reprogramming.

Overview

Key Capabilities:

  • Modify parameters in real-time without rebuilding or reprogramming
  • Monitor signals and scopes while application runs on hardware
  • Capture data from hardware to Simulink workspace
  • Compare simulation vs. hardware behavior side-by-side
  • Start/stop target execution from Simulink interface
  • Trigger data capture based on signal conditions
๐Ÿ’ก Typical Use Case: A motor control engineer uses External Mode to tune PID controller gains while the motor is running. Each parameter change takes effect immediately, allowing real-time observation of motor response without stopping the motor or rebuilding code.

Communication Protocol: XCP

External Mode uses the industry-standard XCP (Universal Measurement and Calibration Protocol) for communication between Simulink and the target microcontroller.

XCP Features:

  • Standardized protocol originally developed for automotive applications
  • Efficient binary data format minimizes communication overhead
  • Synchronization with model execution timing
  • Parameter upload (Simulink โ†’ hardware) and signal download (hardware โ†’ Simulink)

Supported Transport Layer โ€” XCP on SxI (Serial)

The blockset implements XCP on SxI (Serial). At the wire level the target sends/receives plain UART frames; the host sees them on a standard COM port. Two physical wiring options exist โ€” same protocol, same firmware, different USB-UART bridge:

Wiring optionUSB-UART bridgeTypical baudWhen to use
XCP on SerialBoard’s integrated USB-CDC serial bridge โ€” e.g. PKOB nano on Curiosity Nano (which acts as both programmer/debugger and USB-CDC serial bridge), PKOB4 on MCLV-48V-300W, on-board USB-CDC bridge on MCLV-2115 200 โ€“ 460 800 baudDefault โ€” a single USB cable to the board provides both programming and External Mode.
XCP on USBExternal FTDI FT232H USB-to-UART cable (e.g., C232HD-DDHSP-0 / C232HD-EDHSP-0) wired to a free UART of the targetUp to 12 MbaudWhen the integrated bridge is too slow for the number of streamed signals, or on boards without one.

Both paths use the same XCP-on-SxI driver in the generated code; only the physical bridge differs.

Prerequisites

Before enabling External Mode, your model must have:

  1. UART peripheral configured: a UART block (Config + Tx/Rx) wired to a UART that reaches the host โ€” either through the board’s integrated USB-UART bridge or through an external FTDI USB-UART cable.
  2. TX/RX pins routed: target UART TX/RX assigned to the physical pins connected to that bridge.
  3. Cable in place: the USB cable to the board (integrated bridge) or the FTDI cable plugged into the target UART (external bridge).
โš ๏ธ Hardware Connection Required: External Mode requires a working UART link. Verify the UART link is functional before enabling External Mode โ€” e.g., test with a plain UART Tx + a serial terminal first.

Configuration Steps

  1. Open Model Configuration Parameters (Ctrl+E)
  2. Navigate to: Code Generation โ†’ Interface
  3. Check “External mode” checkbox
  4. Select transport layer XCP on Serial โ€” this covers both wiring options (board’s integrated USB-UART bridge and external FTDI USB-UART cable).

Step 2: Configure Communication Parameters

  • Baud rate: e.g., 115 200, 230 400, 460 800. With an external FTDI cable on a free UART, several Mbaud are achievable. Must match the UART block setting.
  • COM port: auto-detected or manually specified (e.g., COM3 for the integrated bridge, a different COMxx for the FTDI cable).
  • Data bits: 8
  • Stop bits: 1
  • Parity: None

Step 3: Configure UART Peripheral (if using Serial)

Ensure your model includes a UART block configured for External Mode:

  1. Add a UART block from the MCHP Blockset library
  2. Configure UART settings:
    • Baud rate: Must match External Mode setting
    • TX/RX pins: Assign to physical pins connected to PC
  3. Do not use this UART for other purposes (External Mode owns the peripheral)
๐Ÿ’ก Dedicated UART Recommendation: Use a dedicated UART peripheral for External Mode. Sharing UART with application logging or other communication can cause data corruption and connection failures.

Step 4: Build and Program

  1. Build the model (Ctrl+B)
    • External Mode communication code is automatically included
  2. Program the target microcontroller via your programmer (ICD, PICkit, etc.)
  3. Connect communication cable between PC and target board

Step 5: Connect and Monitor

In Simulink:

  1. Click “Connect to Target” button in toolbar (or press Ctrl+K)
  2. Wait for connection confirmation (status bar shows “Connected”)
  3. Click “Start Real-Time Code” (or press Ctrl+T)
  4. Observe signals in Simulink scopes updating in real-time

To modify parameters:

  1. Double-click a tunable parameter or constant block
  2. Adjust the value using the slider or numeric entry
  3. Changes take effect immediately on hardware
  4. Observe the effect in real-time scopes

Making Parameters Tunable

By default, most parameters are compiled as constants and cannot be modified at runtime. To enable real-time tuning:

Method 1: Block Parameter

  1. Right-click the block parameter (e.g., Gain block’s “Gain” parameter)
  2. Select “Tune Parameter…”
  3. Check “Tunable” checkbox
  4. Optional: Set min/max limits for safety
  5. Rebuild the model

Method 2: Constant Block

  1. Use a Constant block instead of hardcoding values
  2. Right-click the Constant block โ†’ Properties
  3. Check “Tunable”
  4. Rebuild the model
โš ๏ธ Safety Limits: When tuning parameters for motor control or safety-critical applications, always set appropriate min/max limits. This prevents accidental entry of dangerous values (e.g., excessive PWM duty cycle, negative speed commands).

Performance Considerations

External Mode adds communication overhead to your embedded application:

AspectImpactRecommendation
CPU Overhead5-15% depending on logged signalsMinimize number of logged signals
Communication Latency10โ€“100 ms depending on baud and number of streamed signalsMove to a higher baud or to an external FTDI USB-UART cable on a free UART for lower latency than the integrated bridge.
Maximum Sample RateLimited by communication bandwidthSerial @ 115200 baud: ~1 kHz max
Serial @ 460800 baud: ~5 kHz max
Ethernet/USB: ~100 kHz max
Memory UsageAdditional RAM for communication buffers~2-8 KB depending on configuration

Detailed External Mode Guide

For comprehensive information including PIL testing, timing analysis, and advanced External Mode features, see:

๐Ÿ“š External Mode & PIL Testing Guide

This detailed guide covers:

  • External Mode vs PIL comparison
  • Numerical verification procedures
  • Timing analysis and profiling
  • Best practices for development and commissioning
  • Troubleshooting connection issues

Video Tutorial

๐Ÿ“น Watch: Getting Started with External Mode

Learn External Mode setup and usage in this video demonstration:

๐Ÿ”— External Mode Video Tutorial

The video covers:

  • Enabling External Mode in Simulink
  • Configuring UART communication
  • Building and connecting to hardware
  • Real-time parameter tuning demonstration
  • Monitoring signals on scopes

Troubleshooting

Problem: Connection Timeout

Symptom: Simulink shows “Cannot connect to target” after clicking Connect.

Solutions:

  1. Verify communication cable: Check physical connection between PC and target
  2. Check COM port: Ensure correct COM port is selected in External Mode settings
  3. Verify UART configuration: Confirm UART block baud rate matches External Mode setting
  4. Check target is running: Toggle an LED to verify code is executing
  5. Try different COM port: Sometimes Windows assigns different port number

Problem: Connection Drops During Operation

Symptom: Connection works initially but drops randomly during tuning.

Solutions:

  1. Reduce number of logged signals: Too many signals saturate communication bandwidth
  2. Increase UART baud rate: Try 230400 or 460800 instead of 115200
  3. Check for electrical noise: Poor cable quality or EMI can corrupt data
  4. Disable USB power saving: Windows may put USB ports to sleep (Power Management โ†’ uncheck “Allow computer to turn off this device”)

Problem: Parameters Not Updating

Symptom: Changing parameter value in Simulink has no effect on hardware.

Solutions:

  1. Verify parameter is tunable: Right-click parameter โ†’ check “Tunable” is enabled
  2. Rebuild model: Parameter tunability is set at compile time, requires rebuild
  3. Check parameter is not optimized away: Some unused parameters may be eliminated by compiler
  4. Verify connection is active: Status bar should show “Connected” and “Running”

Problem: Baud Rate Mismatch

Symptom: Garbled data, connection timeouts, or random disconnects.

Solution:

  • Ensure baud rates match exactly:
    • External Mode settings (Model Configuration Parameters)
    • UART block configuration in Simulink model
    • Physical UART peripheral register settings (auto-generated, but verify in code)

Problem: UART Already in Use

Symptom: Build fails with “UART peripheral already configured” or similar error.

Solution:

  • External Mode requires dedicated UART: Remove any other UART blocks or UART communication code
  • Use different UART: If application needs UART for logging, use a second UART peripheral for External Mode

Home | User Guide | Code Generation | PIL Testing | Compiler Setup | Video Demos | Block Reference