Servo Controlling using PIC16F877A

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

Re: Servo Controlling using PIC16F877A

Postby sich » Sat Apr 10, 2010 12:46 pm

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.
~> 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 » Sat Apr 10, 2010 11:42 pm

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

Re: Servo Controlling using PIC16F877A

Postby sich » Mon Apr 12, 2010 10:55 am

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.
~> 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 shahrul » Tue Apr 13, 2010 3:08 am

You can try program servo using Timer Interrupt. It's aesier. To view program and the video, see here.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Servo Controlling using PIC16F877A

Postby ober » Wed Apr 14, 2010 8:26 am

Shahrul, nice work you have there!
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1441
Joined: Wed Apr 15, 2009 1:03 pm

Re: Servo Controlling using PIC16F877A

Postby Han Giap » Thu Apr 15, 2010 10:47 am

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

Re: Servo Controlling using PIC16F877A

Postby shahrul » Thu Apr 15, 2010 11:01 am

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

Re: Servo Controlling using PIC16F877A

Postby Han Giap » Fri Apr 16, 2010 11:52 am

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

Re: Servo Controlling using PIC16F877A

Postby shahrul » Fri Apr 16, 2010 12:43 pm

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

Re: Servo Controlling using PIC16F877A

Postby Han Giap » Fri Apr 16, 2010 3:27 pm

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

PreviousNext

Return to Robot Controller

Who is online

Users browsing this forum: No registered users and 6 guests

cron