Servo Controlling using PIC16F877A

Autonomous Robot, Manual Robot, DC Motor Driver, Stepper Motor Driver, Servo, Multi PWM chip.....

Re: Servo Controlling using PIC16F877A

Postby shahrul » Mon Mar 29, 2010 1:44 am

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.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Servo Controlling using PIC16F877A

Postby joliza » Mon Mar 29, 2010 2:29 pm

The motor should be working. May i know what version of MPLAB and C Compiler you used.
joliza
Novice
 
Posts: 22
Joined: Mon Jun 22, 2009 10:56 am

Re: Servo Controlling using PIC16F877A

Postby Han Giap » Wed Apr 07, 2010 1:46 am

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
Han Giap
Novice
 
Posts: 20
Joined: Thu Mar 25, 2010 7:36 pm

Re: Servo Controlling using PIC16F877A

Postby sich » Wed Apr 07, 2010 2:01 am

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.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: Servo Controlling using PIC16F877A

Postby Han Giap » Thu Apr 08, 2010 1:25 pm

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:
Han Giap
Novice
 
Posts: 20
Joined: Thu Mar 25, 2010 7:36 pm

Re: Servo Controlling using PIC16F877A

Postby sich » Thu Apr 08, 2010 4:50 pm

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?
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: Servo Controlling using PIC16F877A

Postby Han Giap » Thu Apr 08, 2010 8:53 pm

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
Han Giap
Novice
 
Posts: 20
Joined: Thu Mar 25, 2010 7:36 pm

Re: Servo Controlling using PIC16F877A

Postby hyng » Fri Apr 09, 2010 9:48 am

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.
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: Servo Controlling using PIC16F877A

Postby Han Giap » Sat Apr 10, 2010 9:11 am

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
Han Giap
Novice
 
Posts: 20
Joined: Thu Mar 25, 2010 7:36 pm

Re: Servo Controlling using PIC16F877A

Postby shahrul » Sat Apr 10, 2010 9:27 am

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?
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

PreviousNext

Return to Robot Controller

Who is online

Users browsing this forum: No registered users and 22 guests

cron