Automatic Modelling Approach for Power Electronics Converters: Code Generation (C S Function, Modelica, VHDL-AMS) and MATLAB/Simulink Simulation

Modelling and simulation are useful for the analysis and design process of power electronics systems. Power electronics models of static converters are used for component sizing, for control adjustment or behaviour simulation. In this context, average models are a good compromise between complexity, computation time and acceptable accuracy for system simulation. So, the development of averaging methods has been a topic of interest for the power electronic community for over three decades (Chetty, 1982; Middlebrook & Cuk, 1976; Sun & Grostollen, 1992). The modelling of simple DC/DC structures is easy on the continuous conduction mode (Bass & Sun, 1998; Maksimovic et al., 2001; Maranesi & Riva, 2003; Rajagopalan, 1987; Webster & Ngo, 1992). However, the modelling complexity increases with the number of switches and the nature of the operating mode (the state sequences separated by the switch commutations). In this context, average operating analysis is becoming more and more complicated and the modelling requires skilful handling of complicated mathematical expressions which is generally time consuming. In the literature, several automatic averaged modelling techniques have been developed however they have many limitations. As (Sun & Grostollen, 1997) that proposes a package for the modelling of PWM structures, in hard or soft switching, but the modelling is only for power electronics structures alone. The automatic modelling of a three-phase electrical machine with static converter is not possible. So, the environment of the static converter is limited, e.g. the load can not be a three-phase synchronous machine. In the Electrical Engineering Laboratory (G2Elab), (Verdiere et al., 2003) proposes a new software architecture for the average modelling of power electronics structures, but this software is limited to the treatment of DC/DC converters in the continuous conduction mode, the classic average model is only obtained automatically. The same problem as (Sun & Grostollen, 1997), the automatic coupling of converter with electrical machine is not considered. Finally, the computing technologies used to the topological analyze of electrical circuit (e.g. Macsyma) are not up to date.


Introduction
Modelling and simulation are useful for the analysis and design process of power electronics systems.Power electronics models of static converters are used for component sizing, for control adjustment or behaviour simulation.In this context, average models are a good compromise between complexity, computation time and acceptable accuracy for system simulation.So, the development of averaging methods has been a topic of interest for the power electronic community for over three decades (Chetty, 1982;Middlebrook & Cuk, 1976;Sun & Grostollen, 1992).The modelling of simple DC/DC structures is easy on the continuous conduction mode (Bass & Sun, 1998;Maksimovic et al., 2001;Maranesi & Riva, 2003;Rajagopalan, 1987;Webster & Ngo, 1992).However, the modelling complexity increases with the number of switches and the nature of the operating mode (the state sequences separated by the switch commutations).In this context, average operating analysis is becoming more and more complicated and the modelling requires skilful handling of complicated mathematical expressions which is generally time consuming.In the literature, several automatic averaged modelling techniques have been developed however they have many limitations.As (Sun & Grostollen, 1997) that proposes a package for the modelling of PWM structures, in hard or soft switching, but the modelling is only for power electronics structures alone.The automatic modelling of a three-phase electrical machine with static converter is not possible.So, the environment of the static converter is limited, e.g. the load can not be a three-phase synchronous machine.In the Electrical Engineering Laboratory (G2Elab), (Verdiere et al., 2003) proposes a new software architecture for the average modelling of power electronics structures, but this software is limited to the treatment of DC/DC converters in the continuous conduction mode, the classic average model is only obtained automatically.The same problem as (Sun & Grostollen, 1997), the automatic coupling of converter with electrical machine is not considered.Finally, the computing technologies used to the topological analyze of electrical circuit (e.g.Macsyma) are not up to date.
The originality of this chapter consists to improve, on one hand, the work of (Sun & Grostollen, 1997) and (Verdiere et al., 2003), by proposing a new automatic methodology deals with several models (average and exact models) for DC/DC, DC/AC and AC/AC converters, and on other hand, by modelling converters with or without their environment (e.g.electrical machines).The particularities of this approach are the generation of models in different forms: C S-Function, VHDL-AMS, Modelica and the automatic treatment of the static converters in the continuous and discontinuous conduction mode.In this chapter, only results for the continuous conduction mode are presented.In the first part of this chapter, the modelling approach is explained and the main steps of this modelling are detailed.A causal approach for the modelling of static converters of a power electronics applications independently of their environment (i.e its sources and loads) is also presented.In the second part, the implementation in the software tool (AMG for Average Model Generator) dedicated to this automatic building is described.The code generation in C Sfunction, VHDL-AMS and Modelica is illustrated for a boost converter.In the last part, several applications results are presented and implemented in several software (e.g Matlab/Simulink), among them a resonant converter, a three phase inverter coupled with a three-phase machine and a multi-level converter.

Modelling approach
The modelling approach in the software tool AMG is defined by using an a priori on the static converter behaviour and considering some hypothesis (ideal switches OFF "open circuit" and ON "short circuit", linear and invariant passive components and perfect sources).Every model is entirely made in an automatic way from a topological description of the static converter.This description is carried out from a Netlist file extracted by using simulation software (i.e PSpice) and a dedicated simplified component library is used.The user must define the commutation mode (i.e the cyclic sequence of switched configurations in an operating period) and the switch control sequence of the static converter to be modelled, mainly the control links of switches.The switch control and the operating mode are deduced from the analysis of the studied static converter, e.g., by using simulation software (i.e Portunus, Psim, PSpice, Simplorer, Saber, etc.).These data information given by the user are introduced into the software tool AMG.The approach of the automatic building includes three important steps: 1. the analysis of the circuit, 2. the extraction of the state matrixes for each configuration of the static converter, 3. the building of the global state model.
Steps of modelling are presented in Fig. 1.

Topological analysis
An electrical circuit can be represented by a directed graph.The edges of this graph then connect the nodes of the circuit pairs.It is therefore possible to extract a tree of this graph corresponding to a subset of edges covering all nodes in the graph, but not forming mesh.The topological analysis is to automatically determine a tree from a simple description of the topology of the circuit.This method has been tested and used in different works (Delaye et al., 2004).Thus knowing the topology of any electrical circuit, it is possible to express the incidence matrix nodes/branches and then calculate the reduced incidence matrix.
In the incidence matrix, the rows correspond to nodes and the columns to the branches (see Fig. 2).After, this matrix is reduced for each state, according to the conduction state of switches.A switch at state ON is considered as "short-circuit": the lines corresponding to its nodes are added or subtracted (to keep a resulting line with only 0, 1 and -1).A switch at state OFF is considered as an "open circuit": the switch column is suppressed.Welsh algorithm is used to extract the relations between the voltages U and currents I of the circuit (Rajagopalan, 1987).It separates links components and branches variables: -Vmc, Vmr, Vml, Vmj are respectively the vectors of links voltages for the capacitors, the resistors, the inductors and the sources.-Vbc, Vbr, Vbl, Ve are respectively the vectors of branches voltages for the capacitors, the resistors, the inductors and the sources.-Ibe, Ibc, Ibr, Ibl are respectively the vectors of branches currents for the sources, the capacitors, the resistors and the inductors.-Imc, Imr, Iml, Ij are respectively the vectors of links currents for the capacitors, the resistors, the inductors and the sources.So, Kirchhoff laws and relations between, on the one hand, the branches voltage and current and on the other hand, between links voltage and current are easily deduced.We propose also a new extension of the Welsh algorithm that offers the possibility to deduce: -non fed components short-circuited components Finally, the topological analysis offers a first set of circuit equations in the form of relations between on the one hand, the branch current (Ib) and the link current (Im) and on the other hand, the branch voltage (Vb) and the link voltages (Vm).

State matrices
The state matrices of the static converter are extracted for each configuration from their simplified nodes equations.By combining the equations of voltage-current relations, a reduced state system is obtained (Kuo-Peng et al., 1997).

Building of the several models
The global global state model of the converter is made from the state equations for each configuration of the static converter.It consists in extracting the state system for each possible topology of circuit in order to create the converter model.The approach focuses on exact and average models (classic average model, equivalent average model, generalized average model and small signal average model).The models are generated according to the nature of the power conversion (DC/DC, AC/DC) and the operating mode (continuous conduction or discontinuous conduction).
A Comparison between several models generated by AMG is presented in table 1 (Merdassi et al., 2010).

The exact model
The exact model represents the starting point to any average modelling operation (Bacha et al., 1994).Regarding the state of the various switches, the converter can be considered as a variable structure system with N possible configurations during a given commutation period T.
) is defined by equation ( 8) in a corresponding time interval Where: T : the switching period.N: the number of topologies (configurations) that happen during the switching period T.
x : the state vector (size [n]).By assembling these N equations, considering the continuous character of the state variable (vector x) and by assigning a discrete switching function 1,1 − , representing both the operating mode and the control, the global behaviour of the static converter is formulated as the bilinear equation ( 10) (Sun & Grostollen, 1992).Note that p switching functions can describe 2 p configurations.
A: the global state matrix (size [n,n]).

The average model
The average value of the k th harmonic is defined by equation ( 11).Where: represents the harmonic coefficient of range k in the decomposition of the complex Fourier series.It's average is made on a sliding window and not on the static interval.AMG deals with the following types of static converters: DC/DC, DC/AC and AC/AC.It allows the automatic average modelling.In the literature, the following average models (classic average model, equivalent average generator, generalized average model and smallsignal average model) are well known and presented in the papers (Chen & Sun, 2005;Etxeberria-Otadui et al., 2002;Verdiere et al., 2003& Sanders et al., 1990).

Causality of the static converter
For the models of loads or sources that can not be simply described by a circuit representation, a Netlist or graphical approach is limited.So, it is useful to carry out models of static converters without the description of their environment, by using only knowledge on the connection points of the converter with its environment.Then, the obtained models of the static converters are introduced into the global application.Two possibilities are proposed: the static converter model is either oriented or non oriented, i.e. causal or non causal (Allain et al., 2009).

Oriented model
The global model of the static converter is described in a block (e.g. a C S-Function of Matlab/Simulink).Then, it is connected with the other blocks of the system.In this approach, the static converter is considered as a causal model, i.e. the solving sequence of its equations is imposed.So, the model has inputs and outputs.The figure 4 illustrates this causality in the meaning of block representation and Bond Graph representation for a single-phase voltage inverter.

Non oriented model
The causality of the static converter can be determined by respecting the definition given in Bond Graph representation (Karnopp et al., 1990), but applied in the electrical domain.The model can be described in a non causal modelling language, e.g.VHDL-AMS, Verilog or Modelica (for the analog part).This means that the model equations are not oriented.Then the model of the static converter is connected to the models of the components thanks to the modelling language.Finally, the compilers of such languages manage automatically the causality (so the solving sequence of the model equations) at the start of the simulation running.
Practically, the static converter environment is defined with equivalent sources.Thus, a voltage source or a current source is imposed at every connection point (Mohan et al., 1989).However, in power electronics, according to their value, inductors may be compared to current sources whereas capacitors are compared to voltages sources.
In the viewpoint of ordinary differential equation solving, the integral causality requires a numerical integration to get the state variables, i.e. the currents across the inductor and the voltages through the capacitors.So, for the external connection of the static converter, current sources (respectively voltage sources) can be used to represent inductors or inductive phenomena (respectively capacitors or capacitive phenomena).
By considering the integral causality, defined as the preferential causality in Bond Graph, the causality of capacitors and inductors are defined (see Fig. 5).

Fig. 5. Causality of a static converter
This approach proposes to generate automatically its models (exact and/or average) according to the nature of the state variables.However, to associate the generated model with other models, thanks to the static converter environment characterisation, the generated model has to give an expression for every complementary energetic variable of the equivalent sources that are connected to the converter.In this way, the current across voltage sources and the voltage through current sources have to be formulated.
The following outputs are formulated: e I : the sub-vector of the current in the voltage sources at the interface of the static converter.mj V : the sub-vector of the voltage on the current sources at the interface of the static converter.
Finally, models are obtained by using equation ( 2).This representation form of state equation is especially interesting for coupling models.

Implementation
AMG is implemented by using Java and Maple programming.Only symbolic treatments are in Maple.The building of the state matrixes A i , B i , C i and D i for every configuration (indexed i) is developed in Java by equations ( 1) and ( 2).The building of the exact and the average models (equations ( 10) and ( 11)) by a symbolic approach is made in Maple (Merdassi et al., 2008).

Applications in Matlab/Simulink
Many examples of converters are implemented in Matlab/Simulink.The results are presented for several applications on the continuous conduction mode among them a resonant converter, a three phase inverter coupled with a three-phase machine (modelled by a three-phase resistor-inductor load).Finally, a multi-level converter is also taken as an example to show the interest of using AMG for big power electronic structure.

Application 1: A resonant converter
The static converter has been modelled by AMG.The studied structure has an alternative level so the generalized average model is generated for the alternative and the continuous state variables.The equivalent average generator is also tested for this application.

Definition of the control
The mode and the control are deducted from a classic simulation of the structure to be studied in simulation software (e.g Portunus).In the example, these signals will be known as h1 that controls (MOS1, MOS8) and h2 that controls (MOS3, MOS6).Their complementary 1 h and 2 h respectively control (MOS7, MOS2) and (MOS5, MOS4).

Simulation in Matlab/Simulink
The generalized average model allows to get the amplitude and the phase of alternative state variables.They are deduced from the real and imaginary expression of IL1.In Fig. 13  We can notice that, on the one hand, the average equivalent generator is not accurate for this example because it is not adapted to the converter operating in the continuous conduction mode.In fact, the equivalent average generator eliminates some dynamics of the system especially in the discontinuous conduction mode (cf.table 1).On the other hand, the classic average model is better suited for the converter.
As explained above, AMG needs basic assumptions on the external equivalent electrical sources to define its environment to connect to it.

Definition of the control
In this static converter, each commutation cell is an inverter legs.For, one leg when a switch is controlled to be ON the other one is OFF.As a consequence, the inverter needs only three control signals corresponding to the upper switch of the switching cell (MOS1, MOS3 and MOS5).These signals will be known as h1, h2 and h3, respectively controls MOS1, MOS3 and MOS5.So, their complementary 1 2 , h h and 3 h respectively controls MOS2, MOS4 and MOS6.

synchronous machine
Rotor axis (f)

Simulation in Matlab/Simulink
The model has been mixed with the equations of a three phase RL circuit (see Fig. 18) and three-phase synchronous machine which model is a Park Model.Park's transforms and inverse Park's transforms have been added in the machine model.The interest of the AMG tool becomes obvious by looking at the equation generated for this very basic power converter structure.One can easily imagine the difficulty to build such a model without modelling tool, for more complex structures, such a multi-level converter.

Application 3: A multi-level converter
A multi-level converter is taken as an example to show the interest of using AMG for big power electronic structure.

Definition of the control
For this application, the static converter legs are supposed perfectly balanced.In this example, only the model of one leg is generated by AMG.
The switch commutations are controlled by the signals: h1, h2, h3 and h4 and their complementary values.Each control signal is a pulse wave modulation.Each switching cell is control by the same sinusoidal modulation but with a 2 π phase displacement of its triangular waveform compared to the one of the switching cell where it is imbricated.

Simulation in Matlab/Simulink
The exact model of the current IL1 generated in C S-function (e.g Matlab/Simulink) is compared to the classical simulation from electrical software (e.g Portunus).
By using the exact model generated by AMG, simulation results represent the perfect behaviour of the multi-level converter.The same results are given with a comparison between the current IL1 obtained automatically (from the exact model by AMG) and the one obtained from the classical simulation (e.g Portunus).Finally, the automatic modelling approach is also approved for a complicated structure.

Conclusion
This chapter proposes an automatic modelling process that allows to obtain different models of static converter according to the nature of the power conversion and the state variables.Every model is entirely made in an automatic way by the AMG software, from a description of the structure (here a Netlist file generated by PSpice), the commutation mode (cyclic sequence of switched configurations) and the switch control sequence of the static converter to model.This descriptive information is given by the AMG user.The automatic generation is useful, especially for complex static converter structures.The generated models are also automatically translated into C-S Function, Modelica and VHDL-AMS language.Indeed, models in such a language are easy to use in the power electronics simulation software like Matlab/Simulink, Portunus, Simplorer, Amesim, Dymola.This also allows to connect the generated model with others by managing automatically the model causality.This aspect is especially very interesting for coupling models.
Intrinsically, for the average modelling, AMG supposes an a priori on the behaviour of the studied static converters.In this way, the user must understand and analyze the behaviour of the static converter to study.It should also be interesting to extract automatically the control and the mode, by analyzing classical simulation.
A specific methodology for the treatment of the discontinuous conduction mode is also proposed with AMG but not presented in this chapter.However, this automatic treatment requires some knowledge about the converter operating in discontinuous conduction mode.Nowadays, it is only automatically applied for DC/DC converters so it will be interesting in the future to extend it to AC/DC and DC/AC converters.

Acknowledgment
This work has been supported by the French association ANR, in the context of the project C6E2-SIMPA2 on the simulation and modelling of mechatronic systems.

Fig. 3 .
Fig. 3.The reduced incidence matrix for a boost converter (for case 1 and case 2) i t : the commutation instant between configuration i and configuration i+1 i A′ : the state matrix for the i th configuration (size[n,n]).

Fig. 4 .
Fig. 4. Example of causality aspect for a single-phase voltage inverter

Fig. 6 .
Fig. 6.Implementation in Java and Maple In this section, an example of the generated C-S function, Modelica and VHDL-AMS code are presented for a boost converter.

Fig. 8 .
Fig. 8.The exact model for a boost converter in VHDL-AMS

Fig. 10 .
Fig. 10.Control associated to the switching cells

Fig. 13 .
Fig. 12. Implementation of the models for a resonant converter in Matlab/Simulink

Fig. 16 .
Fig. 16.Three phase voltage inverter coupled with synchronous machine Here, for the average model, each control signal is a full wave control one.For this application, full wave control and Pulse Width Modulation (PWM) are applied.For the full wave control, signals are periodical and characterized by a 0.5 duty cycle and δ = 2 3 π the phase shifting angle between the controls h1, h2 and h3.A C S-function is obtained.It contains equations of currents in the voltage sources and the voltage on the current sources according to the equation (4).Analyzing the code (C S-Function), we can see the expression of the DC bus current (i.e.IU1 and IU2) as a function of: -the control signals: h1, h2, h3 -the expressions of the currents in every phase: I1, I2 and I3 In the same way, the voltage drop applied in the phase is a function of: the DC bus voltages: U1, U2 -the control signals: h1, h2, h3.

Table 1 .
Comparison between the models generated by AMG