## 4 Closed-Loop Control Algorithms
### Digital Positional PID Control Algorithm  
The PID algorithm is currently the most popular feedback controller used in the industry [34]. The PID algorithm was formally developed in the late 1930s and has a history of more than 90 years [35]. The basic PID control theory is essentially to control the actuator by the superimposed result of proportional, integral, and differential operations on the error between the target value and the actual value. As depicted in Figure 4, a typical PID controller consists of proportional, integral, and derivative components. In practical applications, the data acquisition module ADC and the actuator module DAC are usually needed in cooperation. For instance, in the PID-controlled closed-loop fluxgate current  
Figure 3: Block diagram of an MCU-controlled closed-loop fluxgate current sensor. sensor illustrated in Figure 4, the acquirer ADC first captures the output voltage of the open-loop sensing circuit \(V_{open}\) and converts it to a digital signal \(V_{actual}\) for processing through the digital PID algorithm. Then, the digital PID output \(u(t)\) needs to be converted to the analog control voltage \(V_{DAC}\) by the actuator DAC. Next, \(V_{DAC}\) controls the feedback current drive circuit to generate an appropriate feedback current for magnetization compensation. The resulting feedback current \(I_{f}\) and the primary current \(I_{p}\) collectively influence the open-loop sensing circuit to maintain \(V_{open}\) at a zero-flux state. This closed-loop control mechanism is facilitated by a digital PID controller, which can be implemented on an MCU by utilizing its internal ADC and DAC modules and the digital PID algorithm. In Figure 4, \(e(t)\) is the deviation between the target value \(V_{target}\) and the actual value \(V_{actual}\), and \(u(t)\) is the output value of the PID controller. The following equation can express the continuous control law of the PID controller:  
\[u(t)=K_{p}\bigg{(}e(t)+\frac{1}{T_{i}}\int_{0}^{t}e(t)dt+T_{d}\frac{de(t)}{dt} \bigg{)}. \tag{4}\]  
where \(K_{p}\) is the proportional factor of the control system, \(T_{i}\) is the integration time of the control system, and \(T_{d}\) is the differentiation time of the control system [35]. When absorbing \(K_{p}\) of Equation (4) into the brackets, a new equation can be obtained:  
\[u(t)=K_{p}e(t)+K_{i}\int_{0}^{t}e(t)dt+K_{d}\frac{de(t)}{dt}. \tag{5}\]  
For discrete PID, Equation (5) can also be written in the difference equation form:  
\[u(k)=K_{p}\bigg{(}e(k)+\frac{1}{T_{i}}\sum_{j=0}^{k}e(j)\times T+T_{d}\bigg{(} \frac{e(k)-e(k-1)}{T}\bigg{)}\bigg{)}, \tag{6}\]  
where \(T\) is the sampling time, \(e(k)\) refers to the error of the \(k\)-th sampling cycle, and \(u(k)\) is the PID output value at the \(k\)-th sampling cycle. Equation (6) is the general discrete equation of the basic PID control theory, also called the positional PID control algorithm. Similarly, Equation (6) can also be rewritten using \(K_{p}\), \(K_{i}\), and \(K_{d}\) as follows:  
\[u(k)=K_{p}e(k)+K_{i}\sum_{j=0}^{k}e(j)+K_{d}\ (e(k)-e(k-1)). \tag{7}\]  
The positional PID controller computes the control variable output after the \(k\)-th sampling cycle based on the deviation \(e(k)\) between the \(k\)-th sampling result of the controlled variable and the set value [35]. This PID controller is well suited for systems with relatively stable set-points and exhibits small steady-state errors. However, positional PID has its drawbacks. One disadvantage is that each PID output is influenced by all past errors,  
Figure 4: Block diagram of a PID-controlled closed-loop fluxgate current sensor. which can lead to significant cumulative deviations over time. Additionally, the calculation process involves the accumulation of \(e(k)\), which can be computationally intensive. In general, the parameters \(K_{p}\), \(K_{i}\), and \(K_{d}\) must be selected appropriately so that the system is free of oscillations and overshoots and settles quickly.