NANO and Program work fine until other circuits are energized

I have a CNC machine that I built and the Mach 3 program has limited inputs (5) which I use for E-Stop, 3 Axis homes, and a Z zero macro. The project I created was using a NANO with 7 inputs and 2 outputs. Six of the inputs are end of travel LS (limit switch) for the X and Y axes. Each LS has its own input so at some point later I may want to know which limit has activated. The last input is a toggle switch input which programmatically allows for E-Stop to be reset and allows moving off of the LS overtravel.
Each of the two outputs activates a relay, one for 250 ms to tell the control program (Mach 3) that there is an E-stop occurrence. The Second output is to enable movement by enabling the enable signal (to High) to the steppers
I have multiple power supplies some are energized whenever the main breaker is on, others are on when power is applied to the steppers and the VFD (BTW the VFD is a 2.2KW system) One of the boards, the break-out board, (BOB) in the circuitry is powered by a USB cable from the PC, in addition, and also has a 12VDC source. All power supplies have a common ground tying back to The main ground coming into the circuit. All circuitry is connected to the same ground as well. All of the switches are connected to the NANO ground which is connected to the common ground. I step down the 12VDC to 5 VDC with a Buck Converter.
Pretty simple, one relay controls the 5VDC to enable input on the stepper drivers, and the other triggers an E-Stop to Mach 3. The BOB where the 5 inputs are connected is sitting around 11 VDC and go to the ground when activated, the NANO has a max of 5VDC so that is why the one relay and rather than supplying the current needed for the Enable signals through the NANO, I opted for the relay just controlling the 5VDC.
That is the description of the circuit and its functions. When powered by a static 5VDC and neither of the Steppers nor the VFD is powered, everything works just as I had planned it. I can activate any LS and the E-Stop will trigger for 250 ms, I can then toggle the enable input and the other relay will reconnect the 5 volts to the stepper drivers and bypass the limit switches so that I can reset E-Stop in Mach 3.
Now the problem, as soon as I power up the rest of the system, ie VFD and Steppers, the E-Stop relay toggles continuously, not always at the same repetition rate, however. I thought that perhaps there was noise now on the lines so I made some RC filters for each of the LS, no help there, if I activated an LS, then while depressed the E-Stop relay stopped cycling, as soon as I released the switch, the relay started up again. Seems like something is cycling something or triggering within the NANO I disconnected all the switches and sequentially reconnect only one at a time, no love there either, as soon as one was connected, or even just touching the screw, the relay would start cycling. Another interesting point: When holding a switch in the activated position, grounded every 4-10 seconds or longer, with no pattern, the E-Stop relay would cycle.
I suspected noise on the switch lines at first, but even just holding the tip of the screwdriver against the input connection would impact the ES relay.

Do I need to put the NANO in a shielded box?
Any thoughts or suggestions?

I would have attached a schematic and the program sketch, just couldn't figure out how to attach them.

A picture says more than a thousand words :wink: Please draw a complete wiring diagram / schematic, take a photo and post it here.

In addition, a photo of your setup might also help; electronics is not my strong point, maybe there is some crosstalk or EMI.

Lastly, although not that likely, you might have a bug in your sketch, so please post it (don't forget the code tags).

CNC Control.txt (6.2 KB)


I hope this fills in the gaps.

As an addendum, all inputs are using the INPUT_PULLUP); which is obvious in the sketch but important to help alleviate any noise by a floating input.

I got the chatter fixed, I think it was a loose connection connecting the RC circuit to the switches. I soldered each of them so that there was no problem with the connection and the chatter ended, but there is still a period where the E-Stop relay will trigger every 5, 10, or more seconds, sometimes only a second, but generally about 5-6 seconds. At this stage do not think it is a circuit problem, perhaps something in the sketch. Also if I have the By-Pass switch on ( sorry schematic is missing a ground connection between the By-Pass switch and the other switch's grounds.) The E-Stop relay remains de-energized, which it should. It should only cycle for 250 ms on a trip of an LS one time only, even if a different LS then trips, which of course should not happen as the machine is in E-Stop mode. The design of the sketch should prevent this from occurring, but I am no expert in any of this. I just know enough to dabble.

Corrected schematic.

If you are a novice at wiring, I also want to see images of it. Also "5 VDC" doesn't really explain where your power is coming from (and I'm not going to read your War and Peace manuscript to see if it's there...).

Points, though, for a neatly done diagram. :slight_smile:

How can "stepper driver" operate from only one wire? Is it an antenna?

Where are the current limiting resistors on the LEDs?

OK, I think I have resolved the problems, the chattering of the relay was probably a bad connection, soldered all connections for the RC filter to the switches and that problem went away.
The next was a challenging problem because it was unpredictable. Sometimes a second sometimes 5 or 6 and sometimes 15 or longer seconds. Standing there contemplating the problem, I placed my hands on each side of the machine's stepper motors, connecting each of the motor cases via my body resistance, the problem seemed to go away, and took a lot longer for the relay to cycle, perhaps 2-3 minutes. The stepper motors shells are not grounded nor are any of the machine's metal parts. Added grounds to all of the machine's parts and it seems that the problem is solved. I want to wait 30 or so minutes to be sure as having a rouge E-Stop in the middle of machining is not a good thing.
I appreciate the insight that I received as I continued to work on this problem. I also had a chance to review my schematic in more detail and revised it to accurately reflect the circuit.
Thank you

Please post that for people that come across this thread.

I think you are doing yourself a disservice by not posting images of your hardware. There is probably a lot of room for improvement. Especially if you want to be really sure of things.


Updated Schematic

CNC Electronics panel

Noise when Steppers and VFD were powered

The problem is still occurring but time is considerably longer. I will hard-wire the ground connections rather than just using clip leads and see if that improves it. Blew O-scope, just stopped working, was junk anyway, but useful at times.

Unshielded "spaghetti" wiring. Sorry, but it can never be reliable.

I didn't ask, just to criticize you. It's to put you on the right path.

Also, your updated schematic still doesn't show ground connections.

Do D02-D08 have the INPUT_PULLUP option enabled in code?

2.2uF/100R is a pretty unorthodox input filter. What is the thinking behind that? Normally you would see something like one 0.1uF cap.

No reply from you about the current limiting resistors...

The steppers have 4 wires, but I was only showing the enable circuit connection of this project, not the entire machine. The 40 V P/S and the Steppers are not shown. as that circuitry has been functioning for about 7 years. I was only showing what is new to the project. Yes, I forgot to include the limiting resistors in the schematic. I will get to draw a complete diagram of the system for my future use as well so that when it breaks, I won't have to remember all the changes I made over the years.
The image of the electronics will show a lot that is not in this current project portion.
I have rebuilt my CNC from scratch starting in April, been a long journey. I will tidy things up when I am sure all is functioning properly, This is in my garage and I do plaques and clocks on it for a small amount of income and mainly as a hobby.

Cart before horse.

I will get to draw a complete diagram of the system for my future use as well so that when it breaks, I won't have to remember all the changes I made over the years.

It's far easier to do it before, and during, than afterwards.

I am not criticizing your efforts, which for you must be big. However the objective truth is that complex projects like this can not be expanded forever without following standard engineering practices. Those take a while to learn, but can't be learned if you don't follow them.

If not, it is easy to reach a point where even experienced people can't help you.

Sorry about this War and Peace, but The entire system is not a few words.

2.2uF/100R is a pretty unorthodox input filter. What is the thinking behind that? Normally you would see something like one 0.1uF cap.
I read an electronics guy's review on the internet of how he determined the values needed, seemed good to me. If it took a little longer, he was talking about 4 ms, for the transition and knocking out the bounce. Lots of math and beyond what I needed in theory.

I only put that (RC filter) in hopes that it would resolve my problem with the chattering. It didn't and bounce on D03 thru D08 is not a concern as any transition should trigger e-stop for the 1/4 second duration, any bounce within that period will not impact the operation. D02 on the other hand probably should be debounced, but I do not think it has to be as I will have to perform a manual function once I flip that switch before its purpose can be fulfilled.

D02 through D08 are all set to input pull-up mode. Actually, I don't currently have the LEDs even installed, but on my test board, I had them there and will put them in the schematic at some time in the future, they would be at the other end of the machine as well as the By-Pass switch, about 4 ft away.

I am confused, I show the 5 V source with the + and - connections with the - connected to ground and all the places that ground needs to be in this circuit, but not in the total machine. Perhaps I need to show something like a chassis ground in the diagram so it is noted and I have learned that grounding everything together including the chassis, which had no electrical connections, but the Steppers were bolted to the rails so that is apparently a problem.

Most of the spaghetti wiring you see is the 40VDC to the stepper drivers, The blueish BOB in the middle is what controls the stepper drivers just to right and up from the NANO in the image I uploaded. The grey connection is a USB converter to replace the old LPT port and provide input and output to Mach 3 CNC control program. It internally has some sort of microprocessor. All inputs both for the BOB and the NANO are power and switches active LOW Outputs from the BOB are digital direction and pulses for rotation. The BOB also has a 5VDC USB source from the PC. The four black boxes with green connectors on them are the stepper drivers, pulse, direction power and enable, outputs are the bi-polar connections to each stepper. Two of the steppers have slaved together as one axis the other two drive independent axis.
Just trying to fill in some blanks.
The white wires on the bottom coming from the NANO are the limit switch inputs all active LOW.
The terminal block to the left is 220 VAC input for the VFD only, but I pull 110AAC off of that TB for the other supplies. The 12VDC is used on the BOB and also feeds the buck converter for the 5 VDC to the NANO.
I didn't feel criticized, the code I included answered some and at this stage, I did not think the LEDs were all that important to this problem. I admit that shielded wiring would be good, and perhaps I may add it to the Steppers but all the wiring for the LS is already installed and run inside of the aluminum extrusions, which I hope will be shielding enough, especially when I chassis ground everything.

What is your recommendation for the RC components .1 Uf cap and 100-ohm resistor?

Other than the NANO circuitry, everything else has been faultless for a long time, many years.

What is the relay's coil current? Nano's output pin current is only 20 ~ 25mA continuous, you probably need "helper" transistors. 2N2222 is popular in U.S. The small blue relays found on hobbyist modules have coil currents of about 75mA @ 5V, two of those could pull Vcc down low enough to cause a brownout reset. That's why @ aarg asked about your 5V power supply.
relayTrans

An Optical Coupler/ Isolator is the input to the relay board, specs say * 5V 2-Channel Relay interface board and each one needs 15-20mA Driver Current. It doesn't say for sure what the coil needs, it looks like this is the indicator Supply voltage: 5VDC Current: Larger than 100mA Load: 250V 10A or 30V 10A DC
I am using a buck converter with a 3 amp capacity to 5 VDC powered by a 12 V DC source with a 5 amp capacity, but it is something to think about. Only one relay is energized at any one time. and generally, the relay that is intermittently energized only triggers for 250 ms. I will install a temporary 5 V additional supply just to make sure something isn't flaky with the 5-volt line. Additionally, in setup, I force the relay signal high so it is not triggered on power up or reset. (I think that is how it works)

I have a jumper that I can use to separate the Source for the coils so that the NANO is only feeding the input with its 5-volt source and a separate source for the coils. That should prevent any brownouts I think.

I added copper wire grounds to all of the extrusions of the machine and tied that to the common ground for the electronics. So far, after several hours, I have not had a false trigger occur.

I like the idea of separating the supplies one for the electronics and one for the relays. My schematic does not show the actual relay circuitry, it is missing the diode, the LED, and the optical isolator for the inputs as well as the jumper for separating the power sources. For me, it was a simple diagram to get the essence of what I wanted, but I can see that details are important so we can all be on the same page.
Thanks for your input

Don't know if your relay module is like this, but here's the general idea:

6m95zlV

D0upWXs_d

That is exactly what I am using, only the two relay module.

So I will remove the jumper and feed the JD-Vcc with a separate 5-volt source.

I am getting closer to a resolution:

Last night the system did not trigger for over 4 hours, but it did trigger. Much better than the 4-5 seconds, before I added grounds to the chassis.

I am thinking that I will use shielded wires for the switches. I have them for the home switches and they have never, to my knowledge, tripped.

I thank you for the effort you have put into this and your explanations.