SNOAAA7 April 2024 LMG3522R030
For a better understanding of C-Script processing, Figure 3-1 provides an overall introduction of project structure and the C-Script function. Code declaration, start function, output function, and update function are used in block. For a detailed explanation of built-in functions and update logic, see the PLECS® C-Script user manual.
Some C-Script setups also need to be made in the C-Script block. Figure 3-2 shows an overview of the setup. The number of inputs represents the input signals from the power stage or other signals generated by other blocks, the number of outputs represents the number of output signals. An important parameter is the sample time, 83ns is set which means the frequency is 120MHz, same as 280039. This also means that the C-Script is simulated in continuous mode, similar to real MCU processing.
Next, a brief introduction of the code function is provided, in which global declarations and definitions are made. For example, in control loop, the inductor current and output voltage are sampled and need to be input to the C-Script block, so a built-in macro is used to define the input signal here. All parameters are initialized in the function.
Global variables defined in code declarations are initialized in the start function.
For example, the voltage loop and current loop reference is initialized as in Figure 3-4.
The update function is the main processing part of the C-Script. Control loop calculation, output voltage sampling, sawtooth, and sinusoidal wave generator, and dead-time control are all accomplished in the update function. For example, AC voltage is sampled at 20kHz.
The desired signal and port outputs are set in the
output function. Also, the PWM signal is defined. For example, Figure 3-6 shows how the twentieth port output is defined as the RMS value of sample AC
voltage. OutputSignal
is the built-in C-Script macro.
Section 3.2 discusses implementation of different blocks.