go_away

Author Topic: moving servos with PICs  (Read 2768 times)

0 Members and 1 Guest are viewing this topic.

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
moving servos with PICs
« on: March 01, 2009, 11:34:02 AM »
hi
i'm totaly green and i need an answer to a simple question:
how do i make servo rotate either forward or backwards with PIC16F627-16F628 or 18F452 (my servos support continuous rotation)
what i want to know is how u make them keep rotating(i'm using assembler language)
plz don't flame me for this question :P

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: moving servos with PICs
« Reply #1 on: March 03, 2009, 06:20:50 AM »
Are you asking about how to modify a servo for continuous rotation, or code to run a servo?

I have several robots posted on the main site for PIC 16F877 with source code to download, and a tutorial to modify servos  . . .

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #2 on: March 04, 2009, 11:54:39 AM »
my servos can rotate continuously,what i need is a code in either ASSEMBLER or BASIC to make them do so :P
or just an idea how to do it

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: moving servos with PICs
« Reply #3 on: March 04, 2009, 12:28:54 PM »
if u have already modded them ,..,..then u know wat the different pulses u send to it will change its speed instead

of rotating to a specific angle...

i dont know abt pic but gor ave i have designed a code which turns the servo...will work with continuous rotation too...thing is the pulse widths are different..but changing the OCR1A values can take care of that..

Code: [Select]
#include<stdio.h>
#include<avr/io.h> //for 8mhz internal oscillator controlling servo by centering it
#include<avr/interrupt.h>
#include<util/delay.h>


int main (void)
{
 
   unsigned int i;
   DDRD |= _BV(5); // Set PORTD5 as output
   DDRC =0x01;

   TCCR1B |= (1 << WGM13); // phase and frequency correct mode
   
   ICR1=10000;
   
   TCCR1A|=(1<<COM1A1);//clear oc1a when upcounting and set Oc1a while downcounting

   TCCR1B |=(1<<CS11); // Start timer at Fcpu/8
   PORTC=0X01;
   
   while(1)
    {

 
  for(OCR1A=350;OCR1A<1150;OCR1A++)
    {
  _delay_ms(1);
}

for(i=1;i<=50;i++)
{
_delay_ms(10);
}



  for(OCR1A=1150;OCR1A>350;OCR1A--)
    {
_delay_ms(1);
}
     for(i=1;i<=50;i++)
{
_delay_ms(10);
}
}
return(0);
   
   
}

JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #4 on: March 04, 2009, 12:45:12 PM »
hmm..i didn't have to modify anything,they are just made in such way that they can rotate and have no stopping thingy on the shaft or anything
Parallax Roatation Servo S148
and i have no knowledge of C language  :-[

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: moving servos with PICs
« Reply #5 on: March 04, 2009, 12:51:50 PM »
err.............its very hard to make u understand ....plzz post the datasheet of ur servo
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #6 on: March 04, 2009, 02:31:32 PM »
ok,datasheet is available here:
http://www.parallax.com/Portals/0/Downloads/docs/prod/motors/crservo.pdf
the thing is that i can turn it either way usic BASIC commands BUT the pulsout command you find in code attached to servo datasheet is not a BASIC command,only works with BASIC stamp thingy,and i can't make it turn around for a period of time(ie.i can apply pulse to Vo say 20ms and it will turn)and i think i'm missing something quite trivial like delay between pulses or something,but every delay makes it stop and i want it rotate :P
« Last Edit: March 04, 2009, 02:39:42 PM by yesus »

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: moving servos with PICs
« Reply #7 on: March 04, 2009, 09:25:50 PM »
i have no idea how do u use basic stamp but if it would have been c...then i what i would have done is that i would have switched on the servo for 1.5 ms  2 ms given it a 20 ms gap...to take it to a particular angle...

now the servo runs in a frequency of 50 hz and with a dutycycle of 20 ms...if u want complete theory for the servo ...go through the servo tutorial or any good member tutorials...
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #8 on: March 05, 2009, 12:09:08 PM »
that's the thing,i can send it pulse of any widht to servo and i can send any delay to it,but how do i make it rotate???
i know how to turn it this way or the other but i want to make it rotate continouosly(either CW or CCW)

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: moving servos with PICs
« Reply #9 on: March 05, 2009, 12:17:35 PM »
u dont unerstand...the duty cycle has to be 20ms...bu if u have  continuous rotation servo then if u send pwm of diff pulse widths then that will change the speed at which it rotates ...suppose u sent a 1.5ms pulse then let the rotate at speed x...then if u send a 2 ms pulse thn this speed will either be faster or slower ..depending on the config of ur servo...
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #10 on: March 05, 2009, 12:37:59 PM »
ok,but what's the delay between pulses??
i'm really trying to understand..just need some guidance

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #11 on: March 05, 2009, 12:51:17 PM »
hold on,i'm missing something here..i send a pulse or different width to make it rotate CW or CCW but what about the lenght of the rotation? how do i set that?
i did read some servo tutorials but english isn't my first language as u might have guested and i don't fully understand the way servos work
i know that u have to apply a signal or certain width to either center or turn servo(either way depending on signal width) but how do i make it keep turning that way until i want it to stop?
i know that most servos work in 50Hz frequency and that's what i don't understand-do i have to send signal to servo every 20ms or so to make it perform some action??

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: moving servos with PICs
« Reply #12 on: March 05, 2009, 01:24:17 PM »
keep doing that in a continuou loop....lby sending pulses of the required length...and when u wantto stop dont send any pulses at all inthe loop
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #13 on: March 05, 2009, 01:40:13 PM »
heh,seems like NOW i have to learn how to use PWM function,oh joy :P

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: moving servos with PICs
« Reply #14 on: March 05, 2009, 01:43:10 PM »
be kind enough tomrk me as helpful hen :D
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline yesusTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: moving servos with PICs
« Reply #15 on: March 05, 2009, 02:18:34 PM »
u got it!

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: moving servos with PICs
« Reply #16 on: March 05, 2009, 10:36:08 PM »
:D
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

 


Get Your Ad Here

data_list