Isolate noise from CNC limit switches - Page 1
Forum section: electronics / projects

author: scott216
author_rank: Regular Contributor
timestamp: May 07, 2015, 11:58:24 pm
content: I'm making a PCB for myShapeoko desktop CNCmachine in order to isolate the Arduino Uno from noise on the limit switch wires and pushbutton wires. The main reason for doing this is electrical noise from the stepper motors and from the router motor can cause the limit switch inputs to trigger. I've got ferrite beads on the limit switch wires and the power cord going to the router. The firmware that's running on the Arduino isGRBL. For the limit switches GRBL can be configured for N.O. or N.C switches. But for the push-buttons the input is configured with internal pull-up resistor on and assumes your switch is N.O. and tied between ground and the input.For my circuit I'm using a Murata NKE0503DC DC-DC converter (Seedata sheet) so I can get an isolated power (3.3v) for the limit switches and pushbuttons. I'm using Vishay optocoupler SFH6732 (seedata sheet) between the limit switches and Arduino Uno.I know on way to reduce noise would be to add caps between ground and the inputs, but I wasn't sure if that made sense in this setup.I'd appreciate any feedback. Attached is my schematic.

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 08, 2015, 12:09:40 am
content: Is the noise coming from ground loops on the low side? Is that why you think you need opto-isolation? (I would think not)Or is the noise coming from such a very high input impedance as the internal pull-ups in the Arduino? (That would be my STRONG suspicion.)It seems to me that it would be an order of magnitude simpler to just put those 47 ohm resistors between +3V3 and the Arduino input pin and let the switches pull down the 47 ohms directly. Or am I missing something here?

author: moffy
author_rank: Super Contributor
timestamp: May 08, 2015, 12:19:25 am
content: Have a similar setup. To reduce noise you can do one or both of the following:1. Twist the signal wire coming from the sensor with a ground wire terminated at the Arduino ground.2. The best and simplest is to just put a capacitor between gnd and the pullup resistor near the Arduino. I have a small breadboard shield attached just for such things.2. Is the simplest and really the best. a 0.01uF capacitor should be plenty. Try this first before more complex solutions. Best of luck.

author: lincoln
author_rank: Regular Contributor
timestamp: May 08, 2015, 12:56:00 am
content: Its all about shielding. What kind of limit switches are you using?1. use ether opto interrupter or hall effect interrupter, Both have drawbacks, both do not have mechanical bounce.2. Use shielded twisted pairs, we used Belden 8451, basically shield is ground, red is voltage to drive the sensor and black is the sensor output.3. be sure you have galvanic isolated you motor drives form the micro controller.4. have your MCU in a shielded box.Motor drives of any complexity are almost all chopper/ current mode drivers.5. drives and drive power should be mount in a metal box. This is your chassy ground6. Shield all the cable leading form the drives to the motor. You can by raw shielding tube and run the wires inside. It looks like giant solder wick. All motor wires need to be shielded from the drives to the motor housing.7. run an extra ground wire from you chassy ground all the way to the motor mount and attache under one of the mounting bolt.8. if you are using connecter in between the motors and drives, keep the wire shield and the motor shield as two separate contacts even though they both terminate in the drive box. the point is to make a low impedance path to ground.9. don't skimp on the wire gauge between motor and drive. You want your drives moving motor not heating wire. If your using nema 23 motor and running more that a foot of cable there is no shame in using 18 AWG, (not related to noise, just a pet peeve)10. now if you have done all that to minimize the amount your radiating and still having problems, as a last resort snap on ferrite over the sensor cables to snub and rf coming into you mcu box.best of luck,

author: rob77
author_rank: Super Contributor
timestamp: May 08, 2015, 07:53:17 am
content: stronger pull-up (smaller pullup resistor value) + capacitor across the switch . if that will not help, then your problem is elsewhere

author: mc
author_rank: Regular Contributor
timestamp: May 08, 2015, 06:17:45 pm
content: Capacitors on a CNC machine switch are generally considered a bodge for an underlying issue. It's certainly not something you'd really want to implement for critical timing switches like homing switches/probes where delays could cause accuracy issues.Provided all your wiring is good, with motor wiring shielded and properly grounded, most noise should be reasonably well controlled. However if you're still getting noise issues, and you still want to opto-isolate things, then I would use a higher voltage for the switch side. Industrial machines use 24V, however 12V is usually more than enough to solve noise problems and if you're making your own board, then it'll be a pretty easy alteration.Going marginally away from the OP, and one for those with more knowledge, but would it be better to have the limit switches pulled high directly from the power source (i.e. at 3.3/5V in this example) when inactive, than it would to be pulling them to ground when inactive?My thinking is it'll take more noise on the wires to lower the 3.3V/5V below the guaranteed high voltage (2.5V for a AVR?), than it would for noise to nudge the voltage above the guaranteed low voltage (0.7V stick in my mind?).I know the 5V would give you a 2.5V noise margin if my memory is correct, however something says I could be a bit off the mark with that assumption.

author: rob77
author_rank: Super Contributor
timestamp: May 08, 2015, 06:46:57 pm
content: Quote from: mc on May 08, 2015, 06:17:45 pmit's the end-stop switch => hitting the end-stop switch means GAME OVER - a CNC machine is NOT supposed to hit the end-stop witch during normal operation.the purpose of the end-stop is to detect faults and avoid jamming the precious linear drives by shutting down the drive.

author: mc
author_rank: Regular Contributor
timestamp: May 08, 2015, 06:51:54 pm
content: Quote from: rob77 on May 08, 2015, 06:46:57 pmPerhaps you overlooked the bit where I said criticaltimingswitches.I never said limit switches weren't critical, it's just a few milliseconds delay isn't going to make much difference if you hit the a limit.

author: rob77
author_rank: Super Contributor
timestamp: May 08, 2015, 06:55:39 pm
content: Quote from: mc on May 08, 2015, 06:51:54 pmsorry, you're right. my apologies.but when reading about switches in a context of a CNC - i'm always thinking about the end-stop switches... because i never seen a mechanical switch which would be critical to timing

author: mc
author_rank: Regular Contributor
timestamp: May 08, 2015, 07:09:36 pm
content: Quote from: rob77 on May 08, 2015, 06:55:39 pmApology accepted.But who said anything about mechanical switchesMechanical switches can be used for homing with pretty good repeatability, usually within a thou or two if you use good quality switches and mount them sensibly, which is good enough for the majority of machines. For most home machines, I wouldn't think you'd gain much by using opto sensors, especially given they're far more prone to dust/dirt/shavings/swarf, unless you manage to enclose them well.Personally, I've now got the luxury of a mix of mechanical and opto switches, combined with encoder indexing for homing purposes on machines that require accurate homing, but my old lathe used an opto slot sensor on the X-axis and a mechanical microswitch on the Z-axis and homing accuracy was always well within a thou on both axis. Just had to remember and clear any stringy bits of swarf out the slot sensor firstAnyway, all this discussion of switches isn't answering my thoughts about high/low switching!

author: moffy
author_rank: Super Contributor
timestamp: May 08, 2015, 11:41:25 pm
content: Quote from: rob77 on May 08, 2015, 06:46:57 pmIf the switch is Normally Open mechanical limit switch and the wire resistance is reasonably low, below 100 ohms, and the cap 0.01uF, you will get less than a 1 to 2us delay in closing, which is the critical action to respond to. That is plenty fast enough. The opening delay will be slower, granted, but you are not normally too concerned about that.

author: scott216
author_rank: Regular Contributor
timestamp: May 09, 2015, 12:29:46 am
content: Wow, there's a lot of discussion here. I'll try to answer some of the questions about my setup.QuoteThe limit switches are also the homing switches. My Shapeoko doesn't support having separate switches. I'm using good mechanical switches from McMaster (P/N 7779K22). I'm not worried about mechanical bounce. The firmware has some debouncing in it. Plus, I don't see how bounce would cause a problem. The mechanical switches seem to be working very well.QuoteWires to stepper motors are shielded 18 gauge. Wires to limit switches are shielded but not twisted.QuoteStepper driver and Uno are not in a shielded box. This would require a lot of rewiring.QuoteI think it's isolated How would I check, just use a multimeter and check the resistance between the motor and ground on the microcontroller?QuoteI've already got ferrite beads on limit switch wires and router power cable.QuoteI'm using NEMA 17 motors with 18 gauge wireQuoteI don't know. Is there a way to figure it out?QuoteThat's a good idea. I am making my own board. I'm actually making it on the desktop CNC in question.QuoteI could probably get away with something simpler like this. But I kind of like going overkill and I feel I learn more.A big part of this is trying to get a better understanding of noise issues on my CNC. I'd like to know more than one way to deal with it and understand where it comes from and the different techniques that can be used. All these posts have been very helpful.Also, I while ago I did put a scope on the limit switch wires and there was a lot of ringing. It actually got worse when I grounded the shield on the stepper motor wires. So I've left the stepper motor shield floating. The limit switch shields are all tied together near the microcontroller and grounded.

author: moffy
author_rank: Super Contributor
timestamp: May 09, 2015, 01:10:47 am
content: QuoteThat sounds like some sort of a grounding issue, where stepper motor return currents are flowing where they shouldn't. If you are using twin shielded cable for your switches then only connect the shield at one end, near the Arduino, not at both ends.

author: scott216
author_rank: Regular Contributor
timestamp: May 09, 2015, 01:30:35 am
content: Quote from: moffy on May 09, 2015, 01:10:47 amThat's how I have the shields connected - only at the Arduino side.

author: moffy
author_rank: Super Contributor
timestamp: May 09, 2015, 01:34:13 am
content: That's good practice. Where were you grounding the shields of the stepper motors to?

author: scott216
author_rank: Regular Contributor
timestamp: May 09, 2015, 01:39:39 am
content: Quote from: moffy on May 09, 2015, 01:34:13 amWhen I grounded the shields on the steppers the ringing was worse, so I left them floating.There's really no chassis ground on the Shapeoko. The power supply is similar to what you see for laptops.

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 09, 2015, 04:19:35 am
content: FLOATING grounds are worse than no grounds at all!When you say "grounded the shields on the steppers" does that mean you connected the shields at the MOTOR END?That is actually the wrong end. Perhaps you need to ESTABLISH a central "star ground" point where everything meets.Grounding and shielding is a "gray art" at best. A great deal of it is trial-and-error.

author: scott216
author_rank: Regular Contributor
timestamp: May 09, 2015, 03:16:36 pm
content: Quote from: Richard Crowley on May 09, 2015, 04:19:35 amNo, I grounded the shields to the microcontroller ground, not the motor end.I think part of the problem is I don't really have a good chassis ground anywhere. The Shapeoko just usesthis power supply; which is the kind of p/s you'd get with a laptop and it just has 24 volts coming out of it. I'd probably be better off with something likethis power supply. Which has a nice metal case which I assume is connected to earth ground on my mains. Then I could connect all my shields to this chassis ground. What do you think?

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 09, 2015, 05:47:07 pm
content: But where does that "line-lump" power supply plug in? I would establish that power input connector as the "star-ground" point where everything else references. Just having a power supply with a metal enclosure is not likely to solve the problem by itself.I would also run two conductor shielded wire out to each switch. The two inner conductors would connect to the switch contacts, and the shield would connect back to ground at the controller board. And if one side of the switch connects to ground, it would be back at the controller board, never out at the far end where the switch is.

author: Kalvin
author_rank: Super Contributor
timestamp: May 09, 2015, 06:32:34 pm
content: How about using current-driven control signal: Place a capacitor between the MCU input and the ground. Create a 2mA constant current source and feed it through the limit switch to the input capacitor / input pin. When the switch is closed, the capacitor will be charged by the constant current. Create 1mA constant current sink and place it in parallel with the capacitor in order to discharge the capacitor when the limit switch opens again. Should be quite insensitive to the voltage coupled noise. Of course, you can use an opto-coupler in current driven mode, but that would be way too easy.

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 09, 2015, 06:41:18 pm
content: A simple circuit using a 47 ohm pull-up resistor to 5V should present such a low impedance that should make it immune to any kind of induced noise possible from such a relatively low-power system. 47 ohms will firmly pull-up the input pin to VCC and prevent induced noise from dragging the pin below the threshold voltage. And a simple micro-switch can easily pull 5V through 47 ohms down to near-zero, well below the threshold voltage. Dunno why it has to be any more complicated than that?

author: scott216
author_rank: Regular Contributor
timestamp: May 09, 2015, 07:30:16 pm
content: Quote from: Richard Crowley on May 09, 2015, 05:47:07 pmThis is how the limit switches are currently setup.

author: scott216
author_rank: Regular Contributor
timestamp: May 09, 2015, 07:33:02 pm
content: Quote from: Richard Crowley on May 09, 2015, 06:41:18 pmI'll give that a try. I might have to find another project to use my opto-couplers on

author: chefkoch84
author_rank: Contributor
timestamp: May 18, 2015, 05:15:00 pm
content: I had similar issues on a 3D printer (reprap). Back then I figured (at least thought) that the stepper motor wires croostalk to the signal levels.My solution was to 3-wire all the limit switches:Code:5V --\-- switch --> digital inputGND--By this solution you need 3 wires for each switch but in every state you have a very defined level.Depending on your situation (type of switches ... wires ... ect. ) this could also be a good alternative.

author: cncjerry
author_rank: Unknown
timestamp: May 18, 2015, 07:20:08 pm
content: Before you spend a lot of time on the switches, make sure your head/tail stock motors are plugged into separate outlets and grounds. Also, try lifting the ground on either the headstock motors or the electronics if it is safe. I had the same problem and the more controls, sensors and switches I added the worse it became. I tried ferrites (e.g. clamps, toroids, etc) as well as shielded cable with conductive HVAC tape. Each that I added reduced the noise BUT lifting the ground on my electronics and running the power from a separate breaker fixed it all. I then sequentially removed each of the ferrites and other shielding and the problem was gone. I ultimately used shielded cables for all with one end only grounded; a separate ground to a cold water pipe for the machine itself; separate breakers and outlets for the headstocks and electronics; and sprinkled clamp on ferrites where they fit.All this was on two stepper systems, a lathe and a small engraving mill, both had the same problem using different drivers. My larger servo system which is CL never had problems but that was 220V motors with 110V electronics so that had more isolation from day one.You should also have an opto isolated BOB on the computer if using parallel port drive. I avoid USB though it is silly in this day but the lag for E-stop was too long for me.Jerry

author: lincoln
author_rank: Regular Contributor
timestamp: May 19, 2015, 06:02:31 am
content: Quote from: scott216 on May 09, 2015, 12:29:46 amOk, looking through the rest of the thread this is not your biggest issue.QuoteOk good, next step is establishing a "star point" ground. more on this later.Quotewell then focus on shielding the motors drives first but its likely to require both.Quoteyour motor drive(s) own power supply and a separate power supply for the MCU. The MCU sends pulses to the drivers via an opto isolators ect. Some motor drives, ie geko drives, have optos built in. you should be able to measure a high resistance between your motor supply black wire and black wire on you mcu.There is a difference between shield and ground. the shielding of wires and the stepper motors are an extension of the metal chassy of your motor drive which is tied to AC safety ground. (I know Its not yet in a metal box but It really should be. ) As Richard Crowley you need to pick a point that all your shields tie to.I may have missed it but what motor drives are you using? what kind of power supply decoupling have you implemented? What is the maximum step rate you are trying to drive?Quote

author: scott216
author_rank: Regular Contributor
timestamp: May 19, 2015, 07:41:40 pm
content: The stepper motors are powered by a laptop-like power supply. Their is a ground pin on the mains side of the power supply, but on the DC side it's just 0 and +24 volts. I haven't checked to see if the 0v is connected to mains ground. The MCU (Arduino UNO) is power by my laptop via USB cable. The stepper driver board (gshield v5) plugs into the Arduino UNO, so they have a common ground but separate power sources.See the attached pictures, in picture #1 you can see my limit switch input board. This board plugs into the Arduino with is underneath it. Then the gshield plugs into my input board, see picture #2.The input board I made is a new one and seems to work pretty well. I've just got some bypass caps and pull-up resistors to reduce the noise. Even though this setup seems to work well, I do want to better understand the things I can do to reduce noise.

author: cncjerry
author_rank: Unknown
timestamp: May 20, 2015, 04:40:14 am
content: Is your noise worse with the headstock motor running at high speed? What I had found was that the more sensors you add, the more 'antenna' you create. If that antenna has a way to ground, it will come back into your power supply no matter how much filtering you have. There are tricks using a single resistor and capacitor to make filters if the noise is a specific frequency. Though you think it is the limit switches it could very well be just the straw that broke the camels back and in some ways you are lucky to find it now before you ruin a part you have invested a lot of time in as I had.Noise shows up on stepper systems as extra or missing steps. The best way to test it is with a dial indicator that your run up to using a program to move a single axis back and forth. The reading on the indicator even if you move off it (outside its travel limits) should be consistent. If it isn't you are missing or gaining steps. Try it with the headstock motor running and without. Turn on your lighting and off (fluorescents?). Run the axis back and forth 10, 20 times keeping track of backlash if necessary. Once you get a good test for the noise, try my idea of lifting the grounds at the wall. Also, make sure you only ground shields at one end. If you have the machine attached to a cold water pipe, ground the shield at that end. Be careful as a reversed neutral/hot could ruin equipment.The most common problem with stepper systems isn't missed or lost steps due to load or acceleration, in my findings it is noise getting into the stepper controllers.The guy at Gecko had really good ways to eliminate noise and has always been helpful. Get the best practice wiring and capacitor bypass drawings off the web.Lastly, I spent 10's of hours on this problem with my sherline based, zero backlash, engraving mill and small lathe. I got lucky on the ground. On my larger systems I run 1100oz/in servos at up to 300ipm though I reduced them recently because the acceleration was shaking the floor. Servo systems accelerate in a quarter turn of the drive wheel. The table on the larger mill weighs about 175 lbs, the headstock about 250lbs and at high acceleration that mass really gets going. The point here is that if you can get to a servo system many of your noise issues will go away.