**7.2.1 Control algorithm**

Traditionally, the implementation of switching type inverter power supply has been accomplished by using the analog technique. However, the analog technique has some drawbacks such as a number of parts required in the system and its susceptibility to ageing and environment variations, which lead to high cost of maintenance. Further, analog control once designed is inflexible and its performance cannot be optimized for various utility distortions. Now with the advent of high speed, lower cost digital signal processing (DSP) ICs, and microprocessors, digital control has become one effective candidate for inverter power supply.

Using a DSP or microprocessor has many benefits that make it attractive for use in control systems, such as:

 Flexibility of Control: When using analog circuits to perform control, the control algorithm is fixed, and is not easily modified. Using a microprocessor allows the designer to change the control code very quickly. It is often helpful to implement

Potential of Grid Technology for Embedded Systems and Applications 347

The standard method for generating PWM pulses by using a microprocessor or DSP is to utilize one of the built-in PWM modules. In our model, the System Function (S-Function) Block is used to compile the embedded system software to control DC/DC and DC/AC circuits. C programs implement the operations of the microcontroller's control units, that is, MMT which controls the generation of the PWM pulses in the DC/DC and MTU which controls the generation of the PWM in DC/AC stage. These programs are embedded into

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

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

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

Fig. 18. Simplified block diagram of the proposed control system

the S-Function Block, as shown in the lower part of Figure 21.

different algorithm and to add them to the Simulink model.

second step, the embedded software is tested using the S-Function.

**7.2.2 PWM generation program** 

**S-Function** 

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 changing several lines of codes, which will take only several minutes.


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 shown in Figure 18.

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 its simple structure, easy to implement in the practical applications and its flexibility.

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 controller. Then the controller equation can be described through equation (2).

$$
\mu\_{pi} = K\_p e(k) + k\_i T \sum\_{n=1}^{k} e(n) + r(k) \tag{2}
$$

Where: Kp and Ki, are the Proportional, Integral coefficient, respectively, upi is controller output , e(k) is the error signal and r(k) is the feed-forward signal.

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-Function block acts as the simulation of the microprocessor unit.

Fig. 18. Simplified block diagram of the proposed control system
