Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Servo motor control...

Status
Not open for further replies.
CCPR1L=250;// from ~40 to 250

What the!!!! I told you that the CCPR1L register can only go up to 39!!! no further!!! 0 to 39... 18 will be your middle... You didn't take anything I said onboard... If you stick the code I gave you in your program it should work.
 
What the!!!! I told you that the CCPR1L register can only go up to 39!!! no further!!! 0 to 39... 18 will be your middle... You didn't take anything I said onboard... If you stick the code I gave you in your program it should work.
but i am using direct ADC no CCPR1L=250;// from ~40 to 250 it was different.
 
CCPR1L cannot exceed 39 when the PR2 has been set to 39.... Nothing can happen but the PWM pin will just be high....
If you put 18 in the CCPR1L the servo should be stopped.
If you put 39 in the CCPR1L the servo should be going in one direction.
If you put 0 in the CCPR1L the servo should be going in the opposite direction.
 
That impressed you? I think I'm done with ETO... let the indians take over with all the lazy nonsense.

you are one the people i learn from, would be a shame if you didnt post
 
Hi,

I have used this but roatating in clockwise only..





Code:
  while(1)

  {

//number = ReadADC(0);

//number /= 6;

//CCP1CON |= (number & 3) <<4; // Bits 1 and 2

//CCPR1L = number >>2; // Bits 3 to 6

CCPR1L=18;

__delay_ms(1000);

CCPR1L=38;

__delay_ms(1000);

CCPR1L=0;

__delay_ms(1000);
 
Dont worry little ghostman; mister t will be around for you.
Have a look at post no 43. With some people you can tell them, but you cant tell them very much.
 
you are one the people i learn from, would be a shame if you didnt post

hi,
You have made an often overlooked comment about experienced members posted replies.:banghead:

Even though the OP may not fully grasp the answers he has been given, many other hobbyists working on similar projects will benefit from the help and guidance given by the experienced members, so their replies are NOT wasted.:)

Eric
 
ericgibbs Spot on!!! I wish all on this forum would think like this.....

Sorry Ritesh you said this was a PWM servo so I have been giving you false info....

This motor DOESN'T work with PWM as such.... I should have asked for this link ages ago... This works with pulse width only..... I have worked before with these servo's before.. They DO run on 50hz but the pulse width is 1mS to 2mS.... with 1.5mS being stopped..

Re-arrange your PWM module and I knock up a calculation to drive this RC servo....
 
I've had coffee and am still confused. Let me review some of this discussion:

Post#1 (Ritesh)
I have got this servo today and want to work on Robotic arm before that i was to fix my hand on it with direct uc and pott meter....
I have no idea about it pulse time rate but it is 180 degree ..
It is replacement of futaba and hi tech

http://www.google.co.in/search?q=F...hannel=np&gws_rd=cr&ei=ZzxEUsSXMsPnrAfhuYDABQ

**broken link removed**

NB: That link is the same as the one Ritesh just gave. It claims the servo he is using is equivalent to the HS311 and standard Futaba hobby servos.

#2 by misterT
That is a standard servo. You get the best results if you control it with a standard servo signal:
http://www.ermicro.com/blog/?p=771

So far, no confusion. Everyone seems on the same page. Then...

#11 by Ian Rogers
These servo's are soooo easy to control.... Set up a 1.9khz pwm... set the pwm to 50:50 and the servo sits at mid position.... set the pwm to 99:1 and the servo shoots to 90 degrees swap it round to 1:99 and the servo shots to -90 degrees...

and
#17 by misterT
he frequency is not important. The pulse width is important. The servo takes the information from the pulse width (it calculates how long the incoming pulse is). 50 Hz is the "old" standard. But you can send the pulses at higher rate to modern servos.

I was so intrigued by the possibilities presented in posts #11 and #17 that I asked (unanswered) Post #18:
In reading your and misterT's comments (#17), I have learned something worth trying this Winter.
What brand and model servo are you using?
Are the "modern" servos digital or analog? If digital, what is the deadband spec in uS? (If you just give the brand and model, I can look up the latter info.)

In fact, I was so intrigued that I brought a lot of my electronic stuff from Cleveland to the farm so I could study it as Fall begins to set in.

Now, it appears from Post#50 that it was all a misunderstanding.

Please help to clarify that. With respect to using 1.9 KHz were Ian Rogers and misterT referring to "modern" industrial servos, "modern" model servos that work at that frequency (if so, please give a brand and model number), or something else?

John
 
Last edited:
I apologize John for any confusion I have created.... I have lead Ritesh down the garden path... The industrial servos from crane gear and machine tools work with PWM the way I first described... The little RC servo's work as that datasheet you posted..

When using motors on large cranes the servo circuitry uses full bridge PWM and my mind was fixed on this operation... ( This is why they whine as they are very large motors and 20khz PWM is what is use to quieten them. )

These little RC servos do not use PWM as such just PW if there is such a thing...
 
hi,
You have made an often overlooked comment about experienced members posted replies.:banghead:

Even though the OP may not fully grasp the answers he has been given, many other hobbyists working on similar projects will benefit from the help and guidance given by the experienced members, so their replies are NOT wasted.:)

Eric
i think experienced members dont realize how many beginners read and follow a thread, and ultimately learn from it. most beginners are too afraid to poke there heads above the wall and ask a question in a thread because so many jump on them and say start your own thread or keep topic on track, i understand why this is done but it also has a negative effect because alot of people dont get to know just how much of there advice is taken in by others.
SIMPLE SOLUTION. there isnt one :S
all i can say is beginners grow a skin ask a relevant question in a thread and dont be offended if your told to go do your own thread.
and to you pro's i say. it may seem like some OP's are off there tree or not payin attention but sometimes they ask questions that to you seem stupid but to alot of beginners following a thread it is probably the same question they would ask if they had the wedding bits to do it.

sorry if off topic blah blah blah but needed saying
LG

edit

oh and incase its of any use at all the thread i posted about earlier is here

https://www.electro-tech-online.com/threads/junebug-servo-c18-code.36127/

well somewhere in that thread
 
I have just re-read the entire thread to see why I have diverted... I picked up on the PWM conversation at post #9

I should have downloaded the datasheet, but I let the thread run.... I wholeheartedly agree John... I have caused massive upset here....
RITESH KAKKAR Sorry again about the misleading....
 
Thanks, Ian, for the clarification.

Way back when, I thought you might be referring to industrial servos. But, misterT's comment (#17) made me reconsider. Now, I think maybe he was referring to pushing the refresh to faster than 20 mS with modern servos, but not quite to 0.53 mS (1.9 kHz). I have run older servos at 100 Hz; they began to behave oddly at 120 Hz, as I recall. I have some newer digital ones with a 2 uS deadband that I will test for working at higher frequencies -- not that I think deadband should make a difference per se . The narrower deadband may simply indicate newer electronics. However, if 2 mS is still used for full swing, then I don't see how we can exceed 500 Hz.

That testing by me is several weeks away at the earliest.

John

Edit: I was composing while Ian just posted. Sorry for any duplication.
 
Yes! The motors I have been using have separate circuitry for the PWM logic... The small thing that Ritesh has got cannot be run by the PWM module as the pulse width control is FAR too small its only 1 to 2mS on a 20mS cycle.. only 5% of the cycle to control the thing..

Here is the code I used to control an RC servo 0 to 90 degrees.. It is for a pic12f1840, it's written on the XC8 compiler. Its for a rear view camera modification for VW golf or Seat Leon...

C:
#include <xc.h>
#pragma config WDTE = OFF, FOSC = INTOSC, MCLRE = OFF, PLLEN = OFF

void DelayUs(int x)      // Small delay
   {
   x /= 7;           // Adjustment for 8Mhz
   while(x--)
     NOP();   
   }
void DelayMs (int x)     // Larger delays
   {
   while(x--)
     DelayUs(1000);     // Close enough
   }

void main()
   {
   int close =0;
   OSCCON = 0x70;       // 8Mhz
   TRISA = 1;         // Reverse input
   ANSELA = 0;         // No ADC's required
   RA2 = 0;         // Switch relay
   while(1)
     {
     if ( RA0 )
       {
       close = 15;     //  Set closing time
       RA2 = 1;     // Break switch relay
       RA5 = 1;     // Pulse on
       DelayUs(2000);   // 2mS pulse width
       RA5 = 0;     // Pulse off
       DelayMs(18);   // Rest of 50hz (20mS cycle )
       }
     else
       {       
       RA5 = 1;     // Pulse on
       DelayUs(1500);   // 1.5mS
       RA5 = 0;     // Pulse off
       DelayUs(500);   // Delay
       DelayMs(18);   // Rest of 50hz (20mS)
       if(close-- == 0 )
         RA2 = 0;    // Reconnect switch after 2 seconds(ish)
       }
     }   
   }
 
OK, I want to ask one thing how to calculate it freq as osc is 20MHz so, one instr takes 1/5000000=.2uSec and i want to know at what pulse the angle value
so,

unsigned int i;

for(i=1;i<=400; i++){
RC2=1;

__delay_us(1500); //at centre
RC2=0;
__delay_ms(20);

}
 
yeah, 1/18mS is 50Hz, but the osc freq will effect this on changing it?
one thing more how to calculate angle from pulse width and i want to connect a pott meter to control servo for robotic arm.
 
i think experienced members dont realize how many beginners read and follow a thread, and ultimately learn from it. most beginners are too afraid to poke there heads above the wall and ask a question in a thread because so many jump on them and say start your own thread or keep topic on track, i understand why this is done but it also has a negative effect because alot of people dont get to know just how much of there advice is taken in by others.
SIMPLE SOLUTION. there isnt one :S
all i can say is beginners grow a skin ask a relevant question in a thread and dont be offended if your told to go do your own thread.
and to you pro's i say. it may seem like some OP's are off there tree or not payin attention but sometimes they ask questions that to you seem stupid but to alot of beginners following a thread it is probably the same question they would ask if they had the wedding bits to do it.

sorry if off topic blah blah blah but needed saying
LG

edit

oh and incase its of any use at all the thread i posted about earlier is here

https://www.electro-tech-online.com/threads/junebug-servo-c18-code.36127/

well somewhere in that thread

LG,

Thank you for the valid input. I am one of those guys and feel you you are spot on! Hope that the experts do read it and hope they will bare with us and our "stupid questions". And to you that took control of this thread well done. Keep on making this the better forum for all electronic enthusiasts that are eager to learn.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top