Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (963.77 KB, 38 trang )
ĐỒ ÁN TỐT NGHIỆP
TRANG 25 / 32
- Ưu điểm: Mô hình nhỏ gọn, thực hiện được các lệnh và thơng số điều khiển, kết
nối được với máy tính.
- Nhược điểm: Mạch chạy chưa ổn định, chưa đưa ra sự khác biệt giữa các cách
điều khiển khác nhau.
- Kết quả đạt được: Thiết kế được mơ hình hoạt động thực hiện gần đầy đủ các yêu
cầu ban đầu. Điều khiển được động cơ quay thuận, nghịch, đạt tốc độ mong muốn.
5.2 . Hướng phát triển
- Động cơ đạt đến tốc độ đặt nhanh hơn và ổn định hơn.
- Điều khiển động cơ vẫn giữ được tốc độ nếu thêm tải phụ vào.
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
ĐỒ ÁN TỐT NGHIỆP
TRANG 26 / 32
TÀI LIỆU THAM KHẢO
[1].https://vi.wikipedia.org/wiki/B%E1%BB%99_%C4%91i%E1%BB%81u_khi
%E1%BB%83n_PID
[2].https://voer.edu.vn/m/tim-hieu-ngon-ngu-lap-trinh-visual-basic/cae67df7
[3]. http://ww1.microchip.com
[4]. Nguyễn Đăng Quang (09-2009). Giáo trình Microsoft Visual Basic..
[5]. https://robotics.stackexchange.com/
[6]. Lê Đức Hạnh (2017). “Lập trình vi điều khiển học PIC và ứng dụng”
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
ĐỒ ÁN TỐT NGHIỆP
TRANG 27 / 32
PHỤ LỤC A
(ĐOẠN MÃ CHO VĐK)
#include <16f887.h>
#include
#DEVICE *=16 ADC=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,
NOLVP, NOCPD, NOWRT
#USE DELAY(CLOCK=20000000)
#use rs232(baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include
#include
#define k1 RD0
#define k2 RD1
#define k3 RD2
#define k4 RD3
#define k5 RD4
#define k6 RD5
#define k7 RD6
#define td RC2
#define ch RA5
#define xung RB0
int16 speed=0,speed1=0,temp=0,temp1=0,PresetSpeed=0,duty=0;
int8 count3=0,count30=0, i=0; int16 t;
int1 chieu=1; char c;
signed int16 e;
float sum=0,PWM;
void PID(void);
void PID() {
e=PresetSpeed-10*speed;
sum+=e;
PWM=(float)(1.455*e+0.0197*sum);
PWM=ceil(PWM);
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
ĐỒ ÁN TỐT NGHIỆP
TRANG 28 / 32
if(PWM>1023)
duty=1023;
else
{if(PWM<0)
duty=100;
else
duty=PWM;
}
set_pwm2_duty(duty);
}
#INT_RDA
Receive_isr()
{
c = getc();
if(c==202) { chieu=1; LCD_putcmd(0x8e); Printf(LCD_putchar," R");
PUTC(202); }
if(c==203) { chieu=0; LCD_putcmd(0x8e); Printf(LCD_putchar," L");
PUTC(203); }
if(c==204) { t=PresetSpeed/100; if(t<9) t++; else t=1; PresetSpeed = (PresetSpeed
%100)+t*100;
PUTC((PresetSpeed%1000)/100); delay_ms(100); PUTC((PresetSpeed
%100)+100);}
if(c==205) { t=(PresetSpeed%100)/10; if(t<9) t++; else t=0; PresetSpeed =
(PresetSpeed/100)*100+t*10+PresetSpeed%10;
PUTC((PresetSpeed%1000)/100); delay_ms(100); PUTC((PresetSpeed
%100)+100);}
if(c==206) { t=PresetSpeed%10; if(t<9) t++; else t=0; PresetSpeed =
(PresetSpeed/10)*10+t;
PUTC((PresetSpeed%1000)/100); delay_ms(100); PUTC((PresetSpeed
%100)+100);}
}
#INT_EXT
void ext_isr() {
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
ĐỒ ÁN TỐT NGHIỆP
TRANG 29 / 32
temp++;
temp1++;
//LCD_putcmd(0xCA); LCD_putchar(temp/10+0x30); LCD_putchar(temp%10+0x30);
}
#INT_TIMER1
void interrupt_timer1()
{
int8 hi,lo;
count3++;
count30++;
set_timer1(15535);
if(count3==3)
speed=temp;
temp=0;
PID();
count3=0;
}
if(count30==30)
speed1=temp1;
PUTC((speed1%1000)/100);
temp1=0;
LCD_putcmd(0xC8); //LCD_putchar((speed1%10000)/1000+0x30);
LCD_putchar((speed1%1000)/100+0x30);
LCD_putchar((speed1%100)/10+0x30);LCD_putchar(speed1%10+0x30);
count30=0; PUTC((speed1%100)+100);
}
}
void start()
{
ch = chieu;
LCD_putcmd(0xCe); if(chieu==1) Printf(LCD_putchar,"R
Printf(LCD_putchar,"L ");
enable_interrupts(int_timer1); //set_pwm2_duty(500);
while(1)
{
if(k2==0) {while(k2==0){} break;}
if(c==201) break;
}
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
");
else
ĐỒ ÁN TỐT NGHIỆP
TRANG 30 / 32
disable_interrupts(int_timer1); set_pwm2_duty(0);
LCD_putcmd(0xC0); Printf(LCD_putchar,"TOC DO: 0
}
void main()
{ trisa=0x00;
trisb=0x01;
trisd=0xff;
trisc=0x00;
"); PUTC(201);
//
LCD_init();
LCD_putcmd(0x80);
Printf(LCD_putchar,"TOC DO DAT 150 ");
LCD_putcmd(0x8e); if(chieu==1) Printf(LCD_putchar," R"); else
Printf(LCD_putchar," L");
LCD_putcmd(0xC0);
Printf(LCD_putchar,"TOC DO: 0
delay_ms(800);
"); PUTC(201);
setup_timer_1(t1_internal);
SET_TIMER1(15536); //T_dinhthoi = (65536-15536)/(20.000/4) = 10000us = 10ms
SETUP_CCP2(CCP_PWM);
SETUP_TIMER_2(T2_DIV_BY_1,254,1);
enable_interrupts(int_ext);
ext_int_edge(0,h_to_l);
set_pwm2_duty(0);
disable_interrupts(int_timer1);
// Khoi tao cho ngat ngoai
enable_interrupts(int_rda);
enable_interrupts(global);
ch=chieu;
td=0;
PresetSpeed=150;
while(1)
{
LCD_putcmd(0x80); Printf(LCD_putchar,"TOC DO DAT ");
LCD_putchar(PresetSpeed/100+0x30);LCD_putchar((PresetSpeed
%100)/10+0x30);LCD_putchar(PresetSpeed%10+0x30);
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
ĐỒ ÁN TỐT NGHIỆP
TRANG 31 / 32
if(k1==0) { while(k1==0) {} PUTC(200); start(); }
if(k3==0) { while(k3==0) {} chieu=1; LCD_putcmd(0x8e); Printf(LCD_putchar,"
R"); PUTC(202); }
if(k4==0) { while(k4==0) {} chieu=0; LCD_putcmd(0x8e); Printf(LCD_putchar,"
L"); PUTC(203); }
if(k5==0) { while(k5==0) {} t=PresetSpeed/100; if(t<9) t++; else t=1; PresetSpeed
= (PresetSpeed%100)+t*100;
PUTC((PresetSpeed%1000)/100); delay_ms(100); PUTC((PresetSpeed
%100)+100);}
if(k6==0) { while(k6==0) {} t=(PresetSpeed%100)/10; if(t<9) t++; else t=0;
PresetSpeed = (PresetSpeed/100)*100+t*10+PresetSpeed%10;
PUTC((PresetSpeed%1000)/100); delay_ms(100); PUTC((PresetSpeed
%100)+100); }
if(k7==0) { while(k7==0) {} t=PresetSpeed%10; if(t<9) t++; else t=0; PresetSpeed
= (PresetSpeed/10)*10+t;
PUTC((PresetSpeed%1000)/100); delay_ms(100); PUTC((PresetSpeed
%100)+100);}
if(c==200) { PUTC(200); start(); }
//LCD_putcmd(0xC0); Printf(LCD_putchar,"TOC DO: 0
}
}
PHỤ LỤC B
ĐOẠN MÃ GIAO TIẾP MÁY TÍNH
Điều Khiển Động Cơ DC Dùng Thuật Tốn PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
");
ĐỒ ÁN TỐT NGHIỆP
TRANG 32 / 32
Private Sub Command5_Click()
If st = 0 Then
MSComm1.Output = Chr(204)
End If
End Sub
Private Sub Command6_Click()
If st = 0 Then
MSComm1.Output = Chr(205)
End If
End Sub
Private Sub Command7_Click()
If st = 0 Then
MSComm1.Output = Chr(206)
End If
End Sub
Private Sub Form_Load()
st = 0
N=0
MSComm1.CommPort = 4
MSComm1.Settings = "4800,n,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = 2 Then
nd = Asc(MSComm1.Input)
Label2.Caption = Str(nd)
If nd < 100 Then
If st = 0 Then
Label2.Caption = Mid(Str(nd), 2, 1) + Mid(Label2.Caption, 2, 2)
Else
Label3.Caption = Mid(Str(nd), 2, 1) + Mid(Label2.Caption, 2, 2)
End If
Else
If nd < 200 Then
nd = nd - 100
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính
ĐỒ ÁN TỐT NGHIỆP
TRANG 33 / 32
If nd < 10 Then s = "0" + Mid(Str(nd), 2, 1) Else s = Mid(Str(nd),
2, 2)
If st = 0 Then
Label2.Caption = Mid(Label2.Caption, 1, 1) + s
Else
Label3.Caption = Mid(Label3.Caption, 1, 1) + s
End If
Else
If nd = 200 Then
st = 1
End If
If nd = 201 Then
st = 0
Label3.Caption = "0"
End If
If nd = 202 Then
Label4.Caption = "R"
End If
If nd = 203 Then
Label4.Caption = "L"
End If
End If
End If
End If
End Sub
Điều Khiển Động Cơ DC Dùng Thuật Toán PID
Với Sự Điều Khiển Và Giám Sát Từ Máy Tính