Contenu principal

Configure and Simulate PFC Boost Converter Controller

R2026b

In this step of the PFC Boost Converter Controller Design Workflow example, you configure the plant model and cascaded current and voltage controller for simulation. To get started, open the project and click the Configure and Simulate shortcut on the project toolstrip.

In this stage you build the Simscape™ Electrical™ plant subsystem for the Classical or Totem-pole PFC boost converter topology, configure the inner current and outer voltage controller subsystem references with default or custom proportional-integral (PI) gains, and validate the closed-loop response in simulation. The gains produced here are written to ctrlData.mat and are the starting point that every downstream stage of the project (frequency response estimation (FRE) tuning, stability and sensitivity analysis, and algorithm export) consumes.

Workflow

This project walks you through the complete design and deployment workflow for a Power Factor Correction (PFC) boost converter controller. By following the steps below, you will:

  • Build the plant model (electrical circuit) and controller

  • Compute default controller gains and run a closed-loop simulation

  • Estimate the converter frequency response for accurate controller tuning

  • Analyze stability margins and sensitivity under varying operating conditions

  • Export the control algorithm to C code for hardware deployment

Each step in the workflow is connected to the next through subsystem references and MAT-file datastores, so outputs from one step automatically propagate as inputs to the subsequent steps.

Model the PFC Boost Converter

Begin by defining the converter hardware parameters. The file "PFCPlantParameters.m" contains all default electrical parameters for the PFC boost converter. If your hardware differs from the defaults, edit this file to add or modify converter data. The parameters defined here are used throughout the rest of the workflow. Models, controller tuning, and code generation all depend on them.

% Select the PFC converter topology
PFCConfig = 'Classical'; % Classical, Totempole

% Get the parameters as per the selected topology
PFCConv = PFCPlantParameters(PFCConfig);

Model the PFC Controller

Next, set up the controller. The subsystem reference models located in ~\ModelComponents\Controller implement a cascaded voltage and current controller matched to your selected topology. You have two options for setting the controller gains: use the automatically computed default gains, or supply your own custom gains. Both options are described below.

Ts       = 1/PFCConv.fsw;       % Current controller sample time [s]
TsVolt   = Ts * 50;             % Voltage controller sample time [s]
TsPlant  = 1/(50*PFCConv.fsw);  % Converter sample time for simulation [s]

GainSelector = 1;               % 1: default, 0: Custom gains

Default Controller Gains

If you are starting fresh, use the default gains. The "PFC Controller Gains" block automatically computes gains from the converter parameters and sample times defined above. When you run the "SimulateBoostPFC.slx" model, these default gains are saved to 'ctrlData.mat' at the end of simulation — ready for use in subsequent workflow steps.

Custom Controller Gains

Once you have tuned gains to your satisfaction (for example, using the Frequency Response Estimation workflow described later), you can store them as custom gains. The "PFC Converter Gains" block reads custom gains from 'ctrlData.mat'. Use the code below to update the custom gains and save them:

prjPath = matlab.project.rootProject().RootFolder;
matFile = fullfile(prjPath, 'Data', 'ctrlData.mat');
load(matFile); % Loads the structure ctrlData
ctrlData.Custom.kpvolt      = 0.2658;         % Kp for Voltage PI Control
ctrlData.Custom.kivolt      = 0.0030/TsVolt;    % Ki*Ts for Voltage PI Control
ctrlData.Custom.kpcur       = 0.1486;           % Kp for Current PI Control
ctrlData.Custom.kicur       = 0.0084/Ts;        % Ki*Ts for Current PI Control
ctrlData.Custom.timestamp   =  datetime;
save(matFile, 'ctrlData');

Simulate the model

With the converter and controller parameters in place, you are ready to run a closed-loop simulation. Open the model below and press Run. The model uses variant subsystems for both the converter and controller, so it automatically adapts to your selected topology. Use the simulation results to verify that the controller achieves the desired steady-state and transient performance before proceeding to further analysis or code generation.

simModel = "SimulateBoostPFC";
open_system(simModel);

Tune the controller and analyze sensitivity

The default gains computed earlier are derived from an analytical transfer function of the converter plant. While this is a good starting point, analytical models have limited ability to capture the true frequency response of the converter, where parasitic elements, nonlinearities, and digital implementation effects are often missing. For a more accurate plant characterization, this project provides a Frequency Response Estimation (FRE) workflow that extracts the plant dynamics directly from simulation.

Once you have an accurate plant model, you can use the Stability Margins and Sensitivity Analysis script to evaluate how robust your controller design is. It reports gain margin, phase margin, crossover frequency, and sensitivity peaks — and shows how these metrics vary across different operating conditions (load, output voltage, input voltage, and component tolerances).

Obtain PFC Boost Converter frequency response

The script below demonstrates how to estimate the open-loop frequency response of the PFC boost converter plant as seen by the inner current control loop. Understanding this plant transfer function is the foundation for accurate controller tuning.

How it works: The Frequency Response Estimation (FRE) block from Simulink Control Design characterizes the plant transfer function from duty cycle to inductor current. To create a valid linearized operating point, the AC source is replaced with a DC source (fixing the input voltage), both PI controllers are deactivated (opening the loop), and a perturbation signal is injected at the duty cycle output. The resulting inductor current response is then used to extract the plant frequency response.

The result captures the small-signal dynamics of the power stage, including the inductor, switch network, and output capacitor, giving you an accurate basis for designing and tuning the current loop controller.

edit OnlineFRE.m;

Analyze sensitivity and stability

After estimating the plant frequency response, use the script below to evaluate your controller's robustness. The sensitivity analysis reports key metrics — gain margin, phase margin, crossover frequency, and sensitivity peaks — that tell you how much design margin your controller has before stability is compromised. It also sweeps operating conditions to reveal which scenarios are most critical.

% Margins, Stability and sensitivity
open StabilityAndSensitivityAnalysis.m

Deploy in hardware

Once you are satisfied with the controller's performance in simulation, the final step is to deploy it on real hardware. This section guides you through exporting the algorithm as standalone C code.

Export algorithm to C code

Alternatively (or additionally), you can export the control algorithm as C code for integration into your own firmware. The steps below prepare the control parameters and then invoke Simulink Coder to generate the code.

Step 1 — Prepare control parameters: First, load the hardware parameters into the Converter Controller Parameters block, then simulate the model to compute the final control parameters for the Converter Voltage Controller.

PFCConfig = 'Classical';

% Get the parameters as per the selected topology
PFCConv = PFCPlantParameters(PFCConfig);

Ts       = 1/PFCConv.fsw;       % Current controller sample time [s]
TsVolt   = Ts * 50;             % Voltage controller sample time [s]

GainSelectorCodeGen = 1; % 1: default, 0: Customer gains

prjPath = matlab.project.rootProject().RootFolder;
matFile = fullfile(prjPath, 'Data', 'ctrlData.mat');
load(matFile); % Loads the structure ctrlData

Next, load the computed gains into |simulink.parameter| objects. This ensures that the code generator outputs them as global variables in separate C files, making it easy to integrate with your firmware build system.

LoadSimulinkParameters;

Generate C code

Step 2 — Generate C code: The code below invokes Simulink Coder to generate C code for both the current and voltage controllers. Each model is pre-configured to produce an initialize function and a step function — these are the two entry points your firmware will call. Controller parameters and limits are generated as separate C source and header files for easy maintenance.

CurrentControlModel = 'CurControllerAlgoEx';
VoltControlModel = 'VoltControllerAlgoEx';
load_system(CurrentControlModel);
slbuild(CurrentControlModel);
load_system(VoltControlModel);
slbuild(VoltControlModel);

Finally, generate the control parameters and limits as standalone C source and header files:

ParameterModel = 'GenParamsCode';
load_system(ParameterModel);
slbuild(ParameterModel);

See Also

Topics