Файл: Microcontroller based applied digital control (D. Ibrahim, 2006).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 14.06.2025

Просмотров: 3281

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

274 LIQUID LEVEL DIGITAL CONTROL SYSTEM: A CASE STUDY

Figure 11.6 Hardware set-up to record the step response

sensor) was recorded in real time using a DrDaq type data logger unit and the Picolog software. Both of these products are manufactured by PICO Technology. DrDaq is a small electronic card which is plugged into the parallel port of a PC. The card is equipped with sensors to measure physical quantities such as the intensity, sound level, voltage, humidity, and temperature. Picolog runs on a PC and can be used to record the measurements of the DrDaq card in real time. The software includes a graphical option which enables the measurements to be plotted.

The microcontroller program to send a step signal to the D/A converter is shown in Figure 11.7. At the beginning of the program the input–output ports are configured and then a step signal (200) is sent to port B. The D/A converter is then enabled by clearing its WR input. After writing data to the D/A converter it is disabled so that its output does not accidentally change. The program then waits in an endless loop.

Figure 11.8 shows the step response of the system, which is the response of a typical firstorder system. It will be seen that the response contains noise. Also, since the DrDaq data logger is 8-bit, its resolution is about 19.5 mV with a reference input of 5V, and this causes the step discontinuities shown in the response (the steps can be eliminated either by using a data logger with a higher resolution, or by amplifying the output of the level sensor). The figure clearly shows that in practice the response of a system is not always a perfect textbook signal.

A smooth curve is drawn through the response by taking the midpoints of the steps, as shown in Figure 11.9.

11.4 DESIGNING A CONTROLLER

The circuit diagram of the closed-loop system is shown in Figure 11.10. The loop is closed by connecting the output of the level sensor to the analog input AN0 of the microcontroller.

DESIGNING A CONTROLLER

275

/*-----------------------------------------------------------------

STEP RESPONSE TEST

==================

This program sends a STEP input to the D/A converter. The value

of the input is set to 200, which corresponds to a voltage of

5 × 200/256V. The output of the D/A is connected to a power

amplifier which has an overall gain of G = 2.5. Thus, the step

voltage applied to the pump is 5 × (200/256) × 2.5 = 9.76V.

The hardware consists of a PIC16F877 microcontroller, where PORT B

is conencted to an AD7302 type D/A converter. The output of the D/A

is connected to an LM675 type DC power amplifier.

File: STEP.C

Date: July 2005

------------------------------------------------------------------

*/

#include <pic.h>

#define AD7302 WR RC0

/* Start of main program */

main(void)

{

TRISB = 0;

/* PORTB is output */

TRISC = 0;

/* RC0 is output */

AD7302 WR = 1;

/* Disable D/A */

/* Send a STEP input to the D/A */

PORTB = 200;

/* Send the STEP */

AD7302 WR = 0;

/* Enable D/A */

AD7302 WR = 1;

/* Disable D/A */

wait: goto wait;

/* Wait here forever */

}

Figure 11.7 Microcontroller program to send a step to D/A

A controller algorithm was then implemented in the microcontroller to control the level of the water in the tank.

One of the requirements in this case study is zero steady-state error, which can be achieved by having an integral type controller. In this case study a Ziegler–Nichols PI controller was designed.

The system model can be derived from the step response. As shown in Figure 11.11, the Ziegler–Nichols system model parameters are given by T1 = 31 s, TD = 2 s and

K

=

2345 − 2150

=

0.05.

200

×

5000/256


276 LIQUID LEVEL DIGITAL CONTROL SYSTEM: A CASE STUDY

mV

Voltage

2350

2300

2250

2200

2150

Sec

0

20

40

60

Figure 11.8 System step response

mV

Voltage

2350

2300

2250

2200

2150

Sec

0

20

40

60

Figure 11.9 Step response after smoothing the curve

Notice that the output of the microcontroller was set to 200, which corresponds to 200× 5000/256 = 3906 mV, and this was the voltage applied to the power. We then obtain the following transfer function:

G(s) =

0.05e−2s

(11.14)

1

+

31s

The time constant of the system is 31 s. It was shown in Section 10.6 that the sampling time should be chosen to be less than one-tenth of the system time constant, i.e. T < 3.1 s. In this case study, the sampling time is chosen to be 100 ms, i.e. T = 0.1 s.


DESIGNING A CONTROLLER

277

Figure 11.10 Circuit diagram of the closed-loop system

mV

Voltage

2350

2300

2250

2200

2150

Sec

0

20

40

60

Figure 11.11 Deriving the system model


278 LIQUID LEVEL DIGITAL CONTROL SYSTEM: A CASE STUDY

Kp

wk

ek

+

pk

KpTi/T

z−1

+

uk

pk−1

Figure 11.12 Realization of the controller

The coefficients of a Ziegler–Nichols PI controller were given in Chapter 10:

K p =

0.9T1

and Ti = 3.3TD .

K TD

Thus, the PI parameters of our system are:

K

p =

0.9 × 31

=

279 and T

3.3

×

2

=

6.6.

0.05

×

2

i =

A parallel PI controller was realized in this case study. The controller is in the form of (10.27), with the derivative term set to zero, i.e.

K p T

D(z) = K p + Ti (1 − z−1) .

The realization of the controller as a parallel structure is shown in Figure 11.12.

The controller software is shown in Figure 11.13. The PI algorithm has been implemented as a parallel structure. At the beginning of the program the controller parameters are defined. The program consists of the functions Initialize AD, Initialize Timer, Read AD Input, and the interrupt service routine (ISR). The A/D converter is initialized to receive analog data from channel AN0. The Read AD Input function reads a sample from the A/D converter and stores it in variable yk . The timer is initialized to interrupt every 10 ms. At the beginning of the ISR routine, the PI algorithm is implemented after every 10th interrupt, i.e. every 100 ms. This ensures that the controller sampling time is 100 ms. The ISR routine reads the output of the level sensor and converts it to digital. Then the PI controller algorithm is implemented. Notice that in the algorithm the input of the D/A converter is limited to full scale, i.e. 255. After sending an output to D/A, the ISR routine re-enables the timer interrupts and the program waits for the occurrence of the next interrupt.

The step response of the closed-loop system is shown in Figure 11.14. Here, the reference input was set to 2280. Clearly the system response, although noisy, reaches the set-point with no steady-state error, as desired.

11.5 CONCLUSIONS

Although the case study given in this chapter is simple, it illustrates the basic principles of designing a digital controller, from the identification of the system to the implementation of a suitable controller algorithm on a microcontroller. Here the classical Ziegler–Nichols PI type


CONCLUSIONS 279

/*****************************************************************************

ZIEGLER-NICHOLS PI CONTROLLER

=============================

This program implements a first-order digital controller module on a PIC16F877 (or equivalent) microcontroller. The microcontroller operates with a 4MHz crystal. The analog input AN0 of the microcontroller is connected to the output sensor of the plant (y). The PORT B output of the microcontroller is connected to an AD7302 type D/A converter. The WR input of the controller is controlled from port pin RC0 of the microcontroller.

The sampling interval is 0.1s (100ms) and the timer interrupt service routine is used to obtain the required sampling interval.

Program : ZIEGLER.C

Date : July 2005

*****************************************************************************/

#include <pic.h>

#define DA Write RC0

volatile unsigned int time now = 0;

float AD LSB, DA LSB, wk,Kp, T, Ti, b, pk, pk 1, ek, sk, yk, y high, y low;

unsigned char uk;

/* This function initializes the A/D converter so that analog data can be received from channel AN0 of the microcontroller */

void Initialize AD(void)

{

ADCON1 = 0x8E;

/*

Configure AN0 for +5V reference */

ADCON0 = 0x41;

/*

Select A/D converter clock */

}

/* This function initilizes the timer TMR0 so that interrupts can be generated at 10ms intervals */

void Initialize Timer(void)

{

T0CS = 0;

/* Select f/4 clock for the TMR0 */

PSA = 0;

/* Select pre-scaler */

PS0 = 1;

/* Set pre-scaler to 64 */

PS1 = 0;

/* PS2,PS1,PS0 = 101 */

PS2 = 1;

TMR0 = 100;

/* Load TMR0 = 100 */

T0IE = 1;

/* Enable TMR0 interrupts */

T0IF = 0;

/* Clear TMR0 interrupt flag */

}

Figure 11.13 Software of the controller (Continued )