PLECS Demo: BuckParamSweep.plecs
BuckParamSweep.plecs Open this model

Closed-loop Controlled Buck Converter

This demonstration is based on the Closed-loop Controlled Buck Converter demo model. It performs a parameter sweep by modifying the value of inductor L1 from a simulation script.

For each parameter value a simulation is performed. The result of each simulation is displayed as new trace in the scope. The script also analyses the simulation result and prints the peak current.

% create filename independent path to scope
mdl = plecs('get', '', 'CurrentCircuit');
scope = [mdl '/Scope'];

% create simStruct with field 'ModelVars'
mdlVars = struct('varL', 50e-6);
simStruct = struct('ModelVars', mdlVars);

plecs('scope', scope, 'ClearTraces');

inductorValues = [50, 100, 200];
for ix = 1:length(inductorValues)
  % set value for L1
  simStruct.ModelVars.varL=inductorValues(ix) * 1e-6;
  % start simulation, return values in 'out'
  out = plecs('simulate', simStruct);
  % add scope run
  plecs('scope', scope, 'HoldTrace', ['L=' mat2str(inductorValues(ix)) 'μH']);
  % find maximum current value and index
  [maxv, maxidx] = max(out.Values(1,:));
  % Output values to Octave console
  printf('Max current for L=%dμH: %fA at %fs\n', 
         inductorValues(ix), maxv, out.Time(maxidx));
end

To run the demonstration, select Simulation scripts... from the Simulation menu and run the Parameter Sweep script.

Open this model