Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328...
Transcript of Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328...
![Page 1: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/1.jpg)
Digital PID: Interfacing the uC PIC18F and Matlab
Autores:
César Domingues
Rafael Mariano
Revisão:
Heitor Vinicius Mercaldi
Vilma A. Oliveira
![Page 2: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/2.jpg)
Contents
1. System overview
2. Plant characteristics
3. Microcontroler algorithm
4. Development
5. Implementation of the algorithm in the
microcontroller
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 3: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/3.jpg)
System overview
MICROCONTROLLER
POWER DRIVER
chopper PWM
MOTOR ENCODER
MICROCOMPUTER
RS-232
interface Feedback control system components
MATLAB
PIC18F
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 4: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/4.jpg)
Plant Characteristics
Encoder
Resolution 1024
DC Motor
Permanent Magnet
Voltage 12V
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 5: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/5.jpg)
Motor Transfer Function
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 6: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/6.jpg)
Controler Transfer Function
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 7: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/7.jpg)
Oficina Controladores PID
09/05/2014
Hardware
Conversor
RS232
PIC18F45K22
+5V 0V
Oscilator
8MHz
Encoder
PWM
Output
Motor
RESET
RC2
RC0 MCLR
RC7
RC6
OSC1
OSC2
VSS VDD
Kit PIC18F45K22
Plant
Power
Amplifier
![Page 8: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/8.jpg)
Specific QEI Hardware
Motor supply
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 9: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/9.jpg)
Main Routine Begin
Waiting
Serial character from
MATLAB
Read serial
‘uart_rd’
Compute PID & set PWM
‘PWM1_set_duty(un)’
Send speed response
‘freq_txt’
‘a’
‘b’
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 10: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/10.jpg)
PID &
PWM
Aquisition
points ?
Set reference
and registers
Compute PID output ‘un’
Read encoder counter
‘TMR1H and TMR1L’
and
Compute speed error ‘en = referencia – frequency’
PID timer
overflow ? Ts=1ms
Interrupt clear
Set PWM dutty = 0
Return
Compute PID & set PWM Sub-routine
Set duty cycle ‘PWM1_set_duty(un)’
‘>501’
‘<501’
‘No’
Running
encoder counter
‘Yes’
Increment points
counter
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 11: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/11.jpg)
Aquisition
points ?
Send to MATLAB
trought RS-232
‘uart1_write_text(freq
_txt)’
Send speed
response
Return
Send Speed response Sub-routine
‘>501’
‘<501’
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 12: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/12.jpg)
Lab. Controle de Sistemas
SEL-0328 14/10/2014
mikroC integrated development
environment (IDE)
![Page 13: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/13.jpg)
Implementation of the Algorithm in the
Microcontroller
while(i<501){
…
frequency = frequency + (TMR1H * 256 + TMR1L);
frequency = frequency*1000;
frequencias[i] = frequency;
frequency = (frequency/1024)*2*pi;
en = referencia - frequency;
i++;
//Calculate the error by a difference equation
un = 0.007996*en - en1*0.01335 + en2*0.005612 + 0.1651*un1 + 0.8349*un2; //0.001
en2 = en1;
en1 = en;
un2 = un1;
un1 = un;
un = un*255;
un = (int)un;
//seta pwm
PWM1_set_duty(un);
}
//controller output : u(n-1) = un1 u(n-2) = un2
//erro : e(n-1) = en1 e(n-2) = en2
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 14: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/14.jpg)
Gravação
Lab. Controle de Sistemas
SEL-0328 14/10/2014
![Page 15: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet](https://reader030.fdocuments.in/reader030/viewer/2022040904/5e7838f1764b185a9535da5b/html5/thumbnails/15.jpg)
END
Thank you very much.
Lab. Controle de Sistemas
SEL-0328 14/10/2014