Defining Custom Functions Using the Integrated C-Compiler
The PLECS C-Script block allows versatile functionality to be implemented in the C programming language. At simulation start, the built-in compiler translates ANSI-C code on the fly to native machine code and links it dynamically into PLECS. The C-Script block provides very fine-grained interaction with the solver, allowing the design of advanced functionalities such as systems with multiple sample rates.
Typical applications where C-Scripts are useful include:
- Implementing complex non-linear and piecewise functions that would otherwise need to be modeled with complicated block diagrams
- Designing modulators or pulse generators that require exact but flexible time step control
- Incorporating external C code, e.g. for a DSP controller, into a simulation model
- Modeling state machines for controller-mode sequencing