Navigation
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 option | USB-UART bridge | Typical baud | When to use |
|---|
| XCP on Serial | Board’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-2 | 115 200 โ 460 800 baud | Default โ a single USB cable to the board provides both programming and External Mode. |
| XCP on USB | External FTDI FT232H USB-to-UART cable (e.g., C232HD-DDHSP-0 / C232HD-EDHSP-0) wired to a free UART of the target | Up to 12 Mbaud | When 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:
- 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.
- TX/RX pins routed: target UART TX/RX assigned to the physical pins connected to that bridge.
- 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
Step 1: Enable External Mode in Simulink
- Open Model Configuration Parameters (
Ctrl+E) - Navigate to: Code Generation โ Interface
- Check “External mode” checkbox
- Select transport layer XCP on Serial โ this covers both wiring options (board’s integrated USB-UART bridge and external FTDI USB-UART cable).
- 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
Ensure your model includes a UART block configured for External Mode:
- Add a UART block from the MCHP Blockset library
- Configure UART settings:
- Baud rate: Must match External Mode setting
- TX/RX pins: Assign to physical pins connected to PC
- 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
- Build the model (
Ctrl+B)- External Mode communication code is automatically included
- Program the target microcontroller via your programmer (ICD, PICkit, etc.)
- Connect communication cable between PC and target board
Step 5: Connect and Monitor
In Simulink:
- Click “Connect to Target” button in toolbar (or press
Ctrl+K) - Wait for connection confirmation (status bar shows “Connected”)
- Click “Start Real-Time Code” (or press
Ctrl+T) - Observe signals in Simulink scopes updating in real-time
To modify parameters:
- Double-click a tunable parameter or constant block
- Adjust the value using the slider or numeric entry
- Changes take effect immediately on hardware
- 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
- Right-click the block parameter (e.g., Gain block’s “Gain” parameter)
- Select “Tune Parameter…”
- Check “Tunable” checkbox
- Optional: Set min/max limits for safety
- Rebuild the model
Method 2: Constant Block
- Use a Constant block instead of hardcoding values
- Right-click the Constant block โ Properties
- Check “Tunable”
- 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).
External Mode adds communication overhead to your embedded application:
| Aspect | Impact | Recommendation |
|---|
| CPU Overhead | 5-15% depending on logged signals | Minimize number of logged signals |
| Communication Latency | 10โ100 ms depending on baud and number of streamed signals | Move 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 Rate | Limited by communication bandwidth | Serial @ 115200 baud: ~1 kHz max Serial @ 460800 baud: ~5 kHz max Ethernet/USB: ~100 kHz max |
| Memory Usage | Additional 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:
- Verify communication cable: Check physical connection between PC and target
- Check COM port: Ensure correct COM port is selected in External Mode settings
- Verify UART configuration: Confirm UART block baud rate matches External Mode setting
- Check target is running: Toggle an LED to verify code is executing
- 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:
- Reduce number of logged signals: Too many signals saturate communication bandwidth
- Increase UART baud rate: Try 230400 or 460800 instead of 115200
- Check for electrical noise: Poor cable quality or EMI can corrupt data
- 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:
- Verify parameter is tunable: Right-click parameter โ check “Tunable” is enabled
- Rebuild model: Parameter tunability is set at compile time, requires rebuild
- Check parameter is not optimized away: Some unused parameters may be eliminated by compiler
- 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