+ Reply to Thread
Results 1 to 10 of 10

Thread: How to control a Servo motor?

  1. #1
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    439

    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
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!


  2. #2
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  3. #3
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    439

    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
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  4. #4
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  5. #5
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    1,993

    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.
    Burt

  6. #6
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    439

    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
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  7. #7
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    439

    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
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  8. #8
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    439

    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
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  9. #9
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  10. #10
    Slorn Newbie
    Join Date
    Oct 2009
    Posts
    10

    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.

+ Reply to Thread

Similar Threads

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

Tags for this Thread