Jump to content

Recommended Posts

Hia boosters,

 

I want to connect 2 servo's on my pic 16f877. But when i use the formula described in the datasheet my lowest possible freq will be somewhere around 480hz and i need something close to 50hz. Am I doing something wrong or isnt it just possible ?

 

or does some1 knows a better chips for driving two servo's ??

 

with kind regards

yod

Link to post
Share on other sites
  • 2 weeks later...

Yo Yodar,

 

I'm presuming that what you're talking about is controlling servos that are typical of what's used in RC planes, cars, etc.

 

I've been using a pic to drive a servo. You'll notice that the PWM frequency is a function of the PIC clock frequency. So one option for you would be to change the crystal and clock the PIC very slowly and you'll be able to get the PWM down to whatever you want. But now you have a slow running PIC.

 

I am getting very good results with an 18F4431 clocked at 40 MHz, but I'm using software delays. I don't need to have the servos hold the position, so I'm positioning the servos and then letting them go idle.

 

Dan

Link to post
Share on other sites
  • 2 weeks later...

Yod

 

Set up a PWM frequency to cover the servo pulse length - say 400HZ. Then electronically AND the PWM output pin with another pin that you set positive in the PWM interrupt routine for one cycle every 8. This will give you the correct pulse length and repeat rate. You may be able to do it by setting the PWM pin to an input in the TRIS register for 7 cycles out of 8 but I haven't tried this - the other definitely works.

 

Best regards

 

Flyer

Link to post
Share on other sites

RC Servo isn't exactly working with PWM, this is more a pulse lenght control since the death time isn't important at all, you only must refresh the pulse every 20mS or the servo will release his position.

 

All you have to do is drive a pulse between 1mS and 2mS (1,5mS reprensentating center position) and refresh it every 20mS.

 

If your CPU time isn't too critical here is how I suggest to do it.

 

Setup a timer that will interrupt every 16mS (62,5 Hz)

In interrupt,

1. Set output of servo 1

2. Wait 1mS

3. Wait X*3,92uS where 0<X<255 128 = servo at center

4. Clear ouput of servo 1

5. Set output of servo 2

6. Wait 1mS

7. Wait Y*3,92uS where 0<Y<255 128 = servo at center

8. Clear ouput of servo 2

9. End of interrupt

 

X = servo 1 position

Y = servo 2 position

 

The only thing is that the CPU, every 16mS, during a time between 2mS and 4mS

will only take care of servo precision.

 

If you need more CPU time, you can drive both refresh and pulse lenght by interrupt, but this is a lot harder.

 

Hope will help

 

Rich

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...
×
×
  • Create New...