2

Author Topic: servos and parallel port  (Read 4268 times)

0 Members and 1 Guest are viewing this topic.

Offline alexanderTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
servos and parallel port
« on: April 28, 2008, 06:44:11 PM »
Hi again.

I know I'm boring you... but I'm always using stepper motors and it's my first time with servo motors.

So... I need to control a small servo with my PC parallel port.

Can I do this just using direct signals or need I a driver circuit?

WIth stepper motors I just need use a driver to get more power, but signals is the same, like I'm using parallel port directly.

Is it possible do this with servo motors?

I don't know if my english is understandable. Sorry.

[]'s
Alexander
Brazil - Rio de Janeiro

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: servos and parallel port
« Reply #1 on: April 28, 2008, 07:06:37 PM »
you need  a driver circuit

also you should never use the ports directly, you might damage PC hardware .

Servos use PWM . What I personally would do is use the serial port and have the microcontroller translate the serial data to servo movements. Or you can have a microcontroller with many pins translate the parallel port.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: servos and parallel port
« Reply #2 on: April 28, 2008, 07:27:16 PM »
Get +5 of a LM7805. Put the ground in common with pins 25-17 of the port.
Put ground and +5 from the regulator into the servo.
Put pin 2 of the parallel port to the pwm input of the servo. It might, or might now work, depending on the servo. A better option would be pin 2 goes through a resistor (>1k) to a transistor base. collector goes into +5, emitter goes into servo input. This way you'll also protect the port (although new ports are sturdy).

You will need to write some software to spit out pwm on the pulses. You'll need to toggle register 0x378, bit 0. Common duty cycle is 50hz. The 'center' pwm is 1.5 ms. You'll need to write the software, although someone might already have done it for you.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline alexanderTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: servos and parallel port
« Reply #3 on: April 28, 2008, 08:32:59 PM »
Thanks 'izua'.

Just two more questions:

- When you say 'get +5' did you mean get from a battery or from the parallel port?

- How can I inverse the rotation (clock-wise, counter-clockwise)?

Is this schematic ok: http://www2.eletronica.org/hack-s-dicas/regulador-lm7805 ?

The software is really easy for me. Electronic is my torment. :)

[]'s
Alexander
Brazil - Rio de Janeiro


Offline alexanderTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: servos and parallel port
« Reply #4 on: April 28, 2008, 08:38:21 PM »
I forgot my third question :D

The regulator is just for protection... or not? If I use directly signals from parallel port (ok, ok, I won't do this...) it's supposed to work, or not?

Thanks a lot... this forum save me a lot of time and work.

Really thanks to all!

[]'s
Alexander
Brazil - Rio de Janeiro

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: servos and parallel port
« Reply #5 on: April 29, 2008, 07:36:27 AM »
Here you go. signals to the servo are only for illustrative purpose, i'm not familliar with the pinout.
7805 gives a clean level of +5V.
you can go with the signal directly from the port, but you won't be able to power the servo from the port.

edit: when i say get +5v, it means out of the regulator. you will need more voltage into it.
rotation is controlled by pwm rate. 1.5ms is middle, 1.0ms is one direction, 2.0 ms is the other one.
« Last Edit: April 29, 2008, 07:41:25 AM by izua »
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline alexanderTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: servos and parallel port
« Reply #6 on: April 29, 2008, 06:37:15 PM »
Thanks for the picture :D

I think I'm understanding better now.

So, I normally use the computer power supply on my projects... I think I can get a 5v power without need a regulator.

I want to try something like this (what do you think?): http://www.andrew.cmu.edu/user/suppe/mobot/mobot2.html

But... I think is better use your idea (the regulator) in conjunction of the circuit above.

[]'s
Alexander
Brazil - Rio de Janeiro

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: servos and parallel port
« Reply #7 on: April 29, 2008, 06:46:01 PM »
You will need at least 6 volts to power a regulator.
A computer power supply is great as a tool, but don't use the one you're powering your computer with. I wouldn't.
I included the 5V there 'cause later you might want an uc or something else to control the servo. I just throw it there in general, but it's not really required as long as you don't give the servo too much voltage. Otherwise, just power both the servo and the transistor from your other voltage source.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline alexanderTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: servos and parallel port
« Reply #8 on: May 04, 2008, 07:24:38 AM »
Hi again.

I made some tests with my servo Tower Pro SG-90 Micro Servo 9g, and... not work...

In fact I can move the motor to the right/clockwise.

I tried a lot of times and seems impossible to move the motor to the left.

Can someone take a look? Or tell me what I'm doing wrong.

I used this schema: http://www.andrew.cmu.edu/user/suppe/mobot/mobot2.html

And used this program (I tried this times in usleep: 10, 15, 20, 30, 35, 100, 200, 150, 120, 12, ...):

#include <stdio.h>
#include <sys/io.h>

int main () {

int PINS28=0x378;
int i;
int sinal28=255;

ioperm(PINS28,3,1);

    for (i=0; i<1000; i++) {
        outb(sinal28,PINS28);
        usleep(120);
        outb(0,PINS28);
    }

    outb(0,PINS28);
}

Thanks!
Alexander
Brazil - Rio de Janeiro

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: servos and parallel port
« Reply #9 on: May 04, 2008, 08:25:07 AM »
your signal is invalid, dude. check the generation loop.
youi set the pin high, wait a while, set the pin low, and immediately set the pin high again. the servo picks it up as one direction (probably reacts as to 20ms). However you'll change the direction, your width % will still be close to 90%.

Try something like this for instance
Code: [Select]
//warning, hand written code, not tested.
double t_up = 1.5;
double t_down = 20-up;
//t_up holds how much the pulse is up, t_down is the differenece of t_up to 20ms (50hz).

while(1)
{
outb(255,0x378);
wait(t_up);
outb(0,0x378);
wait(t_down);
}

there are some problems with the code, first beeing that windows' kernel will guarantee at least the time you pass it in usleep, but it's ussually more.
you could try using kernel CPU resolution timers instead of a plain API call, you might get a much better accuracy. All you will probably get here is 1 ms and 2 ms, at best.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline alexanderTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: servos and parallel port
« Reply #10 on: May 04, 2008, 08:37:04 AM »
God! How stupid!

Thanks!!

PS: I'm using Linux, not Windows. And my computer will just control the robot. I don't use this computer for anything else.

[]'s
Alexander
Brazil - Rio de Janeiro

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: servos and parallel port
« Reply #11 on: May 04, 2008, 08:41:50 AM »
That's great to hear, hehe. I'm not sure of the thread sleep resolution in linux, however, if it won't work out fine, just use the CPU timer. And give the control thread a nice of -15..-19, that should help, too.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

 


Get Your Ad Here

data_list