PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > PIC - Thiết kế và Ứng dụng

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 09-05-2009, 12:15 PM   #1
ProBK
Nhập môn đệ tử
 
Tham gia ngày: Feb 2009
Bài gửi: 5
:
Unhappy Warning trong CCS

em viết luật mờ để đk động cơ, trong chương trình dùng 3 hàm con, dùng timer1 để ngắt lấy mẫu 10ms, timer2 để đk PWM, timer5 để tính vận tốc. khi biên dịch thì CCS báo "interrupts disable during call to prevent re-entrancy:...". Em ko hiểu sao chương trình ko ngắt đc. code của em như thế này:
#include <18F2331.h>
#include <math.h>
#include <stdio.h>
#use I2C(slave,sda=PIN_C4,scl=PIN_C5,address=0x01,force _HW,slow)
#use delay (clock=20000000)
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT
//================================================== ===========================
#define thuan PIN_B6
#define nghich PIN_B7
#byte T5CON =0xfb7
#bit dau=QEICON.5
float uet[7], udet[7], u[7][7],max,et,det,v_do,v_do1,duty;
int a,b;
signed int32 counter,goc_dat,goc_do,p;
//================================================== ======
void tinhp(int i, int j)
{ if (i==0)
{if ((j==0)|(j==1)|(j==2)) p=-1023;
else if (j==4) p=-682;
else if (j==5) p=-341;
else if (j==6) p=0;break;}
else if (i==1)
{if (j==0) p=-1023;
else if ((j==1)|(j==2)|(j==3)) p=-682;
else if (j==4) p=-341;
else if (j==5) p=0;
else if (j==6) p=341;break;}
else if (i==2)
{if (j==0) p=-1023;
else if (j==1) p=-682;
else if ((j==2)|(j==3)) p=-341;
else if (j==4) p=0;
else if (j==5) p=341;
else if (j==6) p=682;break;}
else if (i==3)
{if (j==0) p=-1023;
else if (j==1) p=-682;
else if (j==2) p=-341;
else if (j==3) p=0;
else if (j==4) p=341;
else if (j==5) p=682;
else if (j==6) p=1023;break;}
else if (i==4)
{if (j==0) p=-682;
else if (j==1) p=-341;
else if (j==2) p=0;
else if ((j==3)|(j==4)) p=341;
else if (j==5) p=682;
else if (j==6) p=1023;break;}
else if (i==5)
{if (j==0) p=-341;
else if (j==1) p=0;
else if (j==2) p=341;
else if ((j==3)|(j==4)|(j==5)) p=682;
else if (j==6) p=1023;break;}
else if (i==6)
{if (j==0) p=0;
else if (j==1) p=341;
else if (j==2) p=682;
else if ((j==3)|(j==4)|(j==5)|(j==6)) p=1023;break;}
}

//================================================== ===========================
#INT_TIMER1
void MOu(void)
{int i,j;
counter=poscnt;
goc_do=(counter-32768); et=((goc_dat-goc_do)*3.14)/180;
v_do=208333/vreg/8;
v_do=v_do/6.28;

det=v_do-v_do1;

//Mờ et===================
if (et<=-5)
{ uet[0]=1; uet[1]=0; uet[2]=0; uet[3]=0; uet[4]=0; uet[5]=0; uet[6]=0;
break;
}
else if (et<=-2.5)
{uet[0]= (et-2.5)/1.25; uet[1]=1-uet[0];uet[2]=0; uet[3]=0; uet[4]=0;
uet[5]=0; uet[6]=0;break;
}
else if (et<=-1.25)
{uet[0]=0; uet[1]=(et-1.25)/1.25; uet[2]=1-uet[1]; uet[3]=0; uet[4]=0;
uet[5]=0; uet[6]=0;break;
}
else if (et<=0)
{uet[0]=0; uet[1]=0; uet[2]=et/1.25; uet[3]=1-uet[2]; uet[4]=0;
uet[5]=0; uet[6]=0;break;
}
else if (et<=1.25)
{uet[0]=0; uet[1]=0; uet[2]=0; uet[3]=(1.25-et)/1.25; uet[4]=1-uet[3];
uet[5]=0; uet[6]=0;break;
}
else if (et<=2.5)
{ uet[0]=0; uet[1]=0; uet[2]=0; uet[3]=0; uet[4]= (2.5-et)/1.25;
uet[5]=1-uet[4]; uet[6]=0;break;
}
else if (et<=5)
{ uet[0]=0; uet[1]=0; uet[2]=0; uet[3]=0; uet[4]=0;
uet[5]=(5-et)/1.25; uet[6]=1-uet[5];break;
}
else
{ uet[0]=0; uet[1]=0; uet[2]=0; uet[3]=0; uet[4]=0; uet[5]=0; uet[6]=1;
break;
}

//Mờ det=============================
if (det<=-5)
{ udet[0]=1; udet[1]=0; udet[2]=0; udet[3]=0; udet[4]=0; udet[5]=0;
udet[6]=0; break;
}
else if (det<=-2.5)
{udet[0]= (det-2.5)/1.25; udet[1]=1-udet[0];udet[2]=0; udet[3]=0;
udet[4]=0; udet[5]=0; udet[6]=0;break;
}
else if (det<=-1.25)
{udet[0]=0; udet[1]=(det-1.25)/1.25; udet[2]=1-udet[1]; udet[3]=0;
udet[4]=0; udet[5]=0; udet[6]=0;break;
}
else if (det<=0)
{udet[0]=0; udet[1]=0; udet[2]=det/1.25; udet[3]=1-udet[2]; udet[4]=0;
udet[5]=0; udet[6]=0;break;
}
else if (det<=1.25)
{udet[0]=0; udet[1]=0; udet[2]=0; udet[3]=(1.25-det)/1.25;
udet[4]=1-udet[3]; udet[5]=0; udet[6]=0;break;
}
else if (det<=2.5)
{ udet[0]=0; udet[1]=0; udet[2]=0; udet[3]=0; udet[4]= (2.5-det)/1.25;
udet[5]=1-udet[4]; udet[6]=0; break;
}
else if (det<=5)
{ udet[0]=0; udet[1]=0; udet[2]=0; udet[3]=0; udet[4]=0;
udet[5]=(5-det)/1.25; udet[6]=1-udet[5];break;
}
else
{ udet[0]=0; udet[1]=0; udet[2]=0; udet[3]=0; udet[4]=0; udet[5]=0;
udet[6]=1;break;
}

for (i=0;i<=6; i++)
{ for (j=0;j<=6; j++)
{if (uet[i] < udet[j])
u[i][j]=uet[i];
else
u[i][j]=udet[j];
}
}
for (i=0;i<=6;i++)
{ for (j=0;j<=6;j++)
{max=u[0][0];
if( max<=u[i][j] )
{max= u[i][j];a=i;b=j;}

}
}
tinhp(a,b);
if(p>=0)
{
output_bit(thuan,1);
output_bit(nghich,0);
duty=(max*p);
}
else
{
output_bit(thuan,0);
output_bit(nghich,1);
duty=-(max*p);
}

set_pwm1_duty(duty);
v_do1=v_do;

set_timer1(-50000);
}
//================================================== ===========================
void main()
{
set_tris_a(0x1A);
set_tris_b(0x00);
set_tris_c(0x00);

enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);

setup_timer_2(T2_DIV_BY_16,255,1);
set_timer2(255);
setup_ccp1(CCP_PWM);
setup_timer_5(T5_INTERNAL|T5_DIV_BY_8);
bit_set(cap1con,6);//cho phep doc ve toc do
QEICON = 0x38; //dat che do cho bo feedback
DFLTCON = 0x7e;
maxcnt=65533;//dem toi khi tran counter
poscnt=32768;
goc_dat=100;
vreg=0;
output_bit(thuan,1);
output_bit(nghich,0);
set_pwm1_duty(10);

v_do1=208333/vreg/8;
v_do1=v_do1/6.28;
set_timer1(-50000);
while(true)
{}
}
Các pak nào cao thủ giúp em với. chẳng hiểu sao ko ngắt đc, Hix
ProBK vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 12:42 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam