Controlling 2 servos with one pin using a transistor??
kleekru
Posts: 32
Is it possible to switch between two servos using a (or a couple) of transistors from one output pin?
I have basic servo control working but tried to use a transistor to switch the control of that servo on and off (from another pin)... and I cannot seem to do it.
I'm using an IRF510 with the attached schematic (pardon the very poor quality photo).
I would like to send a signal to the gate on the transistor to open the switch for a servo and then control the servo using a pwm pulse (from another pin).
I realize this will use 3 pins (one for each transistor) and one for the signal to the servos to switch between two servos but bear with me.
Thank you!!
Kevin
I have basic servo control working but tried to use a transistor to switch the control of that servo on and off (from another pin)... and I cannot seem to do it.
I'm using an IRF510 with the attached schematic (pardon the very poor quality photo).
I would like to send a signal to the gate on the transistor to open the switch for a servo and then control the servo using a pwm pulse (from another pin).
I realize this will use 3 pins (one for each transistor) and one for the signal to the servos to switch between two servos but bear with me.
Thank you!!
Kevin
Comments
You schematic is for controlling a motor not a servo. I'm pretty sure you can't control a hobby servo with the schematic you posted.
There's also the question of why not just control the servo directly since it requires fewer pins to control them directly?
The signal line to a servo does not require much current, there isn't an advantage to using a transistor (at least that I'm aware of).
I realize the schematic is for a motor but thought the concept would work through the ground for the servo to turn it on or off. Does that make sense?
Kevin
Much more than before.
I'm still doubtful about the transistor idea. I'd think the overhead of switching the lines would be as much work as bit banging servo control from the other digital outputs.
BTW, (Since you mentioned a different microcontroller first.) There is a microcontroller available that doesn't have any trouble with 32 servos.
I have never used a J-K. Where can you purchase these. I would like to read some datasheets.
As far as multiplexing to save I/O pins, it would be possible to use 4 outputs to drive 8 servos using a 3-to-8 line decoder chip like a 74HC138. Video shows my board using 3 lines to select one of 7 LEDs or a piezo beeper (data line hardwired high here, so one of the 8 outputs is always on). To drive servos, your Stamp would use 3 lines to select which of 8 servos, then send the control pulse on the data/enable line. Note that a Stamp would be pretty busy just doing this, without a lot of extra time to process other data. But it does save 4 I/O lines, if that's what you're after. Likely more useful on a BS1 than a BS2 in this particular case.
In similar fashion, you could use a 4-to-16 line decoder to drive 16 servos, like a 74HC154. Hmm. I might have to try this out myself!
I suppose the JK could be replaced by an inverter. That would be 5 transistors and I'm pretty sure with a little thought the count could be reduced.
This solution uses only one I/O pin to send a composite Servo pulse ... the J-K and the two NAND's break the composite pulse into two separate Servo Pulses. A simple RC timer is used to reset the J-K every 20ms to ensure that it will always start with Servo #1. This also allows a situation where if only one servo is addressed in the composite pulse then only the Servo #1 output is driven.
AFAIK, there's no configuration of that 2-transistor scenario which yields two "standard" pulse trains of 1-2 ms at 50 hz to keep the servos updated. At best, you could have accurate timing of either the high or low state with a pulsout, but the other state would be inaccurate and pick up all the overhead timing, so you couldn't time it to 2 uS or better accuracy.
Even if you could toggle the pulsouts accurately, (high ~1.5 ms, low ~1.5 ms, repeat), that would give you an output frequency of ~333 hz, not the standard 50 hz. IIRC, servos vary, some are fine with higher frequencies, some are not and they are unstable.
Another alternative would be driving the pin High-Z (essentially make it an input) for ~20 milliseconds so that neither transistor conducted, thus restoring the 50 hz drive frequency. It still comes down to timing the pulsouts properly and what works with your particular servo. Something like (untested):
Also, any of these options will consume more of your Stamp's overhead, all to save one I/O pin. What's that worth to you?
1. Update one servo
2. Toggle transistors
3. Wait 10ms
4. Update second servo
5. Toggle transistors
6. Wait 10ms
7. Loop
This would give each servo 20ms refresh
By the way, I burned the heck out of my finger (blister and all) on an IRF510 MOSFET transistor trying to pull it out of my breadboard after it was attached to a 9V battery... just a warning for the kids out there that might be brighter than me to respect your electronics.
http://forums.parallax.com/showthread.php/145218-Golf-Challenge-Controlling-2-servos-with-one-pin