主要内容

Export Controller Algorithm Custom Targets

R2026b

In this step of the LLC Resonant Converter Controller Design Workflow example, you generate portable C code for the LLC resonant converter voltage controller so it can be integrated with a target that is not directly supported by an Embedded Coder® hardware support package. To get started, open the project and click the Algorithm Export shortcut on the project toolstrip. The shortcut opens this live script so you can step through it top to bottom.

To integrate the LLC resonant converter voltage controller with a target that is not directly supported by an Embedded Coder hardware support package, use the algorithm export workflow below to produce portable C code. Run this stage only after the earlier stages have produced validated, deployment-ready gains (desktop tuning with online frequency response estimation (FRE), robustness verification through Stability and Sensitivity Analysis, and hardware-in-the-loop (HIL) re-tuning with hardware FRE), so that the exported code embeds the final compensator, not the analytical starting point.

The workflow has two stages:

  • Prepare the deployment-ready controller parameters.

  • Generate C code for the voltage controller.

Prepare Controller Gains

To produce the numerical gains embedded by the exported code, simulate LLCCalcCtrlParamsAlgoEx.slx. The model reuses the plant parameters and controller sample time from the earlier stages, computes the discrete-time gains, and returns them in the simulation output.

parammodel = 'LLCCalcCtrlParamsAlgoEx';
load_system(parammodel);
SimOutCtrlParams = sim(parammodel);
close_system(parammodel);

To make the computed gains available to the code generator as tunable parameters, load them into Simulink.Parameter objects in the base workspace. Wrapping the gains as Simulink.Parameter objects lets the code generator emit them as global variables in dedicated C files, which is what most production integrations expect.

AlgoExLoadSLParameters;

Generate C Code

To produce the deployment artifacts for the LLC resonant converter voltage controller, build LLCControllerAlgoEx.slx. The model is preconfigured to generate an initialize function and a step function so the controller has a clear public interface for the target integration. Controller parameters and controller limits are emitted as separate C files so you can update gains without regenerating the algorithm code.

algoexmodel = 'LLCControllerAlgoEx';
load_system(algoexmodel);
slbuild(algoexmodel);

See Also

Topics