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.

How to control a Servo motor?

Status
Not open for further replies.

bigal_scorpio

Active Member
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 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 **broken link removed**, it's in C but may be useful.

Mike.
 
Last edited:
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 :confused:
 
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.
 
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 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
 
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
 
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
 
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.
 
Hi Al

This tutorial shows how to control a servo motor.
**broken link removed**

Hope this helps!
Slorn
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top