Generate C Code from a PLECS Model
The PLECS Coder generates generic ANSI-C code from a PLECS schematic. The code can be compiled to execute on the simulation host or a separate target, such as an embedded control platform or real-time digital simulator. The model to be translated into code may be a physical system or control logic.
Code Ready for Deployment
The PLECS Coder can produce code for a specific hardware target. Target support packages (TSPs) 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 schematic via I/O blocks. Various TSPs are available at no additional charge so you can setup your environment with only the targets you need or easily explore others.
Automatic Code Generation for Microcontrollers
The PLECS embedded control platform targets each support code generation and External Mode operation for off the shelf microcontrollers (MCUs) from select manufacturers. Each target contains a unique component library including blocks to model and program the MCU peripherals for sensing and actuation. Embedded control logic can be implemented using standard PLECS library components. Multi-tasking code generation is possible, unlocking processing power for controls regulating multiple system outputs with dynamics on a range of time-scales.
There are two primary methods to deploy generated embedded code onto the MCU. You can directly program the target device from the PLECS application, or generate embedded C code for the specified target into a template integrated development environment (IDE) project specific to the manufacturer. Once the generated code is deployed on the target device, you can connect via the External Mode to inspect real-time signals and adjust controller set points and parameters on the fly.
Available TSPs for specific industry-grade microcontroller families include:
TI C2000 TSP | STM32 TSP |
Real-Time Simulation for Controller Hardware-in-the-Loop Testing
With hardware-in-the-loop (HIL) simulation, real control hardware is connected to a virtual plant model simulated on a real-time simulator. This approach allows easy verification and validation of the control hardware and software without an expensive power stage.
RT Box Target
The RT Box Target Support Package directly targets the PLECS RT Box. The TSP's component library 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 an external source and generating quadrature encoder signals directed to a controller. Further blocks are used for writing data to a file and communicating information using common protocols, e.g., SPI, CAN, UDP, EtherCAT, and EnDat.
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.
The 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.
Support for Third Party Tools
PLECS Blockset users can use PLECS Coder hand in hand with Simulink Coder®. When the build process is started, PLECS automatically generates code for the circuit block and inserts it in the appropriate locations.
The PLECS Coder Target developed by Imperix can be used to directly interface with their controller prototyping platforms, including the B-Box RCP unit and the B-Board PRO. For more information, to watch an introductory video and download the target, visit Imperix's website.
Simulink Coder | Imperix |