PLECS Coder

 

Generate C Code from a PLECS Model

The PLECS Coder generates ANSI-C code from a simulation model. This code can be compiled to execute on the simulation host or a separate target, such as an embedded control platform, hardware-in-the-loop (HIL) system, or real-time digital simulator. A typical application of code generation is to execute a PLECS model in real-time as a virtual plant for the verification and validation of control hardware and software. Generated code can also be compiled and executed on the host to reduce the simulation time of complex models.

Direct Code Generation

The PLECS Coder produces generic ANSI-C code from a PLECS Blockset or PLECS Standalone model. The model to be translated into code can be a physical system or control logic. The PLECS Coder also fully integrates with Simulink Coder® (formerly Real-Time Workshop). When the user starts the build process, PLECS automatically generates the code for the system of interest and inserts it in the appropriate locations in the code generated from the Simulink model. PLECS can generate code for two different targets: the Rapid Simulation target (or RSim target) and the Real-Time target. By default, PLECS automatically selects the correct target depending on the target settings of Simulink Coder.

Code Ready for Deployment

PLECS can also produce code for a specific hardware target. Target support packages permit customizing the code generated for virtually any CPU/MCU-based platform. A simple association between signals in a PLECS model and the physical input and output pins on a target is made directly in the PLECS schematic via I/O blocks.

  • RT Box Target

    ​The RT Box Target support package for PLECS Standalone directly targets the PLECS RT Box. The PLECS RT Box component libary contains blocks for configuring general analog and digital inputs and outputs to and from the unit. Specialized blocks are included for capturing PWM signals from a controller and generating quadrature encoder signals directed to a controller. Below is an example of an offline PLECS model schematic of a three-phase solar inverter system where real-time capable code for the plant, incoming PWM signals, and outgoing current and voltage measurement signals can be generated using the PLECS Coder.

The PLECS Coder External Mode allows the user to connect an offline PLECS model with a real-time model running on the RT-Box in order to tune parameter values on the target and display captured online data in a PLECS Scope.