Page 2 of 5

Re: Servo Controlling using PIC16F877A

PostPosted: Mon Mar 29, 2010 1:44 am
by shahrul
It's easy to control servo using Interrupt Counter, because you need to maintain 50Hz signal into servo. To save servo position, you need to save into EEPROM, because even you switch off power, this data will not lost.

Re: Servo Controlling using PIC16F877A

PostPosted: Mon Mar 29, 2010 2:29 pm
by joliza
The motor should be working. May i know what version of MPLAB and C Compiler you used.

Re: Servo Controlling using PIC16F877A

PostPosted: Wed Apr 07, 2010 1:46 am
by Han Giap
Hi,

yup the source is working when i install the high tech pro c compiler...

but, do u have example of controlling a servo motor.. i means position..

say like, got 3 button... forward , stop and backward.. 0 degree to 90 to 180.. middle position is 90.

example.. when i wan to obtain a 20 degree, i press backward... to the servo motor rotate from 90 to 20...

do guys n gals have any example code?

thanks in advance

Re: Servo Controlling using PIC16F877A

PostPosted: Wed Apr 07, 2010 2:01 am
by sich
From "Single_Servo_16F_20MHz", you learn how to control rc servo motor position by changing the delay values. Then you can refer to "SK40C 16F877A Sample Program" provided in SK40C product page for the way to scan more than one button. Just look into the led blinking program.

Re: Servo Controlling using PIC16F877A

PostPosted: Thu Apr 08, 2010 1:25 pm
by Han Giap
hi..

here my source code for controlling a servo motor

CODE: SELECT_ALL_CODE
if(a=='l')   //Base Rotate to Left
   {   
      for(i=0;i<50;i++)      
      {
      servo5=1;         //angle of -53
      DelayMs(1);
      DelayUs(250);
      DelayUs(50);
      DelayUs(250);
      DelayUs(250);      
            
      servo5=0;         
      DelayMs(18);      
      DelayUs(200);
           }
   }         
        if(a=='p')   //Gripper Close
        {
   for(i=0;i<50;i++)      
      {
      servo5=0;         //angle of +53
      DelayMs(1);         
      DelayUs(500);
                                                
      servo5=0;         
      DelayMs(18);      
      DelayUs(500);
      }
          }

could anyone identifier wat wrong with tis code?

i could not find the problem... it just wont run

thanks in advance :mrgreen:

Re: Servo Controlling using PIC16F877A

PostPosted: Thu Apr 08, 2010 4:50 pm
by sich
Han Giap WROTE:if(a=='p') //Gripper Close
{
for(i=0;i<50;i++)
{
servo5=0; //angle of +53
DelayMs(1);
DelayUs(500);

servo5=0;
DelayMs(18);
DelayUs(500);
}
}

You are giving '0' continuously to the pin. And the value for '1' in both cases are very close too. Are u sure it's -53 and +53 degrees? Or you're not referring to the motor shaft but your mechanism instead?

Re: Servo Controlling using PIC16F877A

PostPosted: Thu Apr 08, 2010 8:53 pm
by Han Giap
hi,


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


ops is my mistake.. typing error... yes... i does turn +53 n - 53...

when i test without adding if(a=='o') n if(a=='p')

actually what i would like to do is.... i wan set the starting position in middle.. then when i press (a=='o') it will rotate to +position while (a=='p') rotate to -position

but i x sure why tis coding would work @@ :|


thanks for the information

Re: Servo Controlling using PIC16F877A

PostPosted: Fri Apr 09, 2010 9:48 am
by hyng
What is "a"? There is 'o' and 'p' in your coding, so i assume you are trying to control from computer. Am i right? Make sure all your initialization is correct. And you should put a bigger i at the loop in order for your servo motor has enough time to rotate to the desire position.

Re: Servo Controlling using PIC16F877A

PostPosted: Sat Apr 10, 2010 9:11 am
by Han Giap
hi,


yup i using a simple GUI control my circuit.. u means increase the time for loop? like 50 to 100? 200?

a is the receive data, example i follow from cytron SKCCA-21 source code.. its works ON or OFF pin... 0V or 5V... but when i apply the delay, it wont..

thanks

Re: Servo Controlling using PIC16F877A

PostPosted: Sat Apr 10, 2010 9:27 am
by shahrul
Han Giap WROTE:hi,


yup i using a simple GUI control my circuit.. u means increase the time for loop? like 50 to 100? 200?

a is the receive data, example i follow from cytron SKCCA-21 source code.. its works ON or OFF pin... 0V or 5V... but when i apply the delay, it wont..

thanks

50 is enough. 50x20ms = 1s, time for servo at one position. You having compile error or you can compile but the servo cannot move.. Did you declare servo port as an output?