Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(EOD).Mechatronics.pdf
Скачиваний:
81
Добавлен:
23.08.2013
Размер:
5.07 Mб
Скачать

page 14

Gp( B)

=

B

1------------------- 0.5B

 

 

• Trying to eliminate the error in one step can require an extremely high (power) gain. When this gain is excessive we may use a less powerful controller.

4.1.2 Programming Examples

The following programs are examples of methods for programming using a few common languages.

These examples are for the Computer Boards DAS08-AOM board (The boards we used in the lab with Labview).

Please note that these programs have not been debugged.

page 15

4.1.2.1 - BASIC

• A simple example of the deadbeat controller is given below. This can be converted to many of the ‘modern’ version of basic that have appeared. Comments have been added to help clarify the operation

10 REM a control loop for the deadbeat controller example for 12 bit input and output 15 REM Written by H.Jack, July 17, 1997 - Not debugged

20 BASE = 330H; REM the base address for the card 20 T = 0.1; REM control system time step

40 M_LAST = 0; REM the current output is zero 50 E_LAST = 0; REM the current error

60 INPUT “ENTER SETPOINT [0 - 4095]” , R; REM get a setpoint 70 DO ; REM start the control loop

80 OUT BASE+2, 0; REM start the a to d conversion

90 WAIT T; REM an operating system specific timing function

100 C_HIGH = INP BASE+0; REM read current position most significant 8 bits 110 C_LOW = INP BASE+1; REM read current position least significant 4 bits 120 C_NOW = C_LOW/16 + C_HIGH*16

130 E_NOW = R - C_NOW; REM calculate the error

140 M_NOW = M_LAST + E_NOW - 0.5*E_LAST; REM the controller equation 150 IF (M_NOW < 0) THEN M_NOW = 0; REM prevent out of range case

160 IF (M_NOW > 4095) THEN M_NOW = 4095; REM prevent out of range case 170 M_HIGH = INT(M_NOW/256) ; REM find the 4 high bits of the 12 bit word 180 M_LOW = M_NOW - 256*M_HIGH; REM isolate the low 8 bits

190 OUT BASE+4, (M_LOW); REM set 8 low bits 200 OUT BASE+5, (M_HIGH); REM set 4 high bits

210 M_LAST = M_NOW; E_LAST = E_NOW; REM current values become last values 220 LOOP WHILE(ABS(E) < 0.001); REM continue looping until the error is small

4.1.2.2 - C

• The example program below should implement the deadbeat controller example given in this section,

page 16

/* A deadbeat controller for a Computer Boards DAS08-AOM card using 16 bit IO */ /* Written by H.Jack, July 17, 1997 - Not debugged */

#include <stdio> #include <conio.h>

main(){

 

int

base = 0x330, /* Base address for card */

 

r, c_now, /* Set up variables for equations */

 

e_now, e_last=0, /* error values */

 

m_now, m_last=0; /* control values */

double

T = 0.1; /* set the system time step */

printf(“Enter the Setpoint [0 - 4095]”); scanf(“%d”, r); /* Input a setpoint */

while(abs(e_last) < 1){ /* loop until the error is small */ outp(base+2, 0); /* start the a to d conversion process */ sleep(T); /* an operating system specific timing function */

c_now = inp(base+0)/16 + inp(base+1)*16; /*calculate the current value */ e_now = r - c_now; /* calculate current error */

m_now = m_last + e_now - 0.5 * e_last; /* the control equation */ if (m_now < 0) m_now = 0; /* keep the output in 0-4095 range */ if (m_now > 4095) m_now = 4095;

outp(base+4, m_now & 255); /* output 8 LSB */ outp(base+5, m_now>>8); /* output 4 MSB */

m_last = m_now; e_last = e_now; /* make current values last */

}

}

4.1.2.3 - Pascal

• The example program below should implement the deadbeat controller example given in this section,

page 17

{A deadbeat controller for a Computer Boards DAS08-AOM card using 16 bit IO }

{Written by H.Jack, July 17, 1997 - Not debugged }

program deadbeat(input, output);

var

base = 0x330, { Base address for card }

r, c_now, { Set up variables for equations } e_now, e_last=0, { error values }

m_now, m_last=0: integer; { control values }

T = 0.1: float; { set the system time step }

begin

writeln(‘Enter the Setpoint [0 - 4095]’); readln(r); { Input a setpoint }

while (abs(e_last) < 1) do{ loop until the error is small } begin

outp(base+2, 0); { start the a to d conversion process }---------

sleep(T); { an operating system specific timing function }---------

c_now := inp(base+0)/16 + inp(base+1)*16; {calculate the current value }-

---

e_now := r - c_now; { calculate current error }

m_now := m_last + e_now - 0.5 * e_last; { the control equation } if (m_now < 0) then

m_now := 0; { keep the output in 0-4095 range } if (m_now > 4095) then

m_now := 4095;

outp(base+4, m_now & 255); { output 8 LSB } -------

outp(base+5, m_now>>8); { output 4 MSB }---------

m_last := m_now; e_last := e_now; { make current values last }

end;

end.

4.1.2.4 - 6811 Assembler

page 18

• The example program below should implement the deadbeat controller example given in this section for a 6811 single chip microcontroller.

• As an exercise, implement the controller on a Basic Stamp chip.

Соседние файлы в предмете Электротехника