How to generate a DLL from a Simulink controller model and use it inside PSCAD?

23 views (last 30 days)
Hi,
I have designed a control model in Simulink , and I want to use the same controller as a DLL inside PSCAD.
Can someone guide me on:
  1. How to generate a DLL from my Simulink model using Embedded Coder?
  2. What settings are required so that PSCAD can call the DLL (initialize, step, and terminate functions)?
My goal is simply to use the Simulink-designed controller inside PSCAD.
What is the correct workflow for this?
Thank you.

Answers (1)

Akanksha
Akanksha on 21 Nov 2025 at 9:23
Edited: Akanksha on 21 Nov 2025 at 9:36
Hey Sohail,
To connect your Simulink model with PSCAD, the main idea is to first generate a shared library (DLL) from Simulink and then call its functions from PSCAD. Start by opening the Configuration Parameters → Code Generation section in your Simulink model. Set the System Target File to "ert_shrlib.tlc", choose C as the language, and enable the Generate shared library option. When you build the model, Simulink will automatically create three important files: the DLL (model.dll), the header file (model.h), and the import library (model.lib). Kindly refer the following official docs for further information -
Next, PSCAD expects your generated DLL to contain three functions: "model_initialize()"(to be called once at the start), "model_step()" (to run at each simulation step), and "model_terminate()" (to clean up at the end). To ensure these functions are included, set the step method to Reusable function under Code Interface Packaging and enable both initialization and termination functions in your model settings. Kindly refer the following official docs for further information -
Finally, for integration, you simply need to provide PSCAD with the DLL, header file, and import library. In PSCAD, you’ll write a small wrapper to load the DLL and call the three functions in the correct order : "model_initialize()" at the start of the simulation, "model_step()" during each time step, and "model_terminate()" at the end. This process ensures PSCAD can successfully execute your model logic from the DLL. For additional clarity, you can refer to these MATLAB Answers discussions:
Hope this helps!

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!