Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 11: Liquid Level Control System: A Case Study 1.

Similar presentations


Presentation on theme: "Lecture 11: Liquid Level Control System: A Case Study 1."— Presentation transcript:

1 Lecture 11: Liquid Level Control System: A Case Study 1

2 Objectives Describe the components of a liquid level control system. Obtain a FOPDT model of the system from a step test. Tune a digital PI controller using Ziegler-Nichols tuning rules. Implement the control algorithm on a PIC16F877 μC. 2

3 System description The system consists of a tank, a pump, a liquid level sensor, a μC, a D/A converter (DAC) and a power amplifier. The liquid enters the tank from above using a pump, and leaves the tank from the bottom. The objective to keep the liquid in the tank at the desired level by manipulating the rate of liquid delivered by the pump. 3

4 Water tank. The tank is a plastic container with measurements 12 cm × 10 cm × 10 cm. The pump. The pump is a small 12 V water pump drawing about 3 A when operating at the full-scale voltage. 4

5 The level sensor. A rotary potentiometer type level sensor is used. The sensor consists of a floating arm connected to the sliding arm of a rotary potentiometer. The level of the floating arm, and hence the resistance, changes as the liquid level inside the tank is changed. A voltage is applied across the potentiometer and the change of voltage is measured across the arm of the potentiometer. The resistance changes from 430Ω when the floating arm is at the bottom (i.e. there is no liquid inside the tank) to 40 Ω when the arm is at the top. 5

6 Microcontroller. A PIC16F877 type μC is used as the digital controller. In general, any other type of μC with a built-in A/D converter can be used. The PIC16F877 incorporates an 8- channel, 10-bit A/D converter. D/A converter. An 8-bit AD7302 type DAC converter is used. Power amplifier. The output power of the DAC is limited to a few hundred milliwatts, which is not enough to drive the pump. An LM675 type power amplifier is used to increase the power output of the DAC and drive the pump. The LM675 can provide around 30 W of power. 6

7 Identifying a FOPDT model of the system In this project, a PI controller is used in order to achieve zero steady- state error. To tune the controller using Ziegler Nichols rules, a FOPDT model of the process is required. This can be obtained from a step test. Referring to the block diagram of the system, a constant voltage is applied to the pump so that a constant rate of liquid is pumped to the tank. The height of the liquid inside the tank is measured and plotted. A FOPDT model of the system can be derived from the response curve. 7

8 The hardware set-up for the step test 8

9 Port B of the μC is connected to data inputs of the DAC, and the converter is controlled from pin RC0 of the μC. The output of the DAC is connected to the LM675 power amplifier which drives the pump. The value of the step was chosen as 200, which corresponds to a DAC voltage of 5V × 200/256 = 3.9 V. The height of the water inside the tank (output of the level sensor) was recorded and plotted in real time using a DrDaq data logger unit and the Picolog software. 9 The hardware set-up for the step test

10 #include #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 so that its output does not accidentally change */ wait: goto wait; /* Wait here forever */ } 10 The software program for the step test

11 11 The step response obtained

12 12 The step response obtained We realize that the response contains noise. Also, the response contains step discontinuities. This is due to the 8-bit resolution of the DrDaq data logger. With a reference input of 5V, this equivalent to a resolution of about 19.5 mV. The figure clearly shows that in practice the response of a system is not always a perfect textbook signal. Anyway, the curve is a typical first-order response. A smooth curve is drawn through the response by taking the midpoints of the steps.

13 Fitting a FOPDT model From the previous figure, the time constant τ = 31s, the time delay L = 2s and the gain K is found as We then obtain the following FOPDT model: In this case study, the sampling period is chosen to be T = 0.1 sec, which is sufficiently less than one-tenth of the system time constant, 3.1 s. 13

14 Designing a controller The coefficients of a Ziegler–Nichols PI controller are: The transfer function of the PI controller is given as: A realization of the controller as a parallel structure is shown. 14

15 Designing a controller The circuit diagram of the closed-loop system is shown below. The loop is closed by connecting the output of the level sensor to the analog input AN0 of the μC. A controller algorithm was then implemented in the μC to control the level of the water in the tank. 15

16 At the beginning of the program, the controller parameters are defined, and then comes the functions: Initialize_AD: initializes the ADC to receive analog data from channel AN0. Initialize_Timer: initialized the timer to interrupt every 10 ms. Read_AD_Input: reads a sample from ADC and stores it in variable yk. The interrupt service routine (ISR): reads the output of the level sensor and converts it to digital. The PI algorithm is implemented after every 10th interrupt, i.e. every 100 ms. This ensures that the controller sampling time is 100 ms. Notice that in the algorithm the input of the DAC is limited to full scale, i.e. 255. After sending an output to DAC, the ISR routine re-enables the timer interrupts and the program waits for the occurrence of the next interrupt. 16 The controller program

17 /********************************************************************* This program implements a PI digital controller on a PIC16F877. The microcontroller operates with a 4MHz crystal. The analog input AN0 of the uC is connected to the output sensor of the plant (y). The sampling interval is 0.1s (100ms) and the timer interrupt service routine is used to obtain the required sampling interval. *********************************************************************/ #include #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 A/D converter so that analog data can be received from channel AN0 of microcontroller */ void Initialize_AD(void) { ADCON1 = 0x8E; /* Configure AN0 for +5V reference */ ADCON0 = 0x41; /* Select A/D converter clock */ } 17

18 /* This function iniatilizes 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 */ } 18

19 /* This function reads data from the ADC and stores it in variable yk */ void Read_AD_Input(void) { ADCON0 = 0x45; /* Start A/D conversion */ while((ADCON0 & 4) != 0); /* Wait until conversion completes */ y_high = ADRESH; /* High 2 bits of converted data */ y_low = ADRESL; /* Low byte of converted data */ yk = 256.0*y_high + y_low; /* Converted data in yk */ yk = yk*AD_LSB; /* Sensor output in mV */ } 19

20 /* Interrupt Service Routine. The program jumps here every 10 ms. */ void interrupt ISR(void) { TMR0 = 100; /* Reload TMR0 = 100 */ /* Check if 100ms has elapsed. The basic timer rate is 10ms and we count 10 interrupts before implementing the controller algorithm */ time_now++; if(time_now == 10) { time_now = 0; Read_AD_Input(); /* Read A/D input */ ek = sk - yk; /* Calculate error term */ pk = b*ek + pk_1; wk = Kp*ek; /* Calculate output */ yk = wk + pk; yk = yk*DA_LSB; if(yk > 255) uk=255; else uk=(unsigned char) yk; PORTB = uk; DA_Write = 0; /* Write to D/A converter */ DA_Write = 1; pk_1 = pk; } T0IF = 0; /* Re-enable timer interrupts */ } 20

21 /* Main Program. The main program initializes the variables, A/D converter, D/A converter etc. and then waits in an endless loop for timer interrupts to occur every 100 ms */ main(void) { Kp = 279.0; T = 0.1; Ti = 6.6; b = Kp*T/Ti; pk = 0.0; pk_1 = 0.0; AD_LSB = 5000.0/1024.0; DA_LSB = 256.0/5000.0; TRISA = 1; TRISB = 0; /* PORTB is output */ TRISC = 0; /* RC0 is output */ sk = 2280.0; /* Set point input */ DA_Write = 1; /* Disable D/A converter */ Initialize_AD(); /* Initialize A/D converter */ Initialize_Timer();/* Initialize timer interrupts */ ei(); /* Enable interrupts */ for(;;); /* Wait for an interrupt */ } 21

22 As the reference input was set to 2280 mV, it is clear that the system response, although noisy, reaches the set-point with no steady-state error, as desired. 22 The step response of the designed closed- loop system


Download ppt "Lecture 11: Liquid Level Control System: A Case Study 1."

Similar presentations


Ads by Google