# How to change circuit parameters during simulation ⚙️

**URL:** <https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52>\
**Category:** Q&A\
**Tags:** sps-software\
**Created:** [March 16, 2026, 5:50pm UTC](https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52 "2026-03-16T17:50:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeylaErdan](https://avatars.discourse-cdn.com/v4/letter/l/aeb1de/32.png) [@LeylaErdan](https://community.opal-rt.com/u/LeylaErdan)\
**Post date:** [March 16, 2026, 5:50pm UTC](https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52/1 "2026-03-16T17:50:57Z")

</div>

A common question when running models in SPS Software is whether it is possible to tune parameters on the fly without stopping the simulation.

Here is how SPS Software handles parameter changes and how you can automate multiple scenarios using MATLAB® scripts.

### 🛑 General Rule: Re-initialization

Each time you change a parameter of an SPS Software library block (like a resistance, inductance, or machine inertia), you generally have to **restart the simulation**. This is because the software needs to re-evaluate the state-space model and update the matrices for the linear and nonlinear parts of your circuit during the initialization phase.

### ⚡ The Exception: Source Parameters

You **can** change the parameters of electrical sources during the simulation!  
If you modify the **Magnitude, Frequency, or Phase** of an AC or DC source block, the modification takes place immediately as soon as you click _Apply_ or close the block menu. This is great for manually testing voltage dips or frequency variations on the fly.

* * *

### 🚀 Pro-Tip: Automating Parametric Studies

If you need to test multiple values for a passive component (like finding the worst-case scenario for an inductor), you don’t need to change it manually and click “Run” every single time.

You can enter a MATLAB variable (e.g., `L1`) in the block’s parameter dialog instead of a fixed number, and use a script to loop through the simulation.

**Example: Finding the worst-case overvoltage**  
Suppose you have a model named `my_circuit` and you want to test an inductance (`L1`) from 10mH to 100mH to see which value causes the highest overvoltage (`V1`).

Here is a clean MATLAB script you can use to automate this parametric study:

```matlab
% 1. Define the range of values to test (10 mH to 100 mH in 10 steps)
L1_vec = (10:10:100) * 1e-3; 

% 2. Initialize the maximum voltage tracker
V1_max = 0;

% 3. Loop through each value
for i = 1:10
    
    % Assign the current value to the workspace variable used in the block
    L1 = L1_vec(i);
    fprintf('Test No %d: L1 = %g H\n', i, L1);
    
    % Run the simulation
    sim('my_circuit'); 
    
    % Memorize the worst case (assuming V1 is saved to the workspace via ToWorkspace block)
    if max(abs(V1)) > V1_max
        imax = i;
        V1_max = max(abs(V1));
    end
    
end

% 4. Display the final result
fprintf('Maximum overvoltage %g V occurred for L1 = %g H\n', V1_max, L1_vec(imax));

```

This approach saves you hours of manual work and ensures you never miss a critical operational point in your design!

---

<div class="post-metadata">

**Author:** ![higuain1995](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@higuain1995](https://community.opal-rt.com/u/higuain1995)\
**Post date:** [August 14, 2026, 1:12am UTC](https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52/3 "2026-08-14T01:12:07Z")

</div>

Hi, does this method work for real-time simulation execution in RT-LAB?

---

<div class="post-metadata">

**Author:** ![Parija](https://yyz2.discourse-cdn.com/flex012/user_avatar/community.opal-rt.com/parija/32/161_2.png) [@Parija](https://community.opal-rt.com/u/Parija)\
**Post date:** [August 18, 2026, 6:58pm UTC](https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52/4 "2026-08-18T18:58:49Z")

</div>

Hello  
Great question! The short answer is: the same logic applies in RT-LAB, but with some important real-time constraints to keep in mind.

Passive component changes still require a restart.

Just as in SPS Software offline simulation, modifying parameters of passive library blocks (resistances, inductances, capacitances, machine inertia, etc.) in an RT-LAB model requires stopping the simulation and reloading the model onto the target. This is because RT-LAB compiles the Simulink model into C code and deploys it to the real-time target; the state-space matrices are fixed at load time and cannot be restructured mid-execution.

Source parameters can be changed on the fly

The live-edit exception for source Magnitude, Frequency, and Phase also holds in RT-LAB. You can modify these through RT-LAB’s visualization and control panel during execution, and the change takes effect immediately — no reload required. This is particularly useful for testing voltage dips or frequency deviations in HIL scenarios.

Automating parametric sweeps in RT-LAB

The MATLAB workspace variable approach described above does work with RT-LAB, with one key adaptation: instead of calling sim(‘my\_circuit’) directly, you use the RT-LAB API (available in MATLAB, Python, or C/C++) to control the simulation lifecycle on the target. The general pattern becomes:

% Loop through parameter values  
for i = 1:10  
L1 = L1\_vec(i);  
% Load and start the model on the RT-LAB target  
rtlab\_load(‘my\_circuit’);  
rtlab\_start();  
% Wait for simulation to complete or reach steady state  
pause(sim\_duration);  
% Acquire signals via RT-LAB API or OpComm/ToWorkspace blocks  
% … signal acquisition logic here …  
rtlab\_stop();  
end  
The exact API calls will depend on your RT-LAB version and whether you are using the MATLAB API, the Python rtlabapi package, or a custom interface. Refer to the RT-LAB Comprehensive API documentation for the current function signatures.

One additional consideration for real-time execution

Because RT-LAB runs on a deterministic real-time OS (OPAL-RTLinux), each load → start → acquire → stop cycle carries a small overhead for compilation (if the model has changed) and target synchronization. For large parametric sweeps, it is worth pre-compiling the model once and only varying the workspace variable between runs to avoid repeated compilation delays.

---

<div class="post-metadata">

**Author:** ![higuain1995](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@higuain1995](https://community.opal-rt.com/u/higuain1995)\
**Post date:** [August 21, 2026, 5:48am UTC](https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52/5 "2026-08-21T05:48:44Z")

</div>

@Parija Thank you for your reply. I am currently working with the RTLAB API. I have a question: Are there specific API functions available to modify parameters of the eHS circuit in real-time during execution? I understand that modifying parameters solely in the MATLAB workspace is not sufficient, as the generated code runs within RTLAB. Therefore, there should be relevant API functions to adjust the passive component parameters of the circuit to support this operation.

---

<div class="post-metadata">

**Author:** ![PFA007](https://yyz2.discourse-cdn.com/flex012/user_avatar/community.opal-rt.com/pfa007/32/120_2.png) [@PFA007](https://community.opal-rt.com/u/PFA007)\
**Post date:** [August 28, 2026, 1:29am UTC](https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52/6 "2026-08-28T01:29:26Z")

</div>

Before updating parameters via API during execution:

Static Passive Components (Fixed R, L, C): Standard passive components compiled in Schematic Editor are converted into fixed matrix coefficients on the FPGA. They cannot be changed arbitrarily at runtime without recompilation.

Variable / Non-Linear Components: To change a passive component (e.g., variable resistor, dynamic load, fault resistance) in real-time, it must be configured as a Variable Component in OPAL-RT Schematic Editor.

Once defined as variable, Schematic Editor creates corresponding input ports on the eHS S-Function block in Simulink (or eHS core inputs).

---

<div class="post-metadata">

**Author:** ![higuain1995](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@higuain1995](https://community.opal-rt.com/u/higuain1995)\
**Post date:** [August 28, 2026, 1:57am UTC](https://community.opal-rt.com/t/how-to-change-circuit-parameters-during-simulation/52/7 "2026-08-28T01:57:50Z")

</div>

@PFA007 Okay, thank you for your reply. Is support for variable/non-linear components dependent on the eHS and RTLAB versions, or is it only possible on eHS Gen5?
