Page 3 of 5

Re: Servo Controlling using PIC16F877A

PostPosted: Sat Apr 10, 2010 12:46 pm
by sich
Can you try ur program with two LEDs first? When you send 'o', LED1 lights up. When you send 'p', LED2 lights up. See what's the outcome. Try to debug ur program part by part.

Re: Servo Controlling using PIC16F877A

PostPosted: Sat Apr 10, 2010 11:42 pm
by Han Giap
hi,,

@ shahrul
i have no problem compile the code using MPLAB with HIgh tech C... i declare the all portB as output..

example: this works..
CODE: SELECT_ALL_CODE
if(a=='u')//Base Up
      {while(a=='u')
      {
         servo2=1;         //port B2
         servo0=1;                  //port B1
         servo1=0;                   //port B3
      }
      }


problem happen when
CODE: SELECT_ALL_CODE
if(a=='o')   //Gripper Open
{
   for(i=0;i<50;i++)      
      {
      servo5=1;         //port B5=1
      DelayMs(1);
      DelayUs(250);
      DelayUs(50);
      DelayUs(250);
      DelayUs(250);      
      
      servo5=0;         //port B5=0
      DelayMs(18);      
      DelayUs(200);
   }
}
if(a=='p')   //Gripper Close
{
   for(i=0;i<50;i++)      
      {
      servo5=1;         //port B5=1
      DelayMs(1);         
      DelayUs(500);
                                                
      servo5=0;         //port B5 =0
      DelayMs(18);      
      DelayUs(500);
      }
}



@sich

yup i try before, i can control the ON, OFF of the LED or output... 0V or 5V

problem occur when i apply the delay (refer as above)


i also duno wat wrong = = :cry:

thanks guys for replying.. :D

Re: Servo Controlling using PIC16F877A

PostPosted: Mon Apr 12, 2010 10:55 am
by sich
What about this:

if(a=='o') //Gripper Open
{
LED1=1;
for(i=0;i<50;i++)
{
LED1=0;
servo5=1; //port B5=1
DelayMs(1);
DelayUs(250);
DelayUs(50);
DelayUs(250);
DelayUs(250);

LED2=1;
servo5=0; //port B5=0
DelayMs(18);
DelayUs(200);
LED2=0;
}

By doing this, you'll know where your program stucked.

Re: Servo Controlling using PIC16F877A

PostPosted: Tue Apr 13, 2010 3:08 am
by shahrul
You can try program servo using Timer Interrupt. It's aesier. To view program and the video, see here.

Re: Servo Controlling using PIC16F877A

PostPosted: Wed Apr 14, 2010 8:26 am
by ober
Shahrul, nice work you have there!

Re: Servo Controlling using PIC16F877A

PostPosted: Thu Apr 15, 2010 10:47 am
by Han Giap
shahrul WROTE:You can try program servo using Timer Interrupt. It's aesier. To view program and the video, see here.


hi Shahrul,

thanks for the info... very appreciate it 8-)

i would like to know... is ur port A as input? n ur servo motor connected to port C (CCP)?

thanks :D

Re: Servo Controlling using PIC16F877A

PostPosted: Thu Apr 15, 2010 11:01 am
by shahrul
Han Giap WROTE:hi Shahrul,

thanks for the info... very appreciate it 8-)

i would like to know... is ur port A as input? n ur servo motor connected to port C (CCP)?

thanks :D

Port A as analog input to set Servo Position value. refer " read_a2d(0) ", that is read channel 0.
Servo at RC0. refer " #define servo RC0 ". This output not using CCP Module, as I describe, just using counter in the interrupt function.

As alternative, you don't need analog input, you can set servo position manually.
Eg,
position=10;
for(i=0;i<100;i++) __delay_ms(10);
position=50;
for(i=0;i<100;i++) __delay_ms(10);

wish you good try.

Re: Servo Controlling using PIC16F877A

PostPosted: Fri Apr 16, 2010 11:52 am
by Han Giap
hi,

Shahrul thanks for the information u provided.

i still x quiet understand..

can gv me some details?

did u set RA7 as input? i means ur variable resistor is connected to RA7?

can i use a simple input button on RA7 ?

thanks for replying :mrgreen:

Re: Servo Controlling using PIC16F877A

PostPosted: Fri Apr 16, 2010 12:43 pm
by shahrul
RA7? not RA7. I use analog input on RA0.
If you want to use Push Button, use 2 push button. 1 for increments and 1 for decrements.
eg, if push button 1 is pressed, increments position servo,
if push button 2 is pressed, decrements position servo.

Re: Servo Controlling using PIC16F877A

PostPosted: Fri Apr 16, 2010 3:27 pm
by Han Giap
shahrul WROTE:RA7? not RA7. I use analog input on RA0.
If you want to use Push Button, use 2 push button. 1 for increments and 1 for decrements.
eg, if push button 1 is pressed, increments position servo,
if push button 2 is pressed, decrements position servo.


hi,
i have try ur coding using proteus.. yup the motor angle change according to the variable resistor. but come out with a warning... (ADC conversion clock period (1e-07) is less than min TAd=1.6us and is possibly invalid for device clock frequency)


:oops: but i still confuse... when should i write the input for increment?

ADCON0=(ADCON0&0xC7)|(channel<<3); //select analog input channel
wat do this coding means?


is it almost the same concept with this 1?
http://www.newcircuits.com/circuit.php?id=uct001

thanks in advance