**S-Function**

346 Grid Computing – Technology and Applications, Widespread Coverage and New Horizons

 Parameter Adjustment: Once the control algorithm is fixed, it is easy to modify the values of references and constants in the control code by directly modifying memory locations. This can be performed while the system is operational, allowing for quick adjustments to be made. If the control algorithm were implemented in analog

 Backtracking: The use of software allows for easy backtracking when the control algorithm is not working. If the control were implemented in analog circuits, the physical modifications would need to be reversed, which may also introduce additional

Many control techniques have been applied to the inverter power supply as mentioned in previous works (Abo Eldahb, 2011). In this study, we newly apply a controlling algorithm which is a two layer control. This algorithm is a combined feed-forward control and feedback control. This control algorithm can significantly improve performances over simple feedback control whenever there is a major disturbance that can be measured before it affects the process output. The basic configuration of the proposed controlling algorithm is

The Proportional Integral (PI) controller control algorithm has been one of the most utilized control techniques in the industry. It has proven its wide range of applications, and it was first introduced to the market in 1939 ((Ho. et al.1999). The main reasons for using PI controller are

To improve the accuracy of both the steady state response and transient response and to minimize the output disturbance, a feed-forward control is added to the classical PI

> 1 () () () *k*

(2)

*n u K e k kT e n r k* 

Where: Kp and Ki, are the Proportional, Integral coefficient, respectively, upi is controller

When the switching time is coming, the deviation between the target output and the actual output is calculated and this deviation is used to modify the controller output. The output of the PI controller must be within specific interval in order to protect the circuits. The modulation factor m is calculated with respect to the controller output. The controller algorithm was applied to both the DC/DC converter and DC/AC inverter separately and it was implemented using the SH7047 microprocessor. In the MILS environment, S-Function Block is used as the interface block to test the embedded software and to optimize the parameters. Details of the S-Function will be described in the next section. Each of the inverter power supply stages has its own C-MEX file which describes part of the embedded software. This C-MEX file is compiled to the S-Function Block, and then the output of the S-

its simple structure, easy to implement in the practical applications and its flexibility.

controller. Then the controller equation can be described through equation (2).

*pi p i*

output , e(k) is the error signal and r(k) is the feed-forward signal.

Function block acts as the simulation of the microprocessor unit.

changing several lines of codes, which will take only several minutes.

hardware, this would not be as easy to complete such a process.

errors in the process.

shown in Figure 18.

simple, slow control algorithms first to verify that the hardware is functioning correctly before moving to a higher performance or complex control algorithm. If hardware were used to do this, this would mean separate hardware designs and implementations for each algorithm. With the use of software, modifying the control algorithm means

> The S-Function provides a powerful mechanism for extending the capabilities of the Simulink environment. It is a computer language description of the Simulink block written in MATLAB, C, C++, and/or FORTRAN. S-Functions are compiled as MEX-files using the MEX utility (The MathWorks web site). The S-Function uses a special calling syntax called the S-Function API (Application Program Interface) that enables the user to interact with the Simulink engine. The interaction is very similar to the interaction that takes place between the engine and the built-in Simulink blocks. S-Function follows a general form and it can accommodate continuous, discrete and hybrid systems. It allows the user to implement different algorithm and to add them to the Simulink model.

> Two S-Function Blocks are designed: one to describe the DC/DC control unit, which is the MMT unit and the other S-Function is used for the MTU unit which controls the second stage, DC/AC stage. The embedded C codes are compiled to the S-Function Block, as shown in Figure 19. In the first step, all the electrical circuit parameters are tested and then, in the second step, the embedded software is tested using the S-Function.

> The S-Function and the C-MEX file have the same name and if the MATLAB path includes a C-MEX file and M file having the same name, the S-Function uses the C-MEX file. After the S-Function name is set, then the S-Function parameters are defined. The parameters include the PI controller parameters which are the Kp and Ki, the proportional coefficient and the integral coefficient. Further, the dead time value (TD) is set. The parameters and the name of

Potential of Grid Technology for Embedded Systems and Applications 349

The data can be displayed and sent to the MATLAB workspace for further analysis by using the scope blocks. The scope block is used to measure and monitor the signal at each point in the model, which allows the user to check the model operation at each point, as shown in Figure 21. This figure presents the entire inverter power supply model which is the MILS environment. The embedded software parameters are optimized and the system

Actual prototype of inverter power supply has been fabricated using Renesas SH microprocessor. The output voltage and the frequency of the inverter power supply are verified and the responses of the inverter power supply in the existence of loads are checked to confirm the efficiency of the control algorithm. Some of the results are shown below in

performance is tested as well as the verification of the control algorithm is done.

Fig. 21. Virtual environment of the inverter power supply

Fig. 22. Output of inverter power supply: (a) Actuals (b) Simulation

**8. Experimental results** 

Figure 22.

the S-Function are defined using the function block parameter then the main C code can be generated then the user can modified this C code until the embedded software is completed .So, the value of the parameters in the S-Function is initialized in the C-MEX file, and then this values will be updated during the simulation process. The updated values can be tested using the S-Function Block parameters for both DC/DC S-Function and DC/AC S-Function, as shown in Figure 20.


Fig. 19. Block parameter dialog box of DC/DC S-Function


Fig. 20. S-Function parameter block

348 Grid Computing – Technology and Applications, Widespread Coverage and New Horizons

the S-Function are defined using the function block parameter then the main C code can be generated then the user can modified this C code until the embedded software is completed .So, the value of the parameters in the S-Function is initialized in the C-MEX file, and then this values will be updated during the simulation process. The updated values can be tested using the S-Function Block parameters for both DC/DC S-Function and DC/AC S-

Function, as shown in Figure 20.

Fig. 19. Block parameter dialog box of DC/DC S-Function

Fig. 20. S-Function parameter block

The data can be displayed and sent to the MATLAB workspace for further analysis by using the scope blocks. The scope block is used to measure and monitor the signal at each point in the model, which allows the user to check the model operation at each point, as shown in Figure 21. This figure presents the entire inverter power supply model which is the MILS environment. The embedded software parameters are optimized and the system performance is tested as well as the verification of the control algorithm is done.

Fig. 21. Virtual environment of the inverter power supply
