## 4 Design of the Sliding-Mode Controller
### Establishing the Switching Function  
The main control objective for the SMC is to ensure that the PV voltage \(v_{pv}\) follows the optimal reference value \(v_{mppt}\) imposed by the MPPT controller with a defined settling time. A commonly adopted strategy to define switching functions with those characteristics is to perform a linear combination of the state variables, which, in this case, are the PV voltage \(v_{pv}\) and the magnetizing current \(i_{m}\), as reported in Section 2. Therefore, a first candidate for switching function is defined as in (17), where the parameter \(k\) is calculated to impose a desired closed-loop behavior:  
\[\psi_{v,i_{m}}=\big{(}v_{pv}-v_{mppt}\big{)}+k\cdot i_{m} \tag{17}\]  
The previous switching function \(\psi_{v,i_{m}}\) fulfills all the stability tests; thus, it is a suitable option to control the flyback-based PV system of Figure 1. Then, considering the correct operation of the SMC (\(\psi_{v,i_{m}}=0\)), the magnetizing current of the flyback converter is defined by the SMC as \(i_{m}=-\left(v_{pv}-v_{mppt}\right)/k\). Since the SMC provides the binary control signal \(u\) to the MOSFET, the dynamic behavior of the PV voltage is analyzed from the averaged differential equation given in (6), which depends on the duty cycle. Hence, substituting the closed-loop expression of \(i_{m}\) into (6) leads to (18), which describes the closed-loop behavior of the PV voltage. Applying the Laplace transformation to the differential equation (18) enables the calculation of (19), which describes the closed-loop behavior of \(v_{pv}\) to changes on the PV current \(i_{pv}\) and MPPT reference \(v_{mppt}\).  
\[\frac{dv_{pv}}{dt}=\frac{i_{pv}+d\cdot\left(v_{pv}-v_{mppt}\right)/k}{C_{pv}} \tag{18}\]  
\[V_{pv}(s)=\underbrace{\frac{1}{C_{pv}\cdot s-\frac{d}{k}}\cdot I_{pv}(s)}_{ \text{introduced error}}+\underbrace{\frac{-\frac{d}{k}}{C_{pv}\cdot s-\frac{d}{k}} \cdot V_{mppt}(s)}_{\text{correct tracking}} \tag{19}\]  
From the dynamic expression (19), it is observed that the SMC based on \(\psi_{v,i_{m}}\) (17) provides the correct tracking of the desired reference \(v_{mppt}\) with a time constant defined by \(k\), but any \(i_{pv}\) value different from zero will introduce a steady-state error equal to \(-i_{pv}/(d/k)\) into the PV voltage, thus degrading the tracking of the reference value. Taking into account that any power production of the PV panel requires an \(i_{pv}\) value higher than zero, an SMC based on \(\psi_{v,i_{m}}\) (17) does not ensure the accurate tracking of the MPPT reference; hence, the PV power could not be maximized.  
To compensate for the error introduced in the dynamic expression (19) by the PV current, such a variable (\(i_{pv}\)) must be introduced into the switching function. Thus, a linear combination of the PV voltage, MPPT reference, magnetizing current, and PV current is defined as the final switching function:  
\[\psi_{x}=k_{1}\cdot\left(v_{pv}-v_{mppt}\right)+i_{pv}-k_{2}\cdot i_{m} \tag{20}\]  
This switching function will modify \(i_{m}\) to eliminate the detrimental effect of \(i_{pv}\) on the tracking of the MPPT reference, as will be described in Section 4.5, and at the same time, \(i_{m}\) will be modified to compensate for the error between \(v_{pv}\) and the reference \(v_{mppt}\). The following subsections present the stability tests for \(\psi_{x}\) (20) and the final closed-loop behavior of the PV voltage imposed by the SMC based on \(\psi_{x}\).