# Power Sharing Control in a Grid-Tied DC Microgrid: Controller Hardware in the Loop Validation
## 2 MGIS: Description, Modeling, and Design
### Open Loop Main Grid Interconnection System Response  
To validate the behavior of the MGIS, its responses were evaluated in open loop for the two operation modes: rectifier and inverter. To calculate the amplitude and phase of the modulating signal that determines the desired operating state, the AC loop presented in the diagram in Figure 4 is considered. For this validation, a value of zero was established for reactive power. This condition is desirable since it implies the state of operation with greater efficiency. Under this consideration, the HBFC AC side voltage is in phase with the AC side current so that its magnitude, \(V_{ab}\), is determined with Equation (15) as a function of the instantaneous active power that is shared, \(P\), and the magnitude of the AC side current, \(I_{a}\).  
\[V_{ab}=\frac{2P}{I_{a}} \tag{15}\]  
With this condition, when applying the KVL to the AC loop in Figure 4, Equations (16) and (17) are obtained for the rectifier and inverter modes of operation, correspondingly. Two equations are generated from this loop, since, in the rectifier mode, the HFBC transfers energy from the MG and uses it in the DC side while, in the inverter mode, the energy generated by the PA that is not consumed in the DC load is injected into the MG. With this change in the direction of the energy flow, the direction of the AC side current changes, so the inductor voltage, \((r+j\omega L)\mathbf{I_{a}}\), changes sign.  
\[\mathbf{V_{g}}=\mathbf{V_{ab}}+(r+j\omega L)\mathbf{I_{a}} \tag{16}\]  
\[\bm  
\(M=I_{a}\sqrt{r^{2}+\omega^{2}L^{2}}\) is the magnitude of the inductor voltage phasor. From these phasor diagrams, the phase angle of the modulator, \(\alpha\), is obtained by calculating its tangent with the triangle ABC, as shown in Equation (18).  
\[\alpha=\left\{\begin{array}{l}atan\left(\frac{\omega L{I_{a}}}{V_{ab}-rI_{a}} \right)\text{: for inverter mode}\\atan\left(\frac{\omega L{I_{a}}}{V_{ab}+rI_{a}}\right)\text{; for rectifier mode} \end{array}\right. \tag{18}\]  
Nevertheless, to obtain the value of \(\alpha\), it is necessary to know the value of \(I_{a}\). The magnitude of the sides \(\overline{AD}\) and \(\overline{DB}\) of triangle ABD depend on \(I_{a}\), while \(\overline{AB}=V_{g}\) is known. Thus, when applying the law of cosines to triangle ABD, with respect to angle \(\gamma\), Equation (19), which depends on \(I_{a}\), is generated.  
\[{V_{g}}^{2}=\frac{4P^{2}}{{I_{a}}^{2}}+{I_{a}}^{2}\left(r^{2}+\omega^{2}L^{2} \right)-4P\sqrt{r^{2}+\omega^{2}L^{2}}cos(\gamma) \tag{19}\]  
Substituting the variables \(k=\sqrt{r^{2}+\omega^{2}L^{2}}\) and \(x={I_{a}}^{2}\) in Equation (19) and rearranging them, Equation (20) is obtained.  
\[{V_{g}}^{2}+4 Pkcos(\gamma)=\frac{4P^{2}}{x}+xk^{2} \tag{20}\]  
Finally, substituting, \(U={V_{g}}^{2}+4 Pkcos(\gamma)\) and \(xk^{2}=k^{2}\frac{v^{2}}{x}\), Equation (21) is generated.  
\[k^{2}x^{2}-Ux+4P^{2}=0 \tag{21}\]  
By solving Equation (21), the value of \(I_{a}\) is obtained where the value of \(\alpha\) is determined with Equations (15) and (18). The angle \(\gamma\), on which Equation (21) depends, is a function of the operation mode and is calculated from triangle BCD in Figure 5, as shown in Equation (22).  
\[\gamma=\left\{\begin{array}{l}atan\left(\frac{\omega L}{r}\right)\text{; for inverter mode}\\ \pi-atan\left(\frac{\omega L}{r}\right)\text{; for rectifier mode}\end{array}\right. \tag{22}\]  
Finally, the magnitude of the modulator is determined from Equations (7) and (8), as shown in Equation (23).  
\[m=\frac{V_{ab}}{v_{dc}} \tag{23}\]