# Digital automatic control system with PID controller/Skaitmenine automatine sistema su PID reguliatoriumi.

IntroductionMass production of microprocessors reduced their cost. Because of this reason they found the new areas of application: to fulfill various computations, to solve control and signal processing task. Nowadays they can be found not just in industry but also in transportation systems and many more complex domestic appliances.

The control problems can be solved by application of analogue means, but digital controllers have some advantages [1]: their parameters remains stable for long time; realized function can be changed only by changing program; digital circuits are robust for noise; single controller in accordance with the speediness, may be capable to control severe plants.

Industrial digital controllers usually are realized on the base of programmable logic controllers [2]. An in advance preprogrammed transfer function of many popular controllers is the main advantage of those. Another advantage of programmable logic controllers is possibility to deal with various types of digital and analog input and output signals. In the mobile and domestic appliances as well as stand-alone devices they are used seldom due to large size and high power consumption. Therefore this area at the present is covered by microcontrollers. Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, power tools ant toys.

A microcontroller can be consider as a self-contained system with a processor, memory and peripherals and be used as embedded system. Microcontrollers use smaller bit words, but their integrated circuit contains a processor core, programmable input/output peripherals and also other functional units, as memory, timers, USB, UART and other interfaces, PWM signal generator and analog- digital converters. Due to small size and small power consumption they are well-suited for domestic, mobile and long lasting battery applications. The most popular are eight-bit word microcontrollers. Usually they are applied for simple task, where floating point operations are not required. For more complicated tasks 16 or 32 bit microcontrollers are applied [3].

Proportional-integral-derivative (PID) controller is the base of universal controllers. It is applied in many industrial control systems and has a lot of forms depending on application [4, 5], and for its tuning many laws are used [6].

The article deals with the problems appearing by programming of PID controller in eight-bit word microcontroller and ways of their solving.

PID algorithm

PID controller usually is used in closed loop systems and forms system control signal y according to error e of controlled parameter i. Block diagram of closed loop system with PID controller is shown in Fig. 1.

[FIGURE 1 OMITTED]

Relationship between input and output on continuous time classical PID controller is described as [1]

Y = [K.sub.p] (e + 1 / [T.sub.n] [integral edt] + [T.sub.v] de / dt); (1)

where [K.sub.p],[T.sub.n] and [T.sub.v] are positive parameters, which are respectively referred to as proportional gain, integral time and derivative time.

Relationship (1) should be replaced by second order difference equation. It takes the form as

[y.sub.n] = -[a.sub.1] [y.sub.n-1] - [a.sub.2] [y.sub.n-2] + [b.sub.0][e.sub.n] + [b.sub.1][e.sub.n-1] + [b.sub.2][e.sub.n-2]; (2)

where [a.sub.1], [a.sub.2], [b.sub.0], [b.sub.1], [b.sub.2] are constants, variables [y.sub.n], [y.sub.n-1], [y.sub.n-2], [e.sub.n], [e.sub.n-1] and [e.sub.n-2] correspond to controller output and input signals at the time instant nT, (n-1)T ir (n-2)T, where T is sampling period and n [member of] N .

The PID controller deals with sampled input signal en which is discountinuous function. Differentiating of such kind function may causes large errors. In order to avoid this disadvantage the ideal derivative part of controller is recommended to replace by real that [1]. In this way the function realized by controller is described as

y(s) = [K.sub.p](1 + 1 / [T.sub.n]s + [T.sub.v]s / [T.sub.l]s + 1)e(s); (3)

where [T.sub.1] is time constant of real differentiation block, y(s) and e(s) is respectively the output and input signals in frequency domain.

The transfer function of PID controller is

[W.sub.PID](s) = y(s) / e(s) = [K.sub.p](1 + 1 / [T.sub.n]s + [T.sub.v]s / [T.sub.l]s + 1) (4)

Chosen function is realized by controller. Coefficients of and its difference equation are calculated from expressions [1]:

[MATHEMATICAL EXPRESSION NOT REPRODUCIBLE IN ASCII] (5)

Analysis of difference equation (2) and coefficients expressions (5) shows that realization of PID controller requires multiplication and adding of real numbers.

Design of the controller of mechatronic system

Controller is devoted for magnetic bearings system where the current control in the field coil is required. The plant is described by first order transfer function

W(s) = k / Ts + 1 (6)

where k is gain and T time constant.

The transfer function of closed loop system, shown in Fig. 1 is

[W.sub.s](s) = [K.sub.p] [T.sub.v][T.sub.n][s.sup.2] + [T.sub.n]s + 1 / [T.sub.n](L + [K.sub.p][T.sub.v])[s.sup.2] + [T.sub.n](R + [K.sub.p])s + [K.sub.p]. (7)

The plant is the coil of electromagnet with time constant T=L/R and gain k=1/R, where L and R is coil inductance and resistance respectively. Assumed parameters are: L=0,047 H and R=15 [omega]. The current settling time will be approximately 4T/R[appriximately equal to]12 ms. If desirable step response settling time should last no longer 6 ms, and overshoot should be not greater than 10%, then on the base of classical control theory the desired coefficients of close loop system can be calculated in this way:

[MATHEMATICAL EXPRESSION NOT REPRODUCIBLE IN ASCII] (8)

Set of equation (8) has 3 variables, therefore it cannot be solved explicit. By setting [K.sub.p]=40, we get [T.sub.n][approximately equal to]0,00145 and [T.sub.v] [approximately equal to] 1,73*[10.sup.-4].

Step responses of current with controller and without it are presented in Fig. 2. Simulation results show the overshoot being about 9 % and settling time not exceeding 6 ms.

[FIGURE 2 OMITTED]

All coefficients of difference equation depend on sampling time T. Algorithm of controller has to be programmed into microcontroller ATmega16. This microcontroller has integrated analog-digital converters whose maximal sampling frequency without losing accuracy is 15 kHz, therefore minimal sampling time is about 66,667 [mu]s. Coefficients (5) of difference equation for this and some other values of sampling time are presented in table 1.

The same table contains additional parameters, which will be valuable in estimation of the word length for storage of coefficients and results. One of the parameters is the ratio of absolute values of maximal and minimal coefficients [alpha]

[alpha] = max([absolute value of [b.sub.0]], [absolute value of [b.sub.1]], [absolute value of [b.sub.2]], [absolute value of [a.sub.1]], [abolute value of [a.sub.2]]) / min ([absolute value of [b.sub.0]], [absolute value of [b.sub.1], [absolute value of [b.sub.2]], [absolute value of [a.sub.1]], absolute value of [a.sub.2]]). (9)

Analysis of coefficients values, presented in Table 1, shows that the ratio between the maximal and the minimal values lies in the range of 1 / 2 thousands. For binary representation of this range 10 / 11 bit length words are required.

PID controller is intended to be implemented in Atmel company's 8 bit microcontroller ATmega16, but it can be applied for the other megaAVR family controllers having the same command system.

As it was mentioned, 8 bit length word is insufficient to represent the coefficients of difference equation, therefore several bytes to store the numbers should be used. For storage of real numbers fixed or floating point formats can be used. The floating point representation is used by all modern computers, but it demands a lot of computation capability. Despite very limited computation capability our system should be able to work as real time system, because of that the fixed point representation of real numbers is chosen. According to the Table 1, minimal length of the word should be 10 bits. For representing them by 8 bit microcontroller 2 bytes length word was chosen. Bytes assignment for representation sign, integer and fractional parts of the number are listed in the Table 2.

As the limited length of the word was chosen, the coefficients of difference equation and intermediate results can be represented with limited accuracy, i.e. the rounding errors appear. For example, the coefficient a2 at T=66,667 us is equal to 0,206. In chosen system it will be represented by 0x001A hexadecimal number, which has the decimal value 0,2031. Rounding error in this case is

0,206 - 0,2031 / 0.206 * 100% [approximately equal to] 1,4%. (10)

In the same way calculated rounding errors of the other coefficients are presented in Table 3.

Results shown in the Table 3 indicates, that maximal values of rounding errors, caused by choosing of 2 bytes length fixed point format for representing of real numbers, reach 6 %. This error could be reduced by choosing longer word length for representation of real numbers. It should be noticed that the larger error is characteristic for small magnitude coefficients.

During the development of controller it is important to choose optimal sampling frequency and numbers storage format, because in this way the program may be optimized and errors can be reduced.

Despite all given remarks in Table 2 shown number format matches all engineering calculations and allows to represent the coefficients of difference equation with suitable accuracy.

Algorithm of multiplication

ATmega16 controller, as well as others megaAVR family controllers, has only 8 bit multiplication command. Our case deals with multiplication of 16 bits (2 bytes), therefore it is convenient use the partition

[PI] = (256[a.sub.1] + [a.sub.0])*(256[b.sub.1] + [b.sub.0]) =

= 65536[a.sub.1][b.sub.1] + 256([a.sub.1][b.sub.0] + [a.sub.0][b.sub.1])+ [a.sup.0][b.sub.0]; (8)

where [a.sub.0], [b.sub.0] - low bytes of the multipliers, [a.sub.1], [b.sub.1] bytes of the multipliers.

[FIGURE 2 OMITTED]

Algorithm of subprogram realizing multiplication is given in Fig. 2. Here [R.sub.x] corresponds to microcontroller registers, C - carry flag attribute. It can be seen that the subprogram uses only 8 microcontroller registers, where each two are used for storage of multipliers and four are used for storage of product. 20 MHz clock rate microcontroller fulfills it in time less than 1 [mu]s. Solution of difference equation (2) takes 12 us.

Step responses of current i and error e (controller input signal) at different sampling time was obtained by simulation and presented in Fig. 3.

Step response curves in Fig. 3 indicate, that overshoot increase together with increasing sampling time. At T=100 [mu]s maximum overshoot values is 9%, but at T= 500 us overshoot rise up to 12 % and exceeds allowed 10 % value.

[FIGURE 3 OMITTED]

Step response of the controller output signal at the beginning of the transient process is presented in Fig. 4.

[FIFURE 4 OMITTED]

Fig. 4 shows that with decreasing of sampling time T the maximal value of output signal increases. In the real system the output signal always is limited, therefore reducing of sampling time is not useful for the system.

Conclusions

Analysis shows, that 8 bit microcontroller capability allows to program PID controller with sampling time no

less than 100 [mu]s. Despite availability of microcontroller ADC to operate faster, the speediness of microcontroller arithmetic logic unit is not sufficient to solve difference equation in real time.

Due to restricted resources of the microcontroller it should be programmed for each task individually. Even small change in conditions of the same task, for example change of sampling time, can result increasing of the error.

Greater sampling time gives in overshoot increasing and non continuity of step response at the beginning of transients. Therefore if the plant is sensitive for dynamic overloads, the small as possible sampling time is recommended.

Reduction of sampling time increases controller output voltage in the beginning of the step response due to derivate action of controller.

References

[1.] Mann H., Schiffelgen H., Froriep R. Einfuhrung in die Regelungstechnik. Analoge und digitale Regelung, FuzzyRegler, Regel-Realisierung, Software.--Munchen: Hanser Verlag, 2000.--450 s.

[2.] Akiner C., Tuncay M. T. Flexible Product Drying System Design and Application // Electronics and Electrical Engineering.--Kaunas: Technologija, 2010.--No. 10 (106). P. 37-42.

[3.] Spanik P., Drgona P., Frivaldsky M., Prikopova A. Design and Application of Full Digital Control System for LLC Multiresonant Converter // Electronics and Electrical Engineering.--Kaunas: Technologija, 2010.--No. 10 (106). P. 75-78.

[4.] Zlosnikas V., Baskys A. PID controller with enhanced disturbance rejection // Electronics and Electrical Engineering.--Kaunas: Technologija, 2008.--No. 5(85).--P. 65-68.

[5.] Lisauskas S., Rinkeviciene R. Model of ventilation system drive with fuzzy controller // Electronics and Electrical Engineering.--Kaunas: Technologija, 2010.--No. 10(106). P.13-16.

[6.] Lutz H., Wendt W.Taschenbuch der Regelungstechnik mit MATLAB und Simulink.--Frankfurt am Main: Harri Deutsch Verlag, 2010.--1409 s.

Received 2011 02 18

A. Petrovas, S. Lisauskas, R. Rinkeviciene

Department of Automation, Vilnius Gediminas Technical University, Naugarduko str. 41, LT-03227 Vilnius, Lithuania, phone: +370 5 2 745013, e-mails: andrius.petrovas@el.vgtu.lt, saulius.lisauskas@el.vgtu.lt, roma.rinkeviciene@el.vgtu.lt

Table 1. Values of difference equation coefficients T,[mu]s 66,667 70 100 500 [b.sub.0] 123 120 100 60.2 [b.sub.1] -212 -205 -162 -61.3 [b.sub.2] 90.3 86.8 64.5 14.4 [a.sub.1] -1,21 -1,20 -1,15 -1,03 [a.sub.1] 0,206 0,198 0,147 0,0333 a 1029 1035 1104 1839 [log.sub.2]a 10 10 10,1 10,8 Table 2. Representation of real numbers Bits Number of bites Meaning 15 1 Sing (+ or -) 7 - 14 8 Integer part (0 - 255) 0 - 6 7 Fraction part Table 3. Rounding errors T,[mu]s 66,667 70 100 500 [b.sub.0] 0 0 0 0,008 [b.sub.1] 0 0 0 0,006 [b.sub.2] 0,003 0,004 0 0,01 [a.sub.1] 3,3 0,5 0,1 0,6 [b.sub.2] 1,4 0,3 0,6 6

Printer friendly Cite/link Email Feedback | |

Title Annotation: | ELECTRICAL ENGINEERING / ELEKTROS INZINERIJA |
---|---|

Author: | Petrovas, A.; Lisauskas, S.; Rinkeviciene, R. |

Publication: | Elektronika ir Elektrotechnika |

Article Type: | Report |

Geographic Code: | 4EXLT |

Date: | Apr 1, 2011 |

Words: | 2441 |

Previous Article: | Modelling and design of HF 200 kHz transformers for hard- and soft-switching application/Minkstai ir kietai persijungiancio transformatoriaus HF 200... |

Next Article: | Investigation of energetic parameters of oscillating synchronous pulsating current motors/Svytuojamuju sinchroniniu pulsuojamosios sroves varikliu... |

Topics: |