End Stop / Limit Switch Problems

137K11667

Intro: End Stop / Limit Switch Problems

UPDATE: There are now several easier alternatives than the G-shield and CNC shield which have built in filters amongst other features.

a) GRBL AIO (Arduino + Drivers + Filters + more on one board)

b) GRBL Breakout (Needs Carrier Boards + Arduino)

c) CNC Shield (Needs Carrier Boards + Arduino, + Make sure your buying latest version or no filters)

Limits switches or 'end stops' as they are known to the 3D printing community can be troublesome for Hobby CNC and 3D print setups. Many forums have discussion on how to stop the false triggers and most of it doesn't seem to work 100%.

You need 100% accurate limit sensing, 1 false limit trigger can ruin your whole print or CNC job.

Much discussion, on the Shapeoko & Shapeoko2 side, falls around using low value pull up resistors or special shielded cables and cable routing paths.. but its all difficult, sometimes expensive and unsightly and usually not a perfect solution.

This problem seems to plague everyone who tries to put limit switches on. There are many recommendations about adding resistors and shielding cables and re running limit switch wires away from power wires etc but I feel its all quite unnecessary.

When ever you have interference, you have options -

1) Chase the interference and fix / shield from it

2) Stick a filter in place to negate the noise.

Read on to see how easy option 2 is to get perfect end stop awareness for your Arduino based CNC machines & Printers

STEP 1: Behind the Issue

Wether you are using a reprap style printer or a cnc router or other cnc tool like the open source shapeoko(2)

and ox, there is allot of interference in the device due to all the equipment and power sources in the mix.

Its too hard to stop 4 steppers, a spindle, a speed controller, and a power supply + any other equipment near by from interfering with delicate 5V ttl logic, even with low value pull up resistors and expensive shielded cables. Not to mention the pain of rewiring the device!

Im not sure about the constant advice to add low value pull up resistors...

Adding lower val pull up resistors just creates heat and wastes power. When ever your limit switch remains depressed, like after a home command, your resistor will be fighting to bring the pin voltage back up to 5 while the limit switch holds it down at 0v. waste & heat.

All you need to do for 100% perfect limit switch operation with Zero false triggers is: 3 small capacitors.

For each capacitor, connect the negative leg to the ground rail, and the positive to one of the limit sense pins on the controller. On an arduino running GRBL these are pins 9,10, &11.

For Shapeokos I have found that a .47uf is perfect in all instances.

One capacitor for each pin. Then as usual your limit switch wires, one wire from each switch to ground and the other to one of the pins 9,10, or 11 (grbl v.08). Same as all the diagrams everywhere, don't need add any of the resistors or other components from these diagrams. These .47uf value caps will ensure that the interference form your power supplies, steppers, spindle and spindle controllers cant affect the 9,10,11 pin voltages quickly or enough to bring the pins voltage down to the logic low threshold which is where your false positive limit error comes from.

The arduinos internal pull up resistors will constantly be charging the cap and holding the pins high which is why you don't need to add more. (this is not a waste of power / creator of heat, capacitors average consumption not add) The internal pull ups will ensure that the cap cant draw to much current on initial charge from the atmega pins so there is no safety issue for the arduino.

The cap works as it should to filter the line noise, not to (big) much so that the limit switch cannot pull the pin to ground quickly, and not to little that there can be any confusion as to if the shapeoko/printer has hit a limit or not.

Its pretty much foolproof, Ive tested it on 5 seperate shapeoko2's, including with bigger nema 23's, quiet cuts spindles, variable speed drives... There is not need to concern how to route the cabling, no need to worry about shielded cabling, no need to add any resistors anywhere. No need to muck with the grbl debounce timing constant. Just put in 3 caps and forget.

To make it clean, get a blank arduino uno prototyping board and install the caps and limit switch inputs to that, then insert that between the arduino and the gshield or what ever stepper shield you are using. As you first power up the board, the capacitors will pull down the limit switch pins for a tiny bit of a second as they charge, so the board will come online in a 'Limit switch error' state, and you have to soft reset and $x to clear it as usual, its actually nice for the controller to come online disabled though so its a cool side effect.

If you want to clean the line best for your particular setup, get an oscilloscope and probe your limit pins while running all the axis and dremel or spindle, and try a bunch of different caps, small as possible going bigger until you get no false limits, then maybe choose the next size up from there to be safe. If you dont have a scope, just use the .47uf or experiment.

Another handy tip, if your using the omron lever style limit switches, set the pull off constants in grbl to about 5mm so that when your homing finishes it pulls back off the limits when done so that its not bending the levers so much, otherwise you constantly have to re bend them back out. Also, I believe that these are the style of switch to use, they are not as convenient for mounting as a momentary push switch as shown in the shapeoko wiki but they are more accurate, they have a threshold from which they literally JUMP from open to closed with a spring effect, it means that the actual point of limit should be more repeatable than using an ordinary momentary push button which bounce more. Also, the momentary switches bottom out when they connect, meaning that if your axis is moving very quickly, you might be able to smash the switch or crash the carriage before the limit is triggered - with the levered switches you get yourself a few extra millimeters before it goes crunch!

Next page some diagrams of the switch filter board

STEP 2: Solve the Issue for GRBL/Shapeoko/Xcarve/Ox...

Options:

1) Get a controller with Limit Switch Filters such as

  • GRBL AIO (Arduino + Drivers + Filters + more on one board)
  • GRBL Breakout (Needs Carrier Boards + Arduino)
  • CNC Shield (Needs Carrier Boards + Arduino, + Make sure your buying latest version or no filters)

or

2) Make an intermediary filter board

For Grbl systems, you can use a protoshield like the one here or one of many others found online.

This will slip nicely between your arduino and controller wether its a gshield or my favourite the CNCshield.

See photos 1-3 for the component layout.

  • Careful these electrolytic .47uf capacitors are polarised, positive to the limit wire and arduino pin and negative to ground

Photos 4-6 show the soldering on the back,

  • note the pins from the 3 orange wires are bent over to meet the pins from the socket two holes over.

Photos 7-9 show the finished filter board sandwiched between the controller and arduino uno.

  • If you want the end result instead of making your own, I have a limited number available already made: here.

Then you are left with 4 wires.

1 is ground, its green in my photos. The other 3 are you XY&Z limits.

These are connected to one side of your normally open limit switch. The other terminal of the limit switch is connected to ground. So when the limit switch is depressed, it will short the circuit to ground and the controller will know its at the ...limit.

Please note, grbl v.09 has moved one of the limit switch pins!! https://github.com/grbl/grbl/wiki/Connecting-Grbl

Also note: I have been pulled up on my resistance to adding resistors: http://www.shapeoko.com/forum/viewtopic.php?f=4&t=...

STEP 3: Testing Your Switches

Some tips to help test without breaking anything!

Setup Grbl Params:

$20=0 (soft limits, bool)

$21=1 (hard limits, bool)

$22=1 (homing cycle, bool)

$130=XXX (x max travel, mm) Make YYY something larger than the machines travel

$131=790.000 (y max travel, mm)Make XXX something larger than the machines travel

$132=110.000 (z max travel, mm)Make XXX something larger than the machines travel

You Can test the limit switches by setting $10=16 (status report mask:00010000)

Then turning on Verbose logging (checkbox) on UGS.

You will see a stream of numbers like "[verbose]"

When you hit the Z switch (manually with your finger) it should change to "[verbose]"

When you hit the Y switch (manually with your finger) it should change to "[verbose]"

When you hit the X switch (manually with your finger) it should change to "[verbose]"

and off course if you have enough hands to push all switches it will show "[verbose]"

So of these 3 numbers, the first corresponds to Z, next Y and third X (seems a bit backwards so be careful) If you find that any of the switches are showing a different differently on the output then you need to swap some of the leads around so that it shows correctly.

Once you are done with this you can set the $10 back to 3 (you must do this or things dont work correctly) and at this point try a homing cycle - its the button labelled $H

Might be a good idea to first turn down the homing speeds:

$24=25.000 (homing feed, mm/min)

$25=250.000 (homing seek, mm/min)

Once you have validated the homing is all working in the right way you can turn them back up a bit.

Its nice to have them turned down while testing so you have time to hit the Estop if things are ging wrong, like for example the machine starts homing in the wrong direction!

You need it to home towards the limit switches. If its not going in the right direction you will need to mess with the $23=0 (homing dir invert mask:00000000) parameter. More info on that here: Homing Directions

55 Comments

Hi Ben,
I have build the Workbee CNC machine using the GBRL shield v3.0 as the controller. but i'm struggling with the limit switch noise problem.
I've quickly put together an image, can you tell me if this is the right way to connect the capacitors?
Thnx GJ
Close enough butdont charge cap through the switch, like this:
Hi there, been looking ot set up my limit switches and keep coming back to this instructable (it's really good!). To be clear, are you saying that your diagram above is the correct way to add a cap to a CNC shield?
Ben,
Thank you so much for your quick reply.
i'll try it tomorrow.
Hi, how about grbl v1.1? I did this noise filter and it works perfectly. Problem I have (I suppose) is connected with TTL. TTL is also on pin 11. 47uF capacitor could probably mess things up. Shouldn't it be pins number 9,10,12 in grbl 1.1? Thanks in advance.
Thank you so much for this post. You are 100% correct. This solved my false signal problems. I salvaged some .47uf caps from an old circuit board and used them on an Arduino proto board to filter my homing / limit stops, hold, probe, etc. I simply plugged the proto board into my Arduino board and problems solved! No resisters were used. I'm running simple unshielded wire.
Installed a new CNC shield V3 onto a new Arduino Uno and verified it was installed correctly . I have 12 volts (verified Pos and Neg installed correctly) to the the CNC shield power connector but can not get a voltage reading to the DRV8825 drivers (tested drivers on another board and they worked fine) and the LED's on the Arduino are not lit up.
1) Does the CNC shield power the Arduino and should the LED be lit up or does the Arduino need a seperate power source? (LED's light up when the Arduino powered directly)
2) Any thoughts on why I can not get a Vref voltage reading on the drivers when installed correctly on the CNC shield?
The drivers need two power supplies, 12V or greater for the motor power and 5V for the drivers logic circuits.
The arduino is powered by the 5V coming down your usb cable. You wont get the drivers to fire up until you connect the USB as they are also powered by the 5V from the arduino.

Ben, Thank you so much for this article. In the sea of confusion surrounding limit switches your article helped me so much. I purchased an x-controller with my x-carve and I have found it difficult to get the information I need about wiring it up with 5 limit switches (2X 2Y 1Z) - I wish I had known about and purchased the 3dtek controller as the basic instructions online tell you everything that I have been trying to find out unsuccessfully about the xcontroller.

I have purchased three .47 uf capacitors and I would like to wire up my limit switches as Normally Closed but I am still confused as to whether I need to add anything to achieve this or whether I can just wire my switches directly into the x-controller. I know it has built in filters and I have attached the shematic. If somebody could please let me know what, if anything, I need to do to achieve this, or whether I would be better off with normally open and the 3 capacitors (or not) I would be eternally grateful. This is the final step in getting my CNC up and running at last.

Hi

Regarding Normally Open (NO) vs Normally Closed (NC), see the limit switch section on this page: https://3dtek.xyz/pages/grblaio

NC is a more safe practice - I have no idea why the GRBL/Shapeoko/XCarve standard is to use NO. Or why they home to the front of the machine, or why they cut in the positive space. I guess they are trying to simplify things?

If wiring NC, you need the switches in series otherwise if in parallel they would both need to be tripped at once which won't happen as they are likely on opposite sides of the machine;) Wiring in parallel is for NO only.

Your limit switches should be marked C for common, NO, & NC. Use common regardless and NO or NC depending on your preferred method.

It's most simple to wire in series in the NO config and forget the filter caps, however, there is about a 100% chance that you will have false limit errors. So chuck a .47uf to 5V on each port, and your resistors too, not that I bother.

I don't see a 5V pin on the X Controllers green plug so I guess you have to do this inside the box?

Oops - It should read

It's most simple to wire in PARALLEL in the NO config and forget the filter caps,

Hi Ben, Thanks so much for your reply.

The less than helpful answer I got from Inventables was basically "sorry, we don't support more than 3 switches - read about limit switches on Github"!

I have a wiring diagram for NC switches and thats the way I want to go but my electronics knowledge is nil beyond following basic schematics so I am confused when you say chuck a .47uf to 5v on each port. Sorry to be thick but I just dont know what to connect to where? If you could explain I would be very grateful.

I know where the 5V is inside the box so I can put in a 5v terminal on the back panel and wire it up without any problem.

Thank you so much for your help,

Regards, Phil

The Previous long winded reply seems to have been lost so pasting it in again:

Not having an X Controller I cant look into detail and make you a schematic to follow. But I will outline the theory and fix in as simple words as possible and you should be able to work it out from this. – Let me know if not so.

Truth is you are likely to have less noise interference with NC, however, NO is the simpler method for wiring and the one that I have tested well and know will be fixed by the .47 Cap.

Ok, so your second Y & X switches (if going Normally Open) connect exactly the same way as the first switch which I am sure is well documented in the X Controller instructions. The machine doesn't know or care that there are two or that one of them is at each end of the machine, grbl just gets a notification for a limit on that axis and stops. Just follow the same wiring setup for the first switch with the second switch. - THIS IS FOR NO ONLY!

One side of each switch goes to Gnd - the other to the appropriate port on the X Controller - looks like pins 10,9, & 7 on your diagram. There is 5V already present on these lines. These are pulled up internally on the microcontroller. So they are not a 5V source, they are a weak signal pulled-up to 5V by a resistor - not to be confused with actual 5V source!

If you want to add some filtering, you can put a 0.47 cap with positive side (if polarised) to Pin 7 or 10 or 9, the negative side to GND. If you want to add some extra pull-up power to hold the pin at 5v with a bit more strength, and to help charge the capacitor quicker between limit switch presses, you can also add a resistor between this line and 5V (if you can find it on your X Controller). You don't need to put two caps and resistors because your using 2 switches as both switches are acting on the one signal line/processor port.

You also don’t need two sets of wires (antennas) running all the way from the machine to the controller. Just run a wire from GND of one switch to GND of the other, and NO from one switch to NO of the other. These two switches on an X Carve are located close by each other ad move together as on the same moving carriage so short wires are easily added between the two.

Here is a simple description of how it is all working. (With NO Mode)

The X Controller is just an Arduino at heart, and Arduino is Just an Atmel 328P microcontroller. A firmware known as GRBL is loaded onto this 328P micro controller. In this way it’s almost the same as what we have done on the AIO. Except that we seem to use a larger cap on filters on all the IO lines

Internally the X Controllers software (GRBL) instructs the 328P to pull up the limit switch lines/pins to 5V. It does this with relatively weak pull-up resistors built into the microcontroller - around 20Kohm value from memory. It does this to set a default known 'all good’ state for the limit switch pins. (These are pins 9,10 & 12 in Arduino Talk)

When you hit a limit switch, the limit switch connects/shorts this pin to ground causing the voltage on this pin to rapidly drop from High State (5V) to Low State (0V/GND). This is what GRBL is watching for.

Important to note - If the pins were pulled up to 5V directly and not through a resistor, closing a switch would instead short out the whole 5V power source to ground and not just the reference voltage on this pin! This would be bad - like fry the USB port on your computer kind of bad. Instead, we are acting on a weak 5V reference voltage, which is easily overpowered and bought down to ground. It’s still technically a short on the 5V line, but it’s shorted through the pull-up resistors which make sure only a small amount of current can flow and so its only a very small short consuming a very small amount of power and not melting anything like your USB port, power supply, switches, wires, tracks on the PCB etc.

The GRBL software is constantly watching these pin voltages and when it sees one of the limit switch pins suddenly hit 0V it thinks - ohh crap - something’s wrong... stop everything. This is if you have hard limits enabled ($21=1). This is true for all occasions except for during a homing cycle - which is obviously the only time that hitting a limit switch is an expected and planned event.

Another important note is the 0V vs 5V logic is not really the truth. There are thresholds within which we assume High and Low. Any voltage below 0.8V we assume is a low signal, any voltage above 2V is a high signal - this is important later. Not sure exactly what happens in between, I guess the previous state is valid until the voltage has crossed back under .8 or over 2v at which time if that state is different from last an event is raised?

EMI noise exists on and around your system. This noise is picked up by your limit switch lines, which are very effective antennas to collect the noise and direct it into the micro controller's pins. In fact, its picked up by every line going back into your controller including estop, probe, feed hold, resume etc. However, in your case, these other lines apart from the probe have very short wires between the controller and the buttons/switches, they are all also internal to the alloy box which provides some shielding. And so while I don't expect you will have issues on these lines, if you did exactly the same solutions being discussed would fix it.

So your long limit switch wires are nice long antennas to pick up any noise. They are inconveniently running side by side with some nice long transmitters - your stepper motor wires.

The currents running in your stepper wires can be large, and it’s switching on and off quickly and at a varying frequency - it's an ideal noise generator. Other items in the vicinity such as power tools, sump pumps, fluorescent lights etc. can all also generate EMI noise for your wires to collect and ruin your day.

A really common one is your shop vac! Damn another unfortunate thing cause you need it. A good method if the shop vac is causing errors is simply turn it on before your machine as its generally the start up that causes the issue. Or roll it to the other side of the room and start it then roll it back to the machine. Or use a vac with a soft start or variable power – most shop vacs don’t have this feature.

Interesting note: Your Makita/Dewalt/ Other hand tool spindles can be a source of the noise. Now or maybe not till later. These are brushed universal motors and so they create a lot of noise both audible noise and also EMI. As the brushes ware through use, these spindles get louder and louder on the EMI front and so you may notice limit switch issues creep back into your system in 6 months from now and wonder why after 6 months of beautiful work its happening again? In this case look to replacing brushes in the router!

So regardless where the noise is coming from, it's getting into your limit switch lines and swinging the voltage around enough that it drops below the low-level logic threshold of 0.8V at which point the GRBL software thinks you have hit a limit switch.

Interesting note: The noise is usually present at a frequency and so while you may not realise, its most likely not just triggering a single limit switch error but more likely hundreds or thousands of them per second!

This is why we need to filter the limit switch lines. There are two ways of doing this, which are physical filters and debounce management. Debounce management is already built into GRBL for homing cycles however not for straight up limit switch functionality. I guess this is because it's not that effective. In short debounce is a software method, which looks at the signal over a short period of time to make sure its stable before acting on any change in state.

We look to physical filters, which attempt to remove the noise before it gets into the controller so that we don’t have to try and manage it with software. In come the Caps and Resistors.

By putting a capacitor between ground and the limit switch line, we are giving it a bit of a buffer charge and requiring a much stronger pull down to the ground in order to fully discharge the capacitor below the 0.8 V threshold that will be picked up as a logic low. IE requiring a strong pull-down like being shorted to ground by you’re limit switch being pressed. There is hopefully enough buffer in the cap to ensure the relatively weak EMI noise currents induced into your limit lines cant pull it down hard enough to cause it to drop below the 0.8V threshold.

Placement, it should be done as close to the controller as possible.

The size of the capacitor is important. It needs to be big enough to provide enough filtering and suck up enough noise. But not so big that it holds huge amounts of power that when shorted to ground will go bang or scum up the contacts of your switches by running too much current through them.

It also importantly needs to be small enough that the pull-up resistors can charge it quickly! When you release a limit switch in NO mode (or press the limit switch in NC mode) it removes the short to ground and allows the capacitor to recharge. It recharges through the weak pull-up to 5v provided by the pull-up resistor and so depending on the resistor used, and the size of the cap, it will recover to the >2V high level in some amount of time.

This recovery time becomes very important to homing cycles. The homing cycle hits a limit switch, and then backs off before going into hit it again. It backs off a defined distance (GRBLS $27 Param) at a defined speed (GRBLS $24 Param). The capacitor and limit switch line must recover to its >2V high logic level during this time or GRBL will get confused. Wondering how or why it has moved away from the switch (removing the short to ground) but not seen the signal go back high?

As mentioned the homing cycle has a debounce parameter. You cannot fix a too slow recharge time with debouncing logic as it’s aimed at solving the opposite problem. Debouncing solves reading a signal jumping up and down too quickly not one that’s taking too long to come back up.

We have found that 0.47uf is a perfect value, as it is not so big holding so much power that it ruins switches or itself when shorted to ground. Also not so big that it cannot be recharged quickly without adding extra pull-ups to help charge it. It’s also not so small that moderate levels of noise can overpower it and cause trouble.

Note: If you do decide to add extra pull-ups to help charge the cap, when doing your calculations remember that the resistor your adding is in addition to the pull-up resistor inside the microcontroller. So your not putting in a pull-up resistor, your adding a second pull-up resistor in parallel with the one that’s already there and this should be factored into your calculations.

The other resistor that’s found in circuits discussing limit errors the one in series with the cap that forms part of a real RC filter. The filter I have discussed to this point is simply a cap, which is not technically the way it should be done. A real RC filter is a Cap and a Resistor – hence ‘RC’. The resistor in this circuit controls the charge and discharge rate of the cap as all current is routed through this resistor. More reading for you here: https://en.wikipedia.org/wiki/RC_circuit

The larger the cap you use the more important it is to have a resistor managing the flow of current too or from it to ensure you don’t damage the rest of the system or the cap. We have been using a simple 0.47 cap for years without resistor in series and without issue regardless of the fact that it’s technically not the right way to do it.

We are expecting 5V on these lines, but use a 16V or 25V cap for reasons you can google – capacitor de rating.

So long story short - you just need to find a GND pin – seems to be marked as pin 3 on that IDE connector in the schematic you sent, and put a cap from there to Z Lim, another to Y Lim and lastly one to Z lim. Observe polarity by ensuring the GND side of the cap is going to the GND pin.

Once successful if you feel the need, go back and use some of this theory to change over to NC, or move on to making sawdust instead!

Best Of Luck

Ben, i can't believe Ithat you took the time to write such a comprehensive and detailed explanation! It took a few read throughs but i understood it all and now feel much more confident about limit switches. Your level of help is exceptional and i cant tell you how much i appreciate it. I really had hit a wall and felt ready to walk away from the machine but i am now looking forward to getting it all running. Have a great weekend and many, many thanks.

Kindest regards,

Phil

Is this what i need to achieve? Sorry for the very basic drawing!

Hi

Almost - NC switch wiring looks good - but Cap wiring needs changing.

Excuse the even worse edited image.

One side of the Cap to ground as I have shown edited on X circuit.

The other side of the cap to pin X limit line which as noted on the image is the 5V side.

You don't need to find a 5V source to connect anything unless you are looking to add an extra pull-up resistor in which case you can see I have added this to your X circuit.

I have annotated only the X, but the same applys for Y & Z

There are some more also ugly but useful schematic images here: https://github.com/gnea/grbl/wiki/Wiring-Limit-Switches

Ben, You are an absolute star!

Thank you so much for your help. I really appreciate you taking the time to help me out. Have a great day.

Regards, Phil

More Comments