701 - GeckoSCRIPT Basics¶
GeckoSCRIPT is JavaScript-based scripting built directly into GeckoCIRCUITS, enabling automation without leaving the application. Powered by GraalVM Polyglot, it provides full access to the circuit simulator API from JavaScript.
What is GeckoSCRIPT?¶
GeckoSCRIPT is:
- Built-in JavaScript engine - No external tools needed
- Direct API access - Manipulate circuit parameters and run simulations programmatically
- Parameter sweeps - Automate multi-variable design space exploration
- Batch automation - Run hundreds of simulations sequentially
- Data export - Generate CSV/JSON results automatically
Opening the Script Editor¶
To access GeckoSCRIPT:
- Launch GeckoCIRCUITS with a circuit file
- Navigate to Tools → GeckoSCRIPT (or Tools → Script Editor)
- Write or paste your JavaScript code
- Click Run to execute
Tip
Scripts run in the same process as GeckoCIRCUITS, with direct access to loaded circuits and simulation state. No external processes required.
Script Structure¶
Basic Script¶
// GeckoSCRIPT example
var Vin = 48; // Input voltage
var Vout = 12; // Output voltage
var Iout = 10; // Output current
// Calculate duty cycle
var D = Vout / Vin;
print("Duty cycle: " + D);
// Set component parameter
setParameter("R_load", Vout / Iout);
// Run simulation
runSimulation();
// Get result
var efficiency = getMeasurement("P_out") / getMeasurement("P_in");
print("Efficiency: " + (efficiency * 100) + "%");
Core Functions¶
Parameter Control¶
// Set component parameters
setParameter("componentName.parameter", value);
// Examples
setParameter("MOSFET1.RdsOn", 0.01);
setParameter("C1.capacitance", 100e-6);
setParameter("L1.inductance", 50e-6);
// Get current parameter value
var L = getParameter("L1.inductance");
Simulation Control¶
// Configure simulation
setSimulationTime(0.01); // 10 ms
setTimeStep(1e-7); // 100 ns
setSolverType("GEAR"); // GEAR, TRZ, or BE
// Run simulation
runSimulation();
// Stop simulation
stopSimulation();
// Wait for completion
waitForSimulation();
Data Access¶
// Get measurement values (after simulation)
var Vavg = getMeasurement("SCOPE.CH1.mean");
var Irms = getMeasurement("SCOPE.CH2.rms");
var Ppk = getMeasurement("SCOPE.CH3.max");
// Get waveform data
var time = getWaveform("SCOPE.time");
var voltage = getWaveform("SCOPE.CH1");
Output and Export¶
// Print to console
print("Result: " + value);
// Export data to CSV
exportCSV("results.csv", ["time", "voltage", "current"]);
// Save circuit
saveCircuit("modified_circuit.ipes");
Parameter Sweeps¶
Single Parameter Sweep¶
var results = [];
var duties = [0.3, 0.4, 0.5, 0.6, 0.7];
for (var i = 0; i < duties.length; i++) {
setParameter("PWM1.dutyCycle", duties[i]);
runSimulation();
waitForSimulation();
var vout = getMeasurement("SCOPE.Vout.mean");
results.push({duty: duties[i], vout: vout});
print("D=" + duties[i] + " -> Vout=" + vout);
}
// Export results
exportResults("sweep_results.csv", results);
Multi-Parameter Sweep¶
var fsw_values = [50e3, 100e3, 200e3];
var L_values = [22e-6, 47e-6, 100e-6];
for (var i = 0; i < fsw_values.length; i++) {
for (var j = 0; j < L_values.length; j++) {
setParameter("PWM1.frequency", fsw_values[i]);
setParameter("L1.inductance", L_values[j]);
runSimulation();
waitForSimulation();
var ripple = getMeasurement("SCOPE.IL.pp");
print("fsw=" + fsw_values[i] + ", L=" + L_values[j] + " -> ripple=" + ripple);
}
}
Control Flow¶
Conditional Logic¶
var Vout = getMeasurement("SCOPE.Vout.mean");
if (Vout < 11.9) {
print("Output voltage too low!");
} else if (Vout > 12.1) {
print("Output voltage too high!");
} else {
print("Output voltage within spec");
}
Loops¶
// For loop
for (var i = 0; i < 10; i++) {
// ...
}
// While loop
var iteration = 0;
while (efficiency < 0.95 && iteration < 100) {
// Adjust parameters
iteration++;
}
Mathematical Functions¶
// Built-in math
var x = Math.sin(angle);
var y = Math.cos(angle);
var z = Math.sqrt(value);
var p = Math.pow(base, exponent);
var l = Math.log10(value);
// Constants
var pi = Math.PI;
var e = Math.E;
Error Handling¶
try {
runSimulation();
var result = getMeasurement("SCOPE.CH1.mean");
} catch (error) {
print("Error: " + error.message);
// Handle error
}
Running Scripts¶
From GUI¶
- Tools → Script Editor
- Write or load script
- Click Run
From Command Line¶
Simulation Exercises¶
- Write parameter sweep for optimal duty cycle
- Automate efficiency measurement vs load
- Generate Bode plot data with frequency sweep
- Create batch simulation for component comparison
Advanced Topics¶
Learning Resources
See the comprehensive GeckoSCRIPT documentation in the tutorial file: resources/tutorials/7xx_scripting_automation/701_gecko_script_basics/GeckoSCRIPT.pdf
Complete API Reference
For a complete API reference with all available functions, see the GeckoSCRIPT API Reference.