External Mode provides real-time parameter tuning and data visualization while your generated code runs on the target.

For code-generation accuracy and timing verification, see the companion PIL (Processor-in-the-Loop) guide.

External Mode: Real-Time Parameter Tuning

What is External Mode?

External Mode creates a bidirectional communication link between Simulink and your embedded target while the code is running. This enables:

  • Upload parameters to running code without rebuilding (e.g., tune PID gains in real-time)
  • Download signals from embedded hardware for real-time plotting in Simulink
  • Start/stop 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, observing the effect of each change immediately on Simulink scopes without stopping the motor or rebuilding code.

External Mode Variants

The toolbox provides MathWorks External Mode for real-time parameter tuning and signal monitoring.

Related Tool - PIC GUI: For simplified data visualization without parameter tuning capabilities, see Data Visualization with PIC GUI. PIC GUI provides lightweight data logging over UART with custom MATLAB visualization scripts.

MathWorks External Mode

Overview

MathWorks External Mode provides tight integration with Simulink, enabling parameter tuning and signal monitoring directly from the Simulink model interface.

Protocol: XCP (Universal Measurement and Calibration Protocol)

External Mode uses the industry-standard XCP protocol, which provides:

  • Standardized communication protocol
  • Support for multiple transport layers (Serial, TCP/IP, CAN)
  • Efficient binary data format
  • Synchronization with model execution

External Mode Setup Procedure

Step 1: Enable External Mode in Model

1. Open Model Configuration Parameters (Ctrl+E)
2. Navigate to: Code Generation โ†’ Interface
3. Check "External mode"
4. Configure transport layer:
   - Transport: "XCP on Serial" (for UART)
   - Transport: "XCP on TCP/IP" (for Ethernet)
5. Set baud rate (serial) or IP address (TCP/IP)

Step 2: Configure Communication Parameters

For Serial (UART):
  - Baud rate: 115200 (or higher)
  - COM port: Detected automatically or set manually
  - Data bits: 8
  - Stop bits: 1
  - Parity: None

For TCP/IP (Ethernet):
  - Target IP address: e.g., 192.168.1.100
  - Port: 17725 (default XCP port)

Step 3: Build, Deploy and Stream with Monitor & Tune

Use the Microchip toolstrip tab (see Microchip Toolstrip ):

1. Microchip tab -> Ext-Mode -> Ext Mode settings
   - Verify External Mode is active, host COM port, baud rate,
     transport, and the target UART Config block.
2. Microchip tab -> Ext-Mode -> Monitor & Tune  (the one-click "go")
   - Builds + deploys as needed, connects External Mode, starts
     execution, and streams live signals to the Simulink scopes.
3. Observe signals in Simulink scopes.
4. Modify tunable parameters in real-time.

The Ext Mode settings button is a split button: its drop-down opens the native MathWorks External Mode Control Panel for manual connect / start / stop control, if you prefer the classic dialog over one-click Monitor & Tune.

Making Parameters Tunable

To allow real-time tuning of a parameter:

1. Right-click the block parameter or constant block
2. Select "Tune Parameter..."
3. Check "Tunable" checkbox
4. Optional: Set min/max limits for safety
5. Rebuild model

During External Mode:
  - Double-click parameter to open slider
  - Adjust value while code runs
  - Observe effect immediately

โš ๏ธ Safety Warning: When tuning parameters in real-time for motor control or other safety-critical applications:

        Set appropriate min/max limits on tunable parameters
        Have emergency stop mechanism ready
        Start with safe operating conditions
        Monitor system behavior continuously

External Mode Performance Considerations

AspectImpactRecommendation
CPU Overhead5-15% depending on logged signalsMinimize number of logged signals
Communication Latency10-100ms depending on transportUse TCP/IP for lower latency than Serial
Maximum Sample RateLimited by baud rate / network speedSerial: ~10 kHz max, Ethernet: ~100 kHz max
Buffer SizeLimits burst logging capabilityConfigure in External Mode settings

Best Practices

  • Minimize logged signals: Only log signals you need to observe
  • Use appropriate sample rates: Don’t oversample slow signals
  • Set parameter limits: Prevent accidental unsafe values
  • Document tuned values: Record final parameter values in model
  • Test without External Mode: Verify performance without communication overhead

Troubleshooting

External Mode Connection Issues

Problem: Cannot connect to target

Solutions:

  • Verify COM port or IP address is correct
  • Check baud rate matches between model and hardware
  • Ensure target code is running (toggle LED test)
  • Check cable connections
  • Disable Windows firewall (for TCP/IP mode)
  • Try different USB port (for Serial mode)

๐Ÿ“น See it in action: XCP External Mode (2:18) ยท All demos โ†’

See Also

Quick Start Guide | Board Templates | PIL Simulation | User Guide