Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 14th November 2009, 11:19 AM   #1
Default How to control a Servo motor?

Hi to all,

I am trying to build a motorised cover for something and have decided that a servo would do the job nicely.

The problem is that I have never used servos before except in RC cars and they were already sorted with signals from the RC.

I have looked at what I could find on the net and now understand that I need to had a signal that can vary from a short pulse to position at on extreme and a longer pulse to go to the other extreme.

My problem is that I can't find anywhere the info about the duration of the signal. I.E. since I only want to move the servo from 1 fixed position to another do I need to send a set number of pulses?

Also do I need to send the pulses continuously to keep the motor at the set position?

The info on the net seems to assume that I know these things and ignores it but for all I know it may only need 1 pulse of the correct duration or a constant stream of them?

I am planning on using a PIC12F629 to control the servo with two switches to open and close the cover (one would be even better but I have no idea if that is possible). I can program the PIC and would be using MikroBasic.

Any help on this would be much appreciated as I am at a time in life that I can only seem to learn by example. (The wife says I'm getting thicker!)

Anyway if you can help in any way that would be great.

Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 14th November 2009, 11:25 AM   #2
Default

The servo needs a pulse every 20mS and the pulse needs to be between 1 and 2mS. The 16F629 should have no problem doing this. If you need any help with the code just ask.

I'm not sure why you would need switches as the servo would always return to the same position.

Edit, I did a short explanation in Bill's Jpug, it's in C but may be useful.

Mike.

Last edited by Pommie; 14th November 2009 at 11:29 AM.
Pommie is offline  
Old 14th November 2009, 02:43 PM   #3
Default

Hi Mike,

I ahd a look at the JPUG but as you thought the C doesn't mean much to me.

Anyway is it possible to send a pulse to a servo, say to -90degrees and then turn off the power and the servo stay there?

That would be my open flap done, then send a pulse to make the servo go to +90degrees and turn off power when I want to open the flap.

I really don't understand the way servo motors work, and as I said before, the net seems to think everyone does! DOH!

I was hoping I could just press a switch and the flap would open and press again for it to close, kind of like a cd drawer does, or have a separate switch for open and close if not.

Thanks.............Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 14th November 2009, 02:49 PM   #4
Default

If the flap is balanced then you could turn off the servo. Most applications require a weight to be held in place and so the servo has to be powered. Get a servo and see if it will stay in position without power.

Mike.
Pommie is offline  
Old 14th November 2009, 04:22 PM   #5
Default

Cd drawers don't use servo's they use geared motors and limit switches easier to code then the servo just something you may want to try.
be80be is offline  
Old 14th November 2009, 06:08 PM   #6
Default

Hi guys,

The servo's I have seem fairly stiff to turn by hand, probably due to a lot of gearing, so I think they should hold their position when unpowered as the flap is very light. And they are just the right size to fit behind the gap I have.

What I want to know is if its possible to use them in this way?

Will they return to center when powered up? How do I code the prog to make the servo go to the positions?

Can anyone show me some servo control code in Mikrobasic or even any basic? Then I can build on it and experiment till I get it right.

Thanks.........Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 14th November 2009, 06:10 PM   #7
Default

Quote:
Originally Posted by Pommie View Post
If the flap is balanced then you could turn off the servo. Most applications require a weight to be held in place and so the servo has to be powered. Get a servo and see if it will stay in position without power.

Mike.
Yes Mike, the servo holds the flap easily when unpowered.

Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 14th November 2009, 06:12 PM   #8
Default

Quote:
Originally Posted by be80be View Post
Cd drawers don't use servo's they use geared motors and limit switches easier to code then the servo just something you may want to try.
Hi Burt,

I only meant like the button on CD drawers work, push to open, push to close etc.

Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 15th November 2009, 12:58 AM   #9
Default

I haven't used microbasic but the code would be something like,
Code:
while 1
    ServoPin=1
    DelayUs(ServoPos)
    ServoPin=0
    DelayUs(20000-ServoPos)
    if(ButtonPin=1) then
        ServoPos=3000-ServoPos
    endif
wend
Once you work out the two values for the correct positions, ServoPos should be initialized to one value and the 3000 number should be the sum of the values.

The button press would need to be debounced and changed to detect a rising edge but it should give you a general idea.

Mike.
Pommie is offline  
Old 15th November 2009, 09:51 AM   #10
Default

Hi Al

This tutorial shows how to control a servo motor.
http://www.dwengo.org/tutorials/light-tracker

Hope this helps!
Slorn

Last edited by Slorn; 15th November 2009 at 09:52 AM.
Slorn is offline  
Reply

Tags
control, motor, servo

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
How to use PIC18F4550 to control a servo motor? Innovator Micro Controllers 7 14th August 2009 06:34 AM
Control position of servo motor Wingmax Robotics Chat 5 5th January 2008 11:24 AM
can anyone explain how to control a servo motor?? TheMaccabee Robotics Chat 4 4th April 2007 02:55 AM
DC motor, Servo Motor or Step Motor ? wcz Electronic Projects Design/Ideas/Reviews 1 29th June 2005 02:41 PM
DC Motor Postion control help (servo) lompa Robotics Chat 6 24th October 2004 04:16 PM



All times are GMT. The time now is 01:25 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker