Jump to content
Sign in to follow this  
robomaker

How To Define Pwm Angle For Servomotor

Recommended Posts

hello guys,

 

i am a newbie and i'm working on a c programming code to control servo motor via pwm to define the angle.i had read a lot of questions and programming in this forum but i still can't understand it.i'm using pic16f877A with 20MHz osc. Since then i have a few problem to make the servo to turn clockwise, counterclockwise and stop at the precise angle because i'm working for dancing robot project in writing the program's code. to define this angle in servomotor programming, is it need me to convert this angle value into binary number for this programming and how to do that?

 

i'have found that in PIC there are 2 types of crystal oscillator that will be used, 4MHz and 20Mhz. any body can tell me what is function of these oscillators due to their value and effect to the programming.

 

I hope that anyone can guide me and i'm really appreciate that..regards

robomaker

Share this post


Link to post
Share on other sites

You seem to be looking for the wrong type of solution.

To start with, how many poles does your servo have? This will tell you

the sequence you need to use for your pwm as well as how precise an

angle it can hold. As well as a few other treats like speed and torque.

 

As for you oscillator/crystal/resonator question it does not quite make sense ...

are you talking about your availible external crystals, the internal. or the pwm?

Basicly PICs have two options, an internal oscillator reference or an external one,

based on how you configure the registers you will be using one or the other.

Share this post


Link to post
Share on other sites

emte,

 

I think you may be answering a better question than the OP asked.

 

It looks like they want to use Radio Control type "servos" that accept a pulse from 850us to 2500us to rotate the servo arm through its range of movement.

 

There are lots of articles on how to use a PIC to control this type of servo.

 

Google is your friend, (about 189,000 for +PIC +RC +SERVO) sort of.

Share this post


Link to post
Share on other sites

hmm, could be

i just try to be as generic as possible, but that also tends to mean i might

go a little more lowlevel than some would like...

 

Blame it on my training :rolleyes:

Share this post


Link to post
Share on other sites
hello guys,

 

i am a newbie and i'm working on a c programming code to control servo motor via pwm to define the angle.i had read a lot of questions and programming in this forum but i still can't understand it.i'm using pic16f877A with 20MHz osc. Since then i have a few problem to make the servo to turn clockwise, counterclockwise and stop at the precise angle because i'm working for dancing robot project in writing the program's code. to define this angle in servomotor programming, is it need me to convert this angle value into binary number for this programming and how to do that?

 

i'have found that in PIC there are 2 types of crystal oscillator that will be used, 4MHz and 20Mhz. any body can tell me what is function of these oscillators due to their value and effect to the programming.

 

I hope that anyone can guide me and i'm really appreciate that..regards

robomaker

 

robomaker,

This subject has been discussed in an earlier threadservo motor control

Here i have given examples using the delay commands of compiler.

If you still wish to generate your pulses using PWM module, you can't use a crystal larger then 1.25mhz to generate 50 hz pulses. I have a sightly different program which generates 100hz pwm for inverter application, but you can modify it for 50 hz. you can change the duty cycle value for the various sero positions.

PWM generation for low frequency

 

regards

Raghunathan.

Edited by ra68gi

Share this post


Link to post
Share on other sites
hello guys,

 

i am a newbie and i'm working on a c programming code to control servo motor via pwm to define the angle.i had read a lot of questions and programming in this forum but i still can't understand it.i'm using pic16f877A with 20MHz osc. Since then i have a few problem to make the servo to turn clockwise, counterclockwise and stop at the precise angle because i'm working for dancing robot project in writing the program's code. to define this angle in servomotor programming, is it need me to convert this angle value into binary number for this programming and how to do that?

 

i'have found that in PIC there are 2 types of crystal oscillator that will be used, 4MHz and 20Mhz. any body can tell me what is function of these oscillators due to their value and effect to the programming.

 

I hope that anyone can guide me and i'm really appreciate that..regards

robomaker

 

robomaker,

This subject has been discussed in an earlier threadservo motor control

Here i have given examples using the delay commands of compiler.

If you still wish to generate your pulses using PWM module, you can't use a crystal larger then 1.25mhz to generate 50 hz pulses. I have a sightly different program which generates 100hz pwm for inverter application, but you can modify it for 50 hz. you can change the duty cycle value for the various sero positions.

PWM generation for low frequency

 

regards

Raghunathan.

 

Depending on how much one knows this is both true and false.

 

Anyway it has yet to be established if he is looking/talking about RC servo control or

standard servo control as in your examples.

Share this post


Link to post
Share on other sites

thanks ra68gi...

 

by the way, i'm working to operate rc servomotor at precise angle... and have repeated actions for each step..

 

as we know servo will turn cck at 1.0ms, center at 1.5 ms and ck at 2.5ms... so how could i define its rotation angle between this range... ex: for 60 degree and -45 degree... by using your delay coding in servomotor control as you suggest...

 

regards:

robomaker

Share this post


Link to post
Share on other sites
as we know servo will turn cck at 1.0ms, center at 1.5 ms and ck at 2.5ms... so how could i define its rotation angle between this range... ex: for 60 degree and -45 degree... by using your delay coding in servomotor control as you suggest...

The short answer is you will not find a pulse width that give the exact same angle for all servos for all time.

 

The long answer is that RC servos are good at returning the control arm to a known position, but are poor at setting the control arm to a specific angle when the linearity of the servo feedback is unknown.

 

At any specific pulse width the angle varies from servo to servo and as a particular servo ages with use and wear of the mechanical linkage.

 

When these servos are used in radio controlled model cars and airplanes the user must adjust the trim tabs on the RC transmitter to calibrate the servos to the desired "neutral" condition.

 

The bottom line is that for RC servos repeatability and precision are two different thing.

 

None of these things are too hard to do. It will take some thought and engineering to get a dynamically stable and responsive system.

Edited by cac001

Share this post


Link to post
Share on other sites

Yes,

As cac says, servo motors can't be used for precise angle measurements. You can use stepper motors for such applications.

 

You can experiment with your servo by varying the pulse width from 1ms -2ms and verifying the postion/ angle. repeat the experiment several times to see if your servo behaves the same always. If its consistent and satisfies your purpose, use it.

 

Stepper motors have higher torque and a very precise angular movement. The only draw back being the complex drive circuitry. Servos has no such problems.

 

regards

Raghunathan.

Share this post


Link to post
Share on other sites

The RC Servo motor people tend to use for these purposes (because they're cheap and simple to interface) have a simple interface signal.

 

That is -- the signal is normally low. It has a 'high' pulse of from 1 mSec to 2 mSec duration, which specifies the desired position of the output shaft. 1.5 mSec being 'centered'. This signal is then repeated every 20 mSec to 50 mSec, to 'refresh' the servo electronics so they 'hold' the commanded position. And most servo's let you 'sweep' only 180 degrees using these pulses.

 

Superficially, this does meet the requirements of a "PWM Signal", but it's kind of misleading to call this a PWM signal. Most "PWM Signals" are specified by percentage of time high and low, and are used for speed control of DC electric motors. The Servo motor wants specifically the signal explained above.

 

Now, some people have "modified" the servo, by 'fixing' the feedback resistor inside the servo into it's middle position, and disconnecting it from the output shaft. Once this is done, a 1.0 mSec pulse causes the servo to spin continuously one way, a 2.0 mSec pulse to spin the other way, and a 1.5 mSec pulse to stop. However, once this is done, you lose the ability to command the servo to a particular position.

 

The "modified" servo makes a very nice inexpensive and simple to interface robot motor. But to position it exactly you then need to add some external position encoder.

Share this post


Link to post
Share on other sites
Superficially, this does meet the requirements of a "PWM Signal", but it's kind of misleading to call this a PWM signal.  Most "PWM Signals" are specified by percentage of time high and low, and are used for speed control of DC electric motors.  The Servo motor wants specifically the signal explained above.

 

 

You definitely can call it PWM signal. A PWM signal has a period value and a duty cycle value. In the case of servo the period is 20ms and to generate this period you need to load the PR2 register with the appropriate value given by the formula in the data sheet [(PR2)+1]*4*Tosc*(TMR2 prescaler value). Similarly the duty cycle for the servo can vary from 1ms to 2ms &

this value is calculated as a 10 bit value from the formula (CCPR1L:CCP1CON<5:4>)*Tosc*(TMR2 prescaler).

 

You will see that the percentage of ON time & OFF time is controlled or changed by changing the dutycycle value but the period( frequency )remains the same.

 

You can also see that to generate signal with 20ms period you need to use crystal freq less then 1Mhz, so i have used an RC oscillator( of less then 1mhz) to generate signal at this period.

 

Raghunathan.

Share this post


Link to post
Share on other sites

hi

 

this is my programming..but it's no working...anybody plzz help me on this programming!!

 

 

 

while( 1 );

{

if (portc.0 == 1)

{

step1:

portb.2=1; //servo1 control

 

for(y=0;y<5;y++)

{

for(x=0;x<50;x++)

{

delay_ms(2); //rotate 90degrees ck

for(w=0;w<50;w++)

{

delay_ms(1); //rotate 90degrees cck

}

}

}

}

}

}

 

 

here is its error

 

Building...

BoostC Optimizing C Compiler Version 6.35 (for PIC16 architecture)

http://www.sourceboost.com

Copyright© 2004-2006 Pavel Baranov

Copyright© 2004-2006 David Hobday

 

Single user Lite License (Unregistered) for 0 node(s)

Limitations: PIC12,PIC16 max code size:2048 words, max RAM banks:2, Non commercial use only

 

 

servotest.c

 

success

Exit code was -1. [invalid argument.]

Removing target: servotest.hex

Failed to locate output file 'servotest.hex'

Done

 

Failed

 

 

regards..

robomaker

Share this post


Link to post
Share on other sites

Superficially, this does meet the requirements of a "PWM Signal", but it's kind of misleading to call this a PWM signal.  Most "PWM Signals" are specified by percentage of time high and low, and are used for speed control of DC electric motors.  The Servo motor wants specifically the signal explained above.

 

 

You definitely can call it PWM signal. A PWM signal has a period value and a duty cycle value. In the case of servo the period is 20ms and to generate this period you need to load the PR2 register with the appropriate value given by the formula in the data sheet [(PR2)+1]*4*Tosc*(TMR2 prescaler value). Similarly the duty cycle for the servo can vary from 1ms to 2ms &

this value is calculated as a 10 bit value from the formula (CCPR1L:CCP1CON<5:4>)*Tosc*(TMR2 prescaler).

 

You will see that the percentage of ON time & OFF time is controlled or changed by changing the dutycycle value but the period( frequency )remains the same.

 

You can also see that to generate signal with 20ms period you need to use crystal freq less then 1Mhz, so i have used an RC oscillator( of less then 1mhz) to generate signal at this period.

 

Raghunathan.

 

i think he was refering to the servo itself not the PWM module in the PIC.

Edited by emte

Share this post


Link to post
Share on other sites

There seems to be a lot of people wanting to use PWM module to control their servos. I think i should make a project and post it on my thread.

 

Regards,

Raghunathan.

Share this post


Link to post
Share on other sites
There seems to be a lot of people wanting to use PWM module to control their servos. I think i should make a project and post it on my thread.

 

Regards,

Raghunathan.

 

You could ... but be aware there is apperently a large difference between how RC fanatics

do things with servos than how they are used in robotics and control systems.

i expect this might have a lot to do with the extra RF overhead they use for communications,

since in competitions they cannot always choose thier frequencies.

Share this post


Link to post
Share on other sites
There seems to be a lot of people wanting to use PWM module to control their servos. I think i should make a project and post it on my thread.
This would be most useful and interesting.

 

Please add this application to your thread.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...