help in programming pic 16f877a by mikro c

Thread Starter

mastertiger

Joined Jul 9, 2012
24
my project is 4 axes cnc with robotic arm
i finish cnc 4 axes (thank god )
i work know in programming pic 16f877a for robotic arm
i use dc motor for production line (portb.f7)
drive for 3 stepper motor take 6 pin from pic for direction and step
(portb from pin 6 to 1 )
2 motor for robotic arm
1 motor for fixture (to automatic fixed the work piece in cnc)
1 servo motor for griper portb.f0
1-start sw1 (portc.f0)
1-sensor in production line (portc.f1)
1-sensor in zero point (origin point of cnc)(portc.f2)
1- stop sw2 (portc.f3)
i make very large program to make it easy to any one to understand
sequence
{
when i push sw1(portc.f0) dc motor for production line run
when work piece cut sensor dc motor stop motor of robotic arm run (one by one ) griper close take work piece to fixture and put it then fixture close
after cnc finish back to zero point robotic move again to take work piece
then dc motor run again }
problem
sensor in zero point active before cnc run so robotic do not stop until cnc start it work to take work piece after put in fixture
this is the program
Rich (BB code):
///////////////////////4 axes cnc machine with robotic arm//////////////////////
///////////////////////////////tiger team///////////////////////////////////////


void main() {


int a;                // variable a
int b;                // variable b
int c;                // variable c
int d;                // variable d
int e;                // variable e
int f;                // variable f
int h;                // variable i
int j;                // variable j
int k;                // variable k
int i;                // variable l
int m;                // variable m
int n;                // variable n
int o;                // variable o
int p;                // variable p
int q;                // variable q
int r;                // variable r
int s;                // variable s
int t;                // variable t
int u;                // variable u
int v;                // variable v
int w;                // variable w
int x;                // variable x
int y;                // variable y
int z;               // variable z
trisa=0;             // porta output
trisb=0;             // portb output
trisd=0;             // portd output
portd=0;              // portd output zero
trisc=0xff;           // portc input
portb=0;              // portb output zero
porta=0;                // porta output zero
loop:                 // loop for all program
if(portc.f0==0)        // if push start

portb=0b10000000;       // run dc motor

if(portc.f1==0)       // if work piece cut sensor
{

portb=0;                     // dc motor stop
for(a=0;a<10;a++)          //loop for link 2 down to take work piece
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);

}

portb=0;
for(b=0;b<10;b++)  // graper close
{
portb=0b00000001;
delay_us(3000);
portb=0;
delay_ms(20);
}

for(c=0;c<10;c++)    //loop for link 2 up
{
portb=0b001000000;
delay_ms(100);
portb=0b000000000;
delay_ms(100);
}
portb=0;
for(d=0;d<10;d++)          //loop for motor base  go to fixture
{
portb=0b00011000;
delay_ms(100);
portb=0b00010000;
delay_ms(100);

}
portb=0;
for(e=0;e<10;e++)    //loop for link2 down to put work piece in fixture
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);

}

portb=0;
for(f=0;f<10;f++)      //motor of fixture close
{
portb=0b000000110;
delay_ms(100);
portb=0b000000010;
delay_ms(100);
}
portb=0;
for(h=0;h<20;h++)    // graper open to leave work piece in fixture
{
portb=0b00000001;
delay_us(1000);
portb=0b00000000;
delay_ms(20);
}
for(j=0;j<10;j++)    // motor of base go back to production line
{
portb=0b000001000;
delay_ms(100);
portb=0b000000000;
delay_ms(100);
}
portb=0;
if(portc.f2==1){while(portc.f2==1){   // problem is here 

if(portc.f2==0)     // if cnc finish
{
for(k=0;k<10;k++)       // motor base go to fixture
{
portb=0b00011000;
delay_ms(100);
portb=0b00010000;
delay_ms(100);
}
portb=0;
for(i=0;i<10;i++)  // link 2 down to take work piece from fixture
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);
}
portb=0;
for(m=0;m<10;m++) // graper close to take work piece from fixture
{
portb=0b00000001;
delay_us(3000);
portb=0b00000000;
delay_ms(20);
}
portb=0;
for(n=0;n<10;n++)      //motor of fixture open
{
portb=0b00000010;
delay_ms(100);
portb=0b00000000;
delay_ms(100);
}
portb=0;
for(p=0;p<10;p++)      //loop for link 2 up
{
portb=0b00100000;
delay_ms(100);
portb=0b00000000;
delay_ms(100);
}
portb=0;
for(q=0;q<10;q++)    //motor of base take work piece to production line
{
portb=0b00001000;
delay_ms(100);
portb=0b00000000;
delay_ms(100);
}
portb=0;

for(r=0;r<10;r++)     // link 2 down to put work piece in production line
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);
}
portb=0;
for(s=0;s<25;s++) //graper open to leave work piece on production line
{
portb=0b00000001;
delay_us(1000);
portb=0b00000000;
delay_ms(20);
}
portb=0;
portb=0b10000000;
delay_ms(9000);
portb=0b00000000;



}}
}
goto loop;
}
i use this code for make robotic stop until cnc finish and back again
if(portc.f2==1){while(portc.f2==1){

if(portc.f2==0)
but do not work
then what i missed
please help
thanks
this is Proteus file
i connected led Instead of drive and motor for simulation
http://www.mediafire.com/download.php?7zo7c2n5eniaenb
thanks i solve my problem
Rich (BB code):
///////////////////////4 axes cnc machine with robotic arm//////////////////////
///////////////////////////////tiger team///////////////////////////////////////
//////////////////////////////mohammed aly//////////////////////////////////////
/////////////////////////////ahmed mohammed/////////////////////////////////////
/////////////////////////////abdel rahman///////////////////////////////////////
/////////////////////////////sherif/////////////////////////////////////////////

void main() {


int a;                // variable a
int b;                // variable b
int c;                // variable c
int d;                // variable d
int e;                // variable e
int f;                // variable f
int h;                // variable i
int j;                // variable j
int k;                // variable k
int i;                // variable l
int m;                // variable m
int n;                // variable n
int o;                // variable o
int p;                // variable p
int q;                // variable q
int r;                // variable r
int s;                // variable s
int t;                // variable t
int u;                // variable u
int v;                // variable v
int w;                // variable w
int x;                // variable x
int y;                // variable y
int z;               // variable z
trisa=0;             // porta output
trisb=0;             // portb output
trisd=0;             // portd output
portd=0;              // portd output zero
trisc=0xff;           // portc input
portb=0;              // portb output zero
porta=0;                // porta output zero
loop:                 // loop for all program
if(portc.f0==0)        // if push start

portb=0b10000000;       // run dc motor

if(portc.f1==0)       // if work piece cut sensor
{

portb=0;                     // dc motor stop
for(a=0;a<10;a++)          //loop for link 2 down to take work piece
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);

}

portb=0;
for(b=0;b<10;b++)  // graper close
{
portb=0b00000001;
delay_us(3000);
portb=0;
delay_ms(20);
}

for(c=0;c<10;c++)    //loop for link 2 up
{
portb=0b001000000;
delay_ms(100);
portb=0b000000000;
delay_ms(100);
}
portb=0;
for(d=0;d<10;d++)          //loop for motor base  go to fixture
{
portb=0b00011000;
delay_ms(100);
portb=0b00010000;
delay_ms(100);

}
portb=0;
for(e=0;e<10;e++)    //loop for link2 down to put work piece in fixture
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);

}

portb=0;
for(f=0;f<10;f++)      //motor of fixture close
{
portb=0b000000110;
delay_ms(100);
portb=0b000000010;
delay_ms(100);
}
portb=0;
for(h=0;h<20;h++)    // graper open to leave work piece in fixture
{
portb=0b00000001;
delay_us(1000);
portb=0b00000000;
delay_ms(20);
}
for(j=0;j<10;j++)    // motor of base go back to production line
{
portb=0b000001000;
delay_ms(100);
portb=0b000000000;
delay_ms(100);
}
portb=0;
while(portc.f2!=1)
{
portb=0;
portd=0b11111111;
}
if(portc.f2==1)     // if cnc finish
{
while(portc.f2!=0)
{
portb=0;
portd=0b11111111;
}

for(k=0;k<10;k++)       // motor base go to fixture
{
portb=0b00011000;
delay_ms(100);
portb=0b00010000;
delay_ms(100);
}
portb=0;
for(i=0;i<10;i++)  // link 2 down to take work piece from fixture
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);
}
portb=0;
for(m=0;m<10;m++) // graper close to take work piece from fixture
{
portb=0b00000001;
delay_us(3000);
portb=0b00000000;
delay_ms(20);
}
portb=0;
for(n=0;n<10;n++)      //motor of fixture open
{
portb=0b00000010;
delay_ms(100);
portb=0b00000000;
delay_ms(100);
}
portb=0;
for(p=0;p<10;p++)      //loop for link 2 up
{
portb=0b00100000;
delay_ms(100);
portb=0b00000000;
delay_ms(100);
}
portb=0;
for(q=0;q<10;q++)    //motor of base take work piece to production line
{
portb=0b00001000;
delay_ms(100);
portb=0b00000000;
delay_ms(100);
}
portb=0;

for(r=0;r<10;r++)     // link 2 down to put work piece in production line
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);
}
portb=0;
for(s=0;s<25;s++) //graper open to leave work piece on production line
{
portb=0b00000001;
delay_us(1000);
portb=0b00000000;
delay_ms(20);
}
portb=0;
portb=0b10000000;
delay_ms(9000);
portb=0b00000000;



}
}
goto loop;
}
 
Last edited by a moderator:

BMorse

Joined Sep 26, 2009
2,675
next time try something like this instead:

Rich (BB code):
if(portc.f2){while(portc.f2){};};  When checking to see if it is ==1 or TRUE

else if(!portc.f2){ };                  When checking to see if it is ==0 or False
 

Thread Starter

mastertiger

Joined Jul 9, 2012
24
new problem help please
i need griper be close all the time when motor move
but pic read it sequence
so can i make pin for servo motor of griper give pulse and at the same time motor run
or i need to use pwm and how can i used it to do this
Rich (BB code):
for(b=0;b<1000;b++)  // graper close
{
portb=0b00000001;
delay_us(3000);
portb=0;
delay_ms(20);
}
and in the same time
Rich (BB code):
for(c=0;c<10;c++)    //loop for link 2 up
{
portb=0b001000000;
delay_ms(100);
portb=0b000000000;
delay_ms(100);
}
portb=0;
for(d=0;d<10;d++)          //loop for motor base  go to fixture
{
portb=0b00011000;
delay_ms(100);
portb=0b00010000;
delay_ms(100);

}
portb=0;
for(e=0;e<10;e++)    //loop for link2 down to put work piece in fixture
{
portb=0b01100000;
delay_ms(100);
portb=0b01000000;
delay_ms(100);

}

portb=0;
for(f=0;f<10;f++)      //motor of fixture close
{
portb=0b000000110;
delay_ms(100);
portb=0b000000010;
delay_ms(100);
}
portb=0;
thanks
 
Last edited by a moderator:

BMorse

Joined Sep 26, 2009
2,675
Why don't you separate each one in its own subroutine??
Example:
Rich (BB code):
void gripper_close(){
for(b=0;b<1000;b++)  // graper close
{
portb=0b00000001;
delay_us(3000);
portb=0;
delay_ms(20);
}
}//end gripper close 

void fixture_close()
{
 for(f=0;f<10;f++)      //motor of fixture close
{
portb=0b000000110;
delay_ms(100);
portb=0b000000010;
delay_ms(100);
}
portb=0;                      
}//end fixture close
then you can just call that sub routine when needed from your main loop....

example:

Rich (BB code):
void main_loop()
{
gripper_close(); //close gripper fixture_close(); //close fixture​
}
OR

You will definitely have to start using timers and interrupts to actuate your servos, then you can control multiple servos at once, take a look here.... >>> http://www.ermicro.com/blog/?p=771
 

Thread Starter

mastertiger

Joined Jul 9, 2012
24
Why don't you separate each one in its own subroutine??
Example:
Rich (BB code):
void gripper_close(){
for(b=0;b<1000;b++)  // graper close
{
portb=0b00000001;
delay_us(3000);
portb=0;
delay_ms(20);
}
}//end gripper close 

void fixture_close()
{
 for(f=0;f<10;f++)      //motor of fixture close
{
portb=0b000000110;
delay_ms(100);
portb=0b000000010;
delay_ms(100);
}
portb=0;                      
}//end fixture close
then you can just call that sub routine when needed from your main loop....

example:

Rich (BB code):
void main_loop()
{
gripper_close(); //close gripper fixture_close(); //close fixture​
}
OR
thanks for replay
if i do that gripper close then fixture close after it
i need to do the both thing in the same time
 
Top