Normally Closed Limit Switches 2

Discussion about the arduino based g-code interpreter, grbl
faulty
Posts: 3
Joined: Wed Nov 26, 2014 2:59 am

Normally Closed Limit Switches 2

Post by faulty » Sun Jan 11, 2015 5:37 am

I'm not sure if I should high jack the earlier thread http://www.shapeoko.com/forum/viewtopic.php?f=3&t=3953

I've chose to do a normally closed setup for my limit switches as well, for the reason for safety, any broken wire should also halt the machine. Much like real world alarm contact or fire alarm trigger. Based on the note from https://github.com/grbl/grbl/wiki/Configuring-Grbl-v0.9
NOTE: If you invert your limit pins, you will need an external pull-down resistor wired in to all of the limit pins to prevent overloading the pins with current and frying them.
I really don't see the purpose of a pull down resistor here. The limit pins are grounded in normal state, and the internal pull up will bring it to "1" when the switches activate, having a pull down will essentially becomes a voltage divider and resulting in 1/2 VCC if the resistor value matches. Unless the note is referring to wiring the common to VCC which means no invert is required for normally closed setup, unless it's a normally open setup.

If someone can help confirm that, then we should correct the note to avoid future confusion.

Btw, I'm actually PIC guy, so no idea if prolong grounding of a pulled-up pin of AVR will cause any issues or permanent damage to the MCU? I can't seems to find relevant warning on this.

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Normally Closed Limit Switches 2

Post by cvoinescu » Sun Jan 11, 2015 5:12 pm

You are correct, that comment is wrong, or at least confused. You don't need a pull-down -- quite the opposite. The code turns off the internal pull-ups when the limit switch logic is inverted (which I think is the wrong thing to do), so you'll need external pull-ups. Or patch the code to always turn the pull-ups on (in limits.c, in limits_init(), delete lines 44-46 and 48, and the second sentence in the comment in line 47). Wire the switches to connect the pin to GND, and, if you have two switches on each axis, connect them series.

The comment on the wiki is sort of correct in that a CMOS input without either a pull-up or a pull-down and no connection otherwise (e.g. an open switch) will be in an indeterminate state, and the input buffer will draw a lot of current and possibly destroy itself. However, all ATMega328P inputs have Schmitt triggers, so it's less of a concern, although leaving pins floating will increase current consumption. The simplest solution is to leave the internal pull-ups on.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

chamnit
Posts: 376
Joined: Tue Aug 12, 2014 2:16 pm
Location: Albuquerque NM, USA
Contact:

Re: Normally Closed Limit Switches 2

Post by chamnit » Sun Jan 11, 2015 7:49 pm

Disclaimer: The NC limit feature was half-baked from the start, as I'm not an electrical engineer. I didn't hear anything about it until a couple of months ago, assuming my short web search on NC switches and its implementation was correct.

It wasn't until a couple of months ago a user mentioned that it is wrong in its implementation. There was some back and forth and I've heard from multiple people differing opinions on what's correct. Some say the internal pull-ups should be enabled, some said that it doesn't matter due to the high resistances of it. Another stated that it's impossible to cover all scenarios and Grbl's pin config should just be as generic as possible and let the user decide how. I'm unsure who is right and who is wrong. What is right and what is wrong.

In short, I'd love a thorough explanation on electrical properties of NC switches and how to ensure that Grbl is generic as possible, especially considering that Grbl won't always be on an Arduino Uno but could be on various ARMs.

EDIT: And what the proper pin state should be for each when triggered.

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Normally Closed Limit Switches 2

Post by cvoinescu » Sun Jan 11, 2015 9:04 pm

TL;DR version: ideally, inverting and the pull-ups should be controlled separately; that would cover all cases. Short of that, leaving the pull-ups on works in practically all cases.

Here's the quick rundown:
  1. NO switches to GND: wire in parallel, signal active low, need pull-ups;
  2. NC switches to GND: wire in series, signal active high, need pull-ups;
  3. NO switches to VDD: wire in parallel, signal active high, need pull-downs (internal pull-ups disabled);
  4. NC switches to VDD: wire in series, signal active low, need pull-downs (internal pull-ups disabled);
  5. Changeover switches wired to both GND and VDD: wiring a little more complex, can be active low or high, pull-ups helpful. Safer failure mode if wired active high and pull-ups enabled;
  6. Active switches (optical, magnetic): may or may not be wired in parallel, signal usually active low, need pull-ups if open-drain; pull-ups don't hurt with any other type of switch I'm aware of.
1 is the old way from GRBL 0.8; 2 is the best way to wire NC switches, and should be the recommended method for 0.9; 3 is pointless; 4 is a good way to get NC switches on GRBL 0.8 without patching it (use stronger pull-downs to overcome internal pull-ups), but unnecessary with 0.9 (use method 2 instead). Method 5 is the best way to wire mechanical switches for noise immunity, albeit slightly more complex. Finally, 6 really depends on the switches, but many of them are active-low open-collector outputs that can be wired in parallel, so they're equivalent to case 1.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

chamnit
Posts: 376
Joined: Tue Aug 12, 2014 2:16 pm
Location: Albuquerque NM, USA
Contact:

Re: Normally Closed Limit Switches 2

Post by chamnit » Sun Jan 11, 2015 9:29 pm

@cvoinescu : That is tremendously helpful. Thank you. I'm going to cross check this with an electrical engineer I know. FWIW, there is an intent to make limit states fully-configurable at some point. There wasn't much of any push back up to now. I'll move it up on my to-do list.

SmokyRick
Posts: 168
Joined: Sun May 11, 2014 7:22 pm

Re: Normally Closed Limit Switches 2

Post by SmokyRick » Sun Jan 11, 2015 9:32 pm

You guys really have me intrigued. I would like to add limit switches but am so lost to what you are saying here. Pull-ups, pull-downs, no idea what you all mean at all. I have a standard SO2 with spindle control enabled. From what I have seen, I need to have the limit switches wired to +5v on the Arduino. That spot is already taken up by the spindle control. Can i wire them parallel to that? Is there something else I need to do to make this all work together? Is there a schematic of what is really needed? I could follow a schematic and get this thing wired, but REALLY am unsure of what to do, right now.
Thanks for any help, and hope this is not considered hi-jacking this thread. I need to know some of this and don't know where else to turn.
Smoky Rick
Smoky Rick Crawford in the middle of Northern Illinois, USA.
ShapeOko2 s/n 5200 all stock. Arduino, gshield, Grbl Controller, Autodesk Fusion 360.
Mods: Quiet cut spindle, grbl v0.9g w/ spindle control enabled.

faulty
Posts: 3
Joined: Wed Nov 26, 2014 2:59 am

Re: Normally Closed Limit Switches 2

Post by faulty » Mon Jan 12, 2015 1:00 am

Thanks guys for the quick confirmation. I realized that when I tested the setup after posting my question, additional pull up is necessary. @cvoinescu, you are right, inverting and pull-up should really be configured separately.

Btw, for anyone new to this, make sure you have shielded wire for your limit switches or add 0.1uF caps to the limit pins otherwise you'll have noise issues. Check out the discussion here http://www.shapeoko.com/forum/viewtopic.php?f=3&t=3423 Earlier I can't get out of alarm state after homing before adding the caps, and I thought it's some grbl bugs :D

veng1
Posts: 250
Joined: Fri Nov 30, 2012 12:09 pm

Re: Normally Closed Limit Switches 2

Post by veng1 » Mon Jan 12, 2015 4:34 pm

@cvoinescu : Please clarify something. Is the term "Changeover switches" as you use a three terminal switch that is NO/NC/Common?

I confess, I don't know what we call that switch in the States.

Thanks,

Pat.

cvoinescu
Posts: 4442
Joined: Thu Jul 19, 2012 6:50 pm
Location: Camberley, UK
Contact:

Re: Normally Closed Limit Switches 2

Post by cvoinescu » Mon Jan 12, 2015 4:53 pm

Yes, I mean using all three terminals (C, NC, NO) of a SPDT switch.

I prefer wiring GND into NC, VDD into NO, and C to the input pin, with the pull-up enabled and the input active high, because a broken wire then causes the limit switch to appear triggered, or to work more or less normally. (If you wire them the opposite way, a broken wire can cause the limit switch to be ignored.) I make the assumption that an interrupted connection is more likely than a short-circuit.

If you have two switches, 1 and 2, wire GND into NC1, VDD into NO1 and NO2, C1 into NC2, and C2 to the input pin. In effect, the NC sections connect in series to GND, and the NO sections in parallel to VDD.

Edited to add this:
changeover limit switch wiring.png
changeover limit switch wiring.png (5.43 KiB) Viewed 5871 times
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

gjbroom
Posts: 11
Joined: Fri Jul 20, 2012 6:13 pm

Re: Normally Closed Limit Switches 2

Post by gjbroom » Fri Feb 06, 2015 5:19 am

cvoinescu wrote:TL;DR version: ideally, inverting and the pull-ups should be controlled separately; that would cover all cases. Short of that, leaving the pull-ups on works in practically all cases.

Here's the quick rundown:
  1. NO switches to GND: wire in parallel, signal active low, need pull-ups;
  2. NC switches to GND: wire in series, signal active high, need pull-ups;
  3. NO switches to VDD: wire in parallel, signal active high, need pull-downs (internal pull-ups disabled);
  4. NC switches to VDD: wire in series, signal active low, need pull-downs (internal pull-ups disabled);
  5. Changeover switches wired to both GND and VDD: wiring a little more complex, can be active low or high, pull-ups helpful. Safer failure mode if wired active high and pull-ups enabled;
  6. Active switches (optical, magnetic): may or may not be wired in parallel, signal usually active low, need pull-ups if open-drain; pull-ups don't hurt with any other type of switch I'm aware of.
1 is the old way from GRBL 0.8; 2 is the best way to wire NC switches, and should be the recommended method for 0.9; 3 is pointless; 4 is a good way to get NC switches on GRBL 0.8 without patching it (use stronger pull-downs to overcome internal pull-ups), but unnecessary with 0.9 (use method 2 instead). Method 5 is the best way to wire mechanical switches for noise immunity, albeit slightly more complex. Finally, 6 really depends on the switches, but many of them are active-low open-collector outputs that can be wired in parallel, so they're equivalent to case 1.
Thank you for this summary. Every thread seems to have different suggestions. As I have to do some rewiring anyways when upgrading from GRBL 0.9a to 0.9g, I am going to redo my homing switches. Even with caps and pullups (and shielded wire) I still have noise issues. Looking at my schematic I drew for myself I think I wired them correctly.

Bookmarking this thread....
ShapeOko1 #443, doubled X gantry + driveshaft Y, ShapeOko2-style Z, open-end mounts, Inventables DC spindle, limit switches
GRBL 0.9j and ChiliPeppr

Post Reply