Noob needs help with opto isolator circuit.

Discussion in 'General Electronics Chat' started by kawgomoo, Aug 5, 2014.

  1. kawgomoo

    Thread Starter New Member

    Aug 5, 2014
    First off. I will apologize for my total ignorance on the subject, i am in way over my head. :eek:

    What i am doing. I have a small CNC machine from the 90's i am attempting to control from the LPT port of my laptop running WIN XP.

    Everything thus far is working, but i am down to my last nit picky item. Which has me stumped.

    Once the computer is booted into…anything, everything is fine. If it is booted into windows, you are good to go. Everything works as it should.

    If you hit F2 during startup, and boot into the BIOS screen, once again. Everything is good.

    However, the issue arises while the computer is booting up, before and during the post screen, when the windows loading screen pops up everything goes normal, and then briefly between the windows load screen and the desktop popping up the machine axes "blip"

    What it boils down to, is all the LPT port pins go HIGH during certain times of boot up etc. For all the steppers, this isn't a big deal. Everything moves one step. However, the machine spindle during this time turns itself on. And thats pretty scary.

    What i have tried to do.

    i built a simple single channel opto isolator circuit to turn the machine spindle on and off.

    At first test, when you booted into windows but didn't have the mach3 cnc program open. all the LPT pins would go HIGH, and the spindle would run uncontrolled. Once you opened the software it took control of the LPT port and the spindle stopped.

    Using PARMON i noticed pin 17 is the only output pin that stays low once windows boots. So using that pin to drive my opto isolator circuit everything works in windows as it should. When the laptop is booted into windows, the cnc machine sits idle. Once i go into the software i can turn the spindle on and off as i want by toggling pin 17 high to low.

    I cannot find a way to make pin stay low during those mentioned boot up times.

    For example. With the CNC powered on, and the laptop powered off.

    I push the power button on the laptop, the spindle on the CNC machine starts running.

    The spindle continues running through the bios screens.

    Window loading screen with the progress bar pops up, spindle stops. Once this screen disappears and the desktop is loading the spindle will briefly run again.

    I have tried pull down resistors of every value i have on pin 17 to try and force it low during start up. If i use a low enough resistance to cure the start up problem, their isn't enough left to trigger the opto isolator when i command the port to go high.

    for pull downs i have tried 1k {pulls to low, computer cannot command high} 2k2 {computer can command high and low, however spindle still runs during boot} I started with 1m ohm pulldown and worked my way down.

    I feel like the computer is commanding pin 17 to go high during these boot times. Maybe in the bios somewhere? I feel no amount of tinkering with my simple circuit will make it work…. But maybe i am missing something here.

    Is there some way to edit whatever is forcing pin 17 to go high during these "black screen" times during computer booting?

    I HATE the idea of the windows computer crashing or locking up, and the result is the cnc machine turns itself ON.

    Help!? lol


    {did any of this make sense?}
  2. MaxHeadRoom


    Jul 18, 2013
    For starters you should NOT have power to any part of the machine that is motor powered, Stepper/servos/spindle etc, while the PC or other controller is powering up, and also if the PC crashes, there should be some kind of safety such as a watch dog timer that drops out the external E-Stop circuit that is manually set/engaged when the system is ready for control.
    IOW, you have an external hard wired relay of some kind with all the necessary functions wired in an a AND function that disables the moving elements, and this requires a manual start by P.B. to ready the system, if anything in the E_stop string is not ready, O.T. limits etc, a start cannot be accomplished.
  3. MaxHeadRoom


    Jul 18, 2013
    BTW, Mach has a form of watchdog called a charge pump, this indicates whether Mach has booted up OK and also the health of the PC, detect crashes etc.
    This should be used to enable the E-stop also.
  4. kawgomoo

    Thread Starter New Member

    Aug 5, 2014
    My problem is getting to mach without the glitching. Their is no simple way to break the connection between the LPT port and the stepper driver.

    I need a way to severe the connection until such a time the pc is ready, or if the pc crashes it severes the logic connection.

    This does not seem to be implemented into any stepper board i have seen, and its not something within the scope of Mach to control.

    Here is a post from another forum where the gentleman have solved this issue. However, his description of what he did to solve the issue is beyond my capability to understand. In his situation, when the pc booted it would key the microphone to his HAM radio. This is the same issue I'm having.

    "I am pleasantly surprised by the response of two distinguished contest
    program writers! K1EA might take a bit longer :)

    My worst hamradio frustrations in 60's were with arcing power amplifiers at
    the beginning of CW TX. I use PTT, no annoying full BK. Sorry for few
    seconds of occasional QRM...

    Pin 1 might be better used for stereo/mono switching in SO2R environment but
    that is another question concerning M$ OS XP and NT limits to LPT access.

    I am glad this discussion takes place at Writelog reflector after a nice
    W5XD article explaining his common sense approach to program changes.

    MX & HNY & 73 de Mario, S56A, N1YU ( STROBE=PTT)

    ----- Original Message -----
    From: "Tree N6TR" <>
    To: <>; <>; <>;
    <>; <>
    Cc: <>; <>
    Sent: Sunday, December 23, 2001 6:34 AM
    Subject: Re: [WriteLog] 10.69 Fixed the LPT Pin 16 Problem

    > > I always assumed that K1EA used pin 1 (strobe) for the emitter of the
    > > keying transistor because the state of pin 17 (CW out) is unknown when
    > > computer is started. I'm not sure if this is a random condition or a
    > > issue, but on many computers pin 17 is high when booted which causes a
    > > radio to go key down (very annoying). By keeping pin 1 unasserted, the
    > > logging program can prevent keying until the pin 17 is low. Indeed, if
    > > recall correctly early versions of CT keyed only pin 1.
    > I had always assumed the same thing - or perhaps someone was having
    > with a leaky transistor, and this was a way to keep it off. However, the
    > "no CW" at power up is nice.
    > > Some years later, N6TR introduces PTT control on pin 16. This pin has
    > > same problem as pin 17 - an undetermined state at startup. To prevent
    > > unintentional PTT assertion at bootup, an duplicate of the CW keying
    > > circuit was used. However, since pin 1 has to be shared now, it can't
    > > keyed for CW so positive keying on pin 17 is introduced.
    > Yes - I think I actually "or'd" the PTT signal into the Pin 1, so that
    > you could have the same "no key" on boot feature.
    > > I've always been concerned about the current handling capacity of the
    > > circuit connected to pin 1. This was designed as a ~STROBE signal to a
    > > printer, now we hang CW keying circuits and PTT on it. The CW line is
    > > almost certainly low current, but who knows about PTT? You never know -with certain radio types that line might directly pull in a relay coil.
    > Yup - this can be a problem - and I have found some computers just can't
    > handle the current.
    > > In most of my CW interfaces now I've added a CMOS logic IC to allow pin
    > > to inhibit the CW keying and PTT in the signal path. The output devices
    > > interfacing to the radio can sink directly to ground without the
    > > going into the LPT port. One added advantage is that the key-down
    > > saturation voltage is lower, thus ensuring full power out on CW. (Don't
    > > laugh - I tried to use a Darlington output optocoupler to key/PTT one of
    > > radios and it would not work!).
    > I have essentially done the same thing. I just put a double inverter on
    > pin 1, and use that to sink the current in the emitters.
    > > BTW, CW out has always been pin 17, not 16. Pin 16 is PTT. This is the
    > > way NA has been for years and I've just been copying everybody. I just
    > > checked this against a reasonably recent TRLog manual.
    > Yup. I am the one who added the PTT as Dave says, and I tried to do it
    > in such a way that everyone else could copy it. I was trying to seel TR
    > Log to W3LPL once, and I guess he was impressed enough with the PTT
    > (which I think is really an important thing that most people don't know
    > they need) that he got Ken to add it to CT?
    > > Not to embarrass anyone, but you can't count on WX0B to get the pins
    > > right. He got his NA pinouts second hand and they were incorrect (Jay
    > > me this).
    > >
    > > Jeez...I thought we had all settled on a standard :-(
    > I think we mostly have. No harm in making the STROBE go low during PTT in
    > book.
    > Tree"
  5. MaxHeadRoom


    Jul 18, 2013
    I don't think you read my other posts, Mach has a feature called a charge pump, this is equivalent to a watch dog timer, that monitors the health of the PC system and is output through the P.P., this charge pump is a PWM signal that is included on some stepper boards, I believe Gecko utilizes it, if you have a system or BOB that does not have it, then it can be implemented by an external custom circuit such as a 555 timer etc, the Gecko site I believe has a suggested circuit.
    The bottom line is that any CNC machine should have a hard wired E-Stop circuit that includes some kind of PC monitor that does not allow the powering of the motion section of the machine until the system is ready and healthy.
    This has been the industry standard way since the virtual inception of motion control and CNC.
    And, BTW is also included in NEC and NFPA79 regulations.
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    My (home designed and built) CNC machine has a PIC micro inside it, that receives commands from the PC of where to move to, then the PIC micro checks that the move cannot pass end limits, and is within the correct speeds etc every time before it moves. Very safe. :)

    Of course that still does not stop it trying to mash an endmill through a job when I give it the wrong coordinates!

    No matter how smart you make a machine, it can still be beaten by a stupid enough human... ;)
  7. MaxHeadRoom


    Jul 18, 2013
    However the OP's problem is attempting to overcome the changing conditions that occur on a P.P. when the PC boots up and loads Mach and resulting switching on of motors that are powered ready.;)
    Last edited: Aug 6, 2014
  8. kawgomoo

    Thread Starter New Member

    Aug 5, 2014

    Ok first things first.

    This is a control retrofit on a Paxton/Patterson CNC Traning Center. It was built in the 90's.

    I am working within its design limitations, and my understanding limitations.

    I have to solve each problem, as they arise, before i can progress to the next issue.

    So far i have Pin mapped the PC's db25 to what the lathe wants to see. This machine was a basket case when i got it from a city auction. I bought it sight unseen lol. {for the lofty sum of 75 bucks}

    My progress follows as such:
    1)Reassemble&Repair machine to working manual state.
    2)Pin map DB25 cable to see if communication is possible. {i don't have the computer card or oem dongle this machine requires to run}
    3)Test Axes movement under Mach
    4)Get spindle control under Mach
    5)System Testing/ Finding Glitches.

    This is where I'm at now. Ive got the machine up and communicating. No small hurdle. Don't get me wrong, i planned to address the stepper motor glitching as well. However the priority was nowhere near as high as getting the spindle under control. The spindle is just off or on, and i like my fingers…as well as all the test equipment I've got draped all over this thing i don't want anything getting sucked in for no good reason.

    The issue at hand, the spindle glitching.

    This is a hardware issue. It happens before Mach. The PCI card that i don't have i assume would handle all these functions…but since i don't have it ;)

    For the spindle glitch issue, which is now resolved, i built a {2 bit?} logic circuit that drives an optical isolator circuit, this is all packaged inside of my DB25 jumper box/dongle thing.

    When the computer goes into a boot state all the pins go high. The OPTIDRIVER stepper board the machine uses has no provisions to "disarm" or await a signal from the current pump in mach. The logic circuit {74ls86} requires one low one high pin, driven off outputs 8 and 9 from the DB25. The odds of the computer pulsing the correct "sequence" to turn on this gate is much less likely than a simple transistor or AND gate. The ls86 is an XOR gate. Actually its 4 XOR gates packaged in one chip.

    Onto the current pump issue.

    Max brings up a very good point, one that is paramount in my mind.


    The next elephant in the room is the fact the machine is powering up with the steppers "live". Now how can we fix that?

    Well fortunately, the 74ls86 has 4 exclusive gates. I only used one to enable the spindle circuit.

    Since I'm running low on pins in my connector {and i want to add a spindle sync sensor for threading} I will share one logic input from the previous gate {spindle} and i will pull one more db25 pin over to the chip.

    I can then use that logic circuit to drive the current select pins on my OPTIDRIVER board, which will effectively lock it out during periods of computer freak out.

    Ive got the current select pins grounded to turn them "on", I'm not sure if the "hi/lo" output of the ls86 will drive them, or if i will need to use a transistor of some sort to open or close ground to the current select pins.
  9. MaxHeadRoom


    Jul 18, 2013
    Are you intending to switch over to Mach completely as it seems you are missing a card that came with the original machine?
    Although you mention that safety is paramount you still do not seem to intend to disable the power for the Steppers and spindle until the external E-stop is satisfied and also receive the E-stop OK from Mach?
    Mach has both an E-stop output signal and also allowance for E-stop in to flag that the external E-stop has tripped and to cease motion, remember that Mach has no idea what is going on externally with both steppers and spindle.
    If you are determined NOT to use the E-stop circuit to remove power from the steppers/spindle, it can also be done from a Mach output to the stepper drive EN input.
    What or Who's stepper drives are being used at present?
  10. kawgomoo

    Thread Starter New Member

    Aug 5, 2014
    The machine has an Estop. It has no function.

    The only way you can remove power from the steppers is to disable to "CURRENT ENABLE" pins on the optidriver. This is how {i assume} the PCI card does it.

    All the estoppery is isolated to ghost channels on the db25 {i.e. channel 27} Making them totally out of my reach…and anyone else who can't manufacture one off PCI cards.

    If you read the last 4 sentences in my last post, those describe my plan to bring "stepper power down" into automated control.

    Mach3 is the only software being used to control this. The OEM PC that controls the machine, along with its cards and software are long gone.

    I am absolutely intent on bringing the estop back online, and getting the steppers safe.

    The optidriver has the DB25 input on it, then passes through to a break out board which distributes power to the various items.

    The little dongle i am building has to house the necessary logic so MACH can control the items inside the Paxton machine. They do not speak compatible languages.

    As i stated, the dongle houses two i/c's. They are providing the logic necessary to allow mach's simple single channel output to safely control the optidriver. All the dongle does is pin mapping, and drop out protection. The logic circuits simply serve to sever the connection from PC to LATHE when **** hits the fan.

    The lathe, by default. Is always on. I didn't build it. There are thousands just like it. You are preaching to the wrong guy. The missing PCI card could have had these circuits built in, also the missing computer is a dos machine, I'm in winxp which doesn't allow direct kernel control. Leaving me to write drivers, or build hardware to make this thing work.

    I have no interest in replacing the stepper controller with a gecko. what is there works, and is a robust all be it dated drive.

    Right now the estop on the machine does nothing. i know its their in mach, but mach doesn't have any influence over the machine right now. besides step and direction. thats what I'm trying to fix.

    With this circuit that i am planning on building now, once the estop flag is thrown it will disable the "Current Enable" for the steppers, and the Spindle. Making the machine….Dead.

    Its just an expansion of the XOR gate in the LS86 ic i am using. It has four gates, each triggered by 2 bits of logic. Using 3 pins from the db25 i can control 2 channels on the chip, i am saving a pin by using a common logic state on multiple channels.

    That gives me enough room in the db25 to add a wire from my optical encoder on the spindle and run a physical connection from the estop switch to mach.

    That should be the last 2 pieces of the puzzle. There is also a shield switch that does not work, which i can wire inline with the estop button so the machine estops anytime the cover is opened or the button is pushed.

    Now maybe there is some peripheral device that plugs into a db25 cable, and allows you to configure all this crap. But i don't know of one. {could use an arduino I'm sure} But alas. This works, is relatively simple and cheap, and should do everything i ask of it.
  11. MaxHeadRoom


    Jul 18, 2013
    The big problem is that is hard to establish exactly what you have in the way of hardware without a detailed reference of some kind, so it may be a step by step process!
    Some kind of schematic and details of what you intend fitting or already have in place is really required to eliminate guess work.
    In the absence of original documentation it may be necessary to reverse engineer the present system and document it.
    As it was a machine used in teaching I would seriously expect an E-stop circuit to be present.
    If this is restored I would expect your spurious movements on power up to disappear.
    What is the type of spindle? AC motor with VFD? DC with controller? You say it is just on/off? No speed control?
    As I mentioned before, the E-Stop should be a hard wired circuit, not purely software origin.
  12. kawgomoo

    Thread Starter New Member

    Aug 5, 2014
    If you google Paxton/Patteron CNC training center you will find it. Its a sherline 4000 mini lathe, with 82oz steppers. Thats all I've been able to find out about it.

    The Estop button is hard wired. It goes to the Optidriver board. But does not appear in the DB25 connector. This is what i mean by its on a ghost channel. Its a channel created through some sort of logical communication, not hard wired to a pin in the db25 connector.

    As such, making the button talk back to Mach is impossible {for me}, without making changes INSIDE the cnc lathe. I will post some pics so you see what i mean.

    My first goal was to get the machine pseudo operational and find out what, if anything was salvageable. As it turns out, so far pretty much everything has been OK. just needing some tweaking or refitting.

    Right now my goal is to see how far i can develop the INTERFACE dongle between machine and PC loaded with Mach. I am in the midst of reverse engineering the lathe right now, to find out what is, or is not possible, without making any changes inside the machine. {To benefit the next sucker that goes through this}

    My little circuit to isolate the spindle may very well end up being temporary. But for where i am at in the development stage, i needed to incorporate some level of safety into the machine. I will be booting the computer frequently, plugging, unplugging. I don't need it going haywire in the meantime.

    Right now actually, i am going to address the estop situation and see what i can't come up with.

    The estop mushroom switch itself appears broken. It works, but its loose, and it doesn't latch. No idea if it ever did. Right now its a momentary switch that sends a ground signal to the optidriver board. With the machine running, pushing the estop does nothing. Not in manual mode or cnc mode. The switch does electrically open and close. I do have spare estop switches laying around, so thats no big deal to replace.

    Spindle Speed is controlled through some sort of basic speed control. It has a pot that affects speed, much like a glorified ceiling fan dimmer. It is not a VFD or anything cool. The channel that controls my ls86 could be mapped to PWM through mac and let me control speed by pulsing the SSR and eliminating the other piece of crap…I think?

    The spindle motor is not reversible in any way so far as i can tell.

    Bear in mind, i know nothing about CNC, Computer, Electronics or any of the skills related to this.

    I downloaded Mach for the first time ever over the weekend, been working on this little thing a little bit each day.

    Once i got the spindle wired up, i had to stop, go learn enough about G Code so i could start and stop the spindle through mach. I knew it worked with PARMON but just wanted to see it happen through the Mach console was cool.

    So far M3 M4 and M5 is the sum of all the g code i know! even figuring out where and how to enter it into mach was a journey in of itself!
  13. kawgomoo

    Thread Starter New Member

    Aug 5, 2014
    Ok next question. There are 6 pins labeled M1- Limit, M1+ Limit, M2- Limit etc.

    What are these? The machine itself has 2 limit switches, and no home switches. Unless i am totally missing something.

    Im looking to free up a few pins, so i have enough to do everything i want. Not sure what exactly i can eliminate, or what each of these functions is supposed to do.

    Also attached is the only info i have on the machine.
  14. MaxHeadRoom


    Jul 18, 2013
    Normally for a lathe you would see at least 4 limits, X+,X-, Z+ & Z- all over travel limits, with Mach, the O.T. limits also work as Home limits, double duty when first powered up.
    I suspect there are 3 lots to cover a 3 axis mill etc.
  15. kawgomoo

    Thread Starter New Member

    Aug 5, 2014
    Yes, these guys build a little mill too. I had hoped to keep the third axis wiring intact, so this dongle will work for both machines.

    Why does each limit/home switch have a - and +?

    Can i wire both limit switches to one channel? or do they need to be on separate pins?

    How does an estop typically interface with one of these cnc machines? just logic to the mach program or should it physically shut the whole machine down? {kill power}

    When i wire up estops on other stuff i build, they are wired into the main contactor, so when you push it the entire machine goes dead. But those are simple analog machines.
  16. MaxHeadRoom


    Jul 18, 2013
    The limits are at each end of the ball screw etc, so that the +X +Z is each axis plus limit and the same with the -X -Z Plus on a Lathe is usually farthest away from the chuck.
    In the case of Mach, the + limits also operate as home limits to reference the machine.
    Mach's method is to wire the limits in series and when you home, it heads to the X and then Z and expects to see a limit which it assumes pertains to the axis you are homing.
    That is exactly how the E-Stop works, or should, if you have wired one before then you are familiar with it, the limits string should include any interlock switch and E-stop P.B. the relay at the end of the string will pick up the power for the spindle and stepper drives, there would also be a contact that goes to Mach to release the the stop.
    If you have a limited knowledge of the electrics, it is most likely going to be a step at a time, as there appears to be a bit of work to get it going.
  17. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    1. activate the estop before powering up the CNC machine
    2. activate the PC/MACH3 before powering up the CNC machine

    I'm not sure why the steppers being "live" is a problem. They can't move at all until MACH3 sends step pulses out the parallel port.
  18. MaxHeadRoom


    Jul 18, 2013
    This has been an issue as seen by many on other hobby CNC forums, pulses appear on the P.P. as the P.C. and Mach load.
    It is generally more serious for the spindle where those that have fitted a SSR say to switch a router on, have seen the router start up due to the arbitrary state of the P.P. until Mach takes the port over.
    Regardless, safe procedures should be put in place.
    Although Mach is hobby based S/W, at least they have addressed the issue of E-stop input and output, and supplied a way to shut any powered devices off via the charge pump signal in order to comply with normal machine safety practices.
    Just because CNC has entered the realm of hobbyist's, there is still a need to conform to the certain practices that have developed over time in the industry.
    THE_RB likes this.
  19. kawgomoo

    Thread Starter New Member

    Aug 5, 2014
    The Factory Estop has been fixed. It had been hot wired closed. It only kills power to the spindle however. It does not send a signal back to the stepper board at all :/ and does not kill power to the entire machine.

    When you power up the laptop the steppers do in fact move. Not much, only a couple steps. However, it is really freaking annoying. Also if machining a piece and you rebooted the computer your tool would move. Does this matter? i don't know. But it seems like it would suck.

    My understanding of electrics in general is pretty solid. Switches, wires etc. But when it comes to designing logic circuits off the cuff to interface with a machine that I'm not even sure what its supposed to be doing. Well, that can be a little challenging.

    Also, this machine only has Z- limit switch and X+ switch. I don't want it to home close to the chuck like that. So i will end up adding another switch.

    Good call on the -/+ thing. I thought it was a dedicated positive and ground for each switch. Now i realize it is an input for different switches at opposite ends of the machines travel {makes much more sense}

    My plan as of now.

    I want to put the Shield switch and Estop in series, so if either the cover is opened or button pressed the machine will estop.

    I will get the limit switches in NC series as suggested by mach. I may add another switch to the Z so i can home at the tail stock end.

    Now i am going to attempt to expand my logic isolation circuit to Disable the stepper current enable function on the board. This turns the steppers "off". By isolating the single enable pin it prevents the steppers from moving around while the pc boots up and down. {which yes it does do, and i hate it}

  20. kawgomoo

    Thread Starter New Member

    Aug 5, 2014

    As max stated, the PP goes into an unknown state during computer boot up. The bios also polls the port to see if any hardware is connected, i.e. a printer. This polling of the port causes things to happen on the CNC machine.

    Win98 users don't experience this as much as win2k/nt/xp user do.

    The Charge Pump Function inside of Mach is an ATTEMPT to rectify this situation, Unfortunately it is not very effective, at all.

    Charge pump is a single output, like everything else. Since the PP goes into an undefined state, and then goes through an "ALL HOT" state when the bios probes the port. Anything plugged into the PP at this time will trigger if its an active high during the bios port probing. During the undefined times, anything can happen.

    That is why my Dongle has to have hardware inside of it. My machine is not setup for a charge pump function. Also, i cannot globally power down the machine {easily} during startup and shutdown. Further more, if the machine loses communication with the laptop for any reason i CANNOT have it default or trip into an unsafe state. The dongle requires a Code to be sent to it from the PC in order to initialize the PP and allow communication to the CNC machine. When the computer freezes up or drops out, communication is lost to the dongle which shuts down all communication to the CNC as well as powering down the spindle and steppers. This is why i built it. So under ALL CONDITIONS the machine will remain safe. A startup and shutdown protocol of killing power might stop the machine from freaking out when you want it to, but i cannot accept a machine that does what it wants whenever the pc drops out.

    We use Laptops for tuning car engine control computers, the same issues have been realized before. Except when you are driving a vehicle and the laptop drops out it can shut down your engine, or all kinds of other crazy stuff.

    People preach the Estop. But if your estop is Software only, configured on one pin. you are messing up. The estop needs to have authority to stop the machine, no matter what the computer is doing. It is totally possible for a windows computer to lock up while pulsing a stepper, continue wildly pulsing that stepper while ignoring estop requests on the PPort as the machine runs away.