Escolar Documentos
Profissional Documentos
Cultura Documentos
9
LABORATORIO DE CONTROL CON MICROPROCESADORES
IMPLEMENTACIN DIGITAL DE ALGORITMOS DE CONTROL
OBJETIVO
Familiarizar al estudiante con el manejo de conversores Anlogos /
Digitales y salidas PWM que posee el micro controlador Atmega164.
Familiarizar al estudiante con las tcnicas de implementacin digital de
los algoritmos de control ms comunes utilizados en los sistemas de
control y aplicarlos al control en lazo cerrado de la velocidad de un
motor de corriente continua (MOTOMATIC).
PREPARATORIO
A travs del prtico de comunicacin serial el computador enva los
comandos necesarios al micro controlador para que este realice la
medicin de una seal analgica conectada al conversor A/D. Esta seal
es el voltaje de realimentacin acondicionado, proveniente de un taco
generador y corresponde a la velocidad del motor del MOTOMATIC. De
igual manera, el computador consulta en el micro controlador el valor de
la referencia de velocidad (set point).
La referencia o set-point de velocidad podr ser variada mediante el uso
de las teclas conectadas al micro controlador
Tecla 1: incremento set point en 2
Tecla 2: incremento set point en 10
Tecla 3: decremento set point en 2
Tecla 4: decremento set point en 10
El computador recibe las seales de set-point y de realimentacin, y
obtiene el error.
La seal de error es la entrada de la ecuacin de diferencias
correspondiente al algoritmo P.I.D. El resultado que arroja el algoritmo
P.I.D. deber ser apropiadamente limitado y escalado para que su rango
de variacin est siempre entre 0 y 255 (FFH).
Dim X As Integer
Dim Y As Single
Dim Porc As Long
Dim X_1 As Word
Dim Y_1 As Single
Setpoint = 0
'////CONFIGURO PWM
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down ,
Prescale = 1
'///CONFIGURO LCD
Config Lcd = 16 * 2
Config Lcdbus = 4
Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 ,
Db7 = Porta.3 , E = Porta.5 , Rs = Porta.4
Cls
Cursor Of
Cls
'///ACTIVO INTERRUPCIONES PARA PULSADORES Y COMUNICACION
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 ,
Databits = 8
On Urxc Comp
Enable Interrupts
Enable Urxc
On Int0 Pulsadores
Config Int0 = Falling
Enable Int0
Enable Interrupts
'////CONFIGURO ADC
Const K = 100 / 1024
Const P = 100 / 255
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
'////PROGRAMA PRINCIPAL
Do
X = Getadc(6)
Y=X*K
Temp = Y * 1
X_1 = Setpoint
Y_1 = X_1 * P
Porc = Y_1 * 1
Locate 1 , 1
Lcd "SETPOINT(" ; Setpoint ; "):" ; Porc ; "% "
Locate 2 , 1
Lcd "REALIMENT: " ; Temp ; "%
"
Pwm1a = Pid
X = Getadc(6)
X=X/4
Loop
'////INTERRUPCION DE LOS PULSADORES
Pulsadores:
If R_data = 65 Then
Realim = Getadc(6)
Print Setpoint
X1 = ""
End If
If R_data = 66 Then
Realim = Getadc(6)
Realim = Realim / 4
Print Realim
X1 = ""
End If
If R_data = 67 Then
Pid = Val(x1)
X1 = ""
End If
Return
LCD1
LM016L
PRCTICA No.9
R8(1)
R8
D0
D1
D2
D3
D4
D5
D6
D7
R1
RS
RW
E
VSS
VDD
VEE
1K
R2
7
8
9
10
11
12
13
14
4
5
6
1
2
3
1K
1K
R3
LCD1(VDD)
LCD1(VEE)
1
2
3
4
RS
EN
1K
U1
R9
A
B
C
D
INT
110R
INT
A
B
ENTRADA ANALOGICA
U1(AVCC)
C
D
RV1(2)
40
41
42
43
44
1
2
3
PB0/XCK0/T0/PCINT8
PB1/T1/CLKO/PCINT9
PB2/AIN0/INT2/PCINT10
PB3/AIN1/OC0A/PCINT11
PB4/SS/OC0B/PCINT12
PB5/MOSI/PCINT13
PB6/MISO/PCINT14
PB7/SCK/PCINT15
9
10
11
12
13
14
15
16
PD0/RXD0/PCINT24
PD1/TXD0/PCINT25
PD2/INT0/RXD1/PCINT26
PD3/INT1/TXD1/PCINT27
PD4/OC1B/XCK1/PCINT28
PD5/OC1A/PCINT29
PD6/ICP/OC2B/PCINT30
PD7/OC2A/PCINT31
29
27
4
AREF
AVCC
RESET
ATMEGA164P
P1
28%
RV1
CON
1k
1
6
2
7
3
8
4
9
DCD
DSR
RXD
RTS
TXD
CTS
DTR
RI
ERROR
COMPIM
PA0/ADC0/PCINT0
PA1/ADC1/PCINT1
PA2/ADC2/PCINT2
PA3/ADC3/PCINT3
PA4/ADC4/PCINT4
PA5/ADC5/PCINT5
PA6/ADC6/PCINT6
PA7/ADC7/PCINT7
PC0/SCL/PCINT16
PC1/SDA/PCINT17
PC2/TCK/PCINT18
PC3/TMS/PCINT19
PC4/TDO/PCINT20
PC5/TDI/PCINT21
PC6/TOSC1/PCINT22
PC7/TOSC2/PCINT23
XTAL1
XTAL2
37
36
35
34
33
32
31
30
19
20
21
22
23
24
25
26
8
7
1
2
3
4
RS
EN
CON