Convert a 0 to +5 signal to a +/-5 signal - Page 1
Forum section: electronics / beginners

author: Stonent
author_rank: Super Contributor
timestamp: June 09, 2014, 04:32:36 pm
content: I need to convert a 0 to +5 square wave into a +5 to -5 signal. The signal is being generated by a microcontroller and the resulting +/-5 needs to be able to drive a small electromagnet that's about 220 Ohms.Nothing in the circuit is voltage or timing critical in fact the solenoid works fine from an AA battery. I just chose +/-5 so I didn't have to get two voltage sources.It would seem that you could build a circuit with an NPN and PNP transistor but I'm having trouble figuring out how wire it correctly.The circuit will not be at a fixed frequency but I doubt it will go over a few hundred hertz just because the reaction time electromagnet. I suppose ideally I would like the ability to have a +5, 0 and -5 rather than just either being +5 or -5. I can use more than one I/O pin on the mcu if needed, but it would seem that you could express this with a tri-state setup with +5 being +5, input being 0, and Gnd being -5.

author: mazurov
author_rank: Frequent Contributor
timestamp: June 09, 2014, 04:43:06 pm
content: You can try MAX232 TTL to RS-232 converter. The output voltage will be higher though.

author: oPossum
author_rank: Super Contributor
timestamp: June 09, 2014, 04:44:25 pm
content: You can do it with an op-amp...For -5/0/+5 output, just use 2 identical resistors on two pins for 0/2.5/5 in.If the electromagnet is not grounded, just drive it with two 0/5V signals.

author: Stonent
author_rank: Super Contributor
timestamp: June 09, 2014, 04:58:02 pm
content: I suppose also going to +/- 2.5V would work as well.I have quite a few transistors I can spare, mostly PN2222, 3904 and 3906, but not any OpAmps.The project is a part of the time machine display for my wife's classroom, the signal is needed to drive the wall clock's ticking so I can speed it up and slow it down.From what I discovered yesterday, to complete a tick, the signal has to go over and under 0, not just positive and zero. If I just pulse on and off the second hand ticks forward and falls back to where it was. When I looked at the signal on my oscilloscope I saw how it was going over and under 0 volts.I know I could use other sources for the signal but since I plan to use a microcontroller in other parts of the display I figured I'd include it in this part as well.

author: oPossum
author_rank: Super Contributor
timestamp: June 09, 2014, 05:30:00 pm
content: Oh, it's a clock solenoid.Try 2 output pins with a ~330 ohm series resistor. That will give you bipolar drive and should have enough current for that little solenoid.Code:Out 1 Out 2 SolenoidLow Low 0High Low +Low High -High High 0

author: Stonent
author_rank: Super Contributor
timestamp: June 09, 2014, 06:00:00 pm
content: Quote from: oPossum on June 09, 2014, 05:30:00 pmThanks. Do you think there's much risk when the field collapses on the transition that it could kick back and damage anything, or would the 330R resistors be enough for that?

author: Dave
author_rank: Super Contributor
timestamp: June 09, 2014, 06:11:52 pm
content: Why not make a small H-bridge? That way you also avoid the potential inductive kickback of the coil damaging the micro.

author: oPossum
author_rank: Super Contributor
timestamp: June 09, 2014, 06:14:30 pm
content: It's on the edge of what a micro will tolerate. You could buffer it with almost any buffer/inverter chip (74x04, 74x125, 74x244, etc...) or use your 2N3904/2N3906 as an emitter follower (common collector amp).

author: Stonent
author_rank: Super Contributor
timestamp: June 11, 2014, 05:29:41 pm
content: I was able to drive the clock last night. Unfortunately even with the resistor recommendations it didn't have enough current to force a tick over. So what I ended up doing is putting a potentiometer in series and adjusting down until I could get it going with the final outcome being a 100 ohm resistor in series with the MCU pins. I have to short the resistor to get it to start moving the gears and then remove the short so it can continue off of the 100 Ohm resistor.The pulses I ended up with are to invert every 18ms. 17ms seems to have a little trouble starting sometimes, but 18 seems stable. As of yet I haven't figured out a way to control the direction other than repeatedly resetting the power or tapping the second hand while it is in motion to cause it to change direction.At the current rate of speed the minute hand moves at about the rate the second hand used to move.I suspect the original wave form had something to do with keeping it in the same direction all the time. I'm pretty much using a square wave right now, but I haven't scoped it out yet.When I was looking at the original wave form, it looked sort of like this. (Not to time scale)So the upside had a curve up and the down side had a curve down. Due to the slowness of the spacing I can't get the up and down curve on my analog scope on the same screen. That's also the reason I don't see a vertical line, it just shuts the power off at the end.