Enabling Limit Switches (+ electrical noise on wires)

Discussion about the arduino based g-code interpreter, grbl
scott216
Posts: 228
Joined: Thu Oct 10, 2013 12:35 pm
Location: New Jersey

Enabling Limit Switches (+ electrical noise on wires)

Post by scott216 » Sat May 10, 2014 4:29 pm

I installed limit switches and I'm having trouble getting them to work. I've got 330 ohm pull-up resistors to 5v for each axis. The switches are normally open and connected to ground. I put a voltmeter on pins D9, D10, D11 to verify they work properly and they do. When not pressed the voltage is 5v, when pressed it's zero. I have shielded wire going to the switches with the shield connected to ground on the Arduino side of the cable.

So, when I run the command ($16=1) to enable the limit switch feature, this is what I get.

Code: Select all

>>> $16=1
ok
ALARM: Hard limit. MPos?
[Reset to continue]
All the switches are open. I don't know why I'm getting this error.

If I click on Soft Reset button I get this:

Code: Select all

Grbl 0.8c ['$' for help]
['$H'|'$X' to unlock]
and the Active State says "Alarm".

If I execute the command $X, I get this

Code: Select all

>>> $X
[Caution: Unlocked]
ok
ALARM: Hard limit. MPos?
[Reset to continue]
If I disconnect power and power up again, it's in Alarm mode
Last edited by scott216 on Wed May 14, 2014 2:12 am, edited 1 time in total.
Shapeoko v2 with DW660
GRBL v0.9i
Location: New Jersey

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

Re: Enabling Limit Switches

Post by cvoinescu » Sat May 10, 2014 6:21 pm

Did you maybe compile GRBL with the limit switch logic inverted? Or is that the stock .hex file?

It's also possible that the Arduino input buffers (the part of the circuit that reads the pins) is toast for those pins. That can happen because of electrostatic discharge, for instance. If you have a spare Arduino, give it a try.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

scott216
Posts: 228
Joined: Thu Oct 10, 2013 12:35 pm
Location: New Jersey

Re: Enabling Limit Switches

Post by scott216 » Sat May 10, 2014 7:05 pm

cvoinescu wrote:Did you maybe compile GRBL with the limit switch logic inverted? Or is that the stock .hex file?

It's also possible that the Arduino input buffers (the part of the circuit that reads the pins) is toast for those pins. That can happen because of electrostatic discharge, for instance. If you have a spare Arduino, give it a try.
It's the stock hex file; I haven't re-flashed the Uno (yet). The homing routine works fine, so I know the inputs are all working. I did narrow the problem down to just the x-axis limit switch. If I disconnect it I don't have the problem. I even moved the x-axis limit switch cable away from all other wiring so it wasn't close to anything, but that didn't help. So it doesn't seem like a noise issue, but I'm gonna put some caps on the lines just to see if that helps.
Shapeoko v2 with DW660
GRBL v0.9i
Location: New Jersey

lordmundi
Posts: 207
Joined: Wed Jan 01, 2014 4:02 am
Location: Friendswood, TX
Contact:

Re: Enabling Limit Switches

Post by lordmundi » Sat May 10, 2014 7:15 pm

I've made a few posts on limit switches in the forum (look it up if you are interested) and I can assure you that noise turns out to be a way bigger issue than it seems possible. I think the stepper motor lines just put out WAY more noise than I (and many others) could have thought possible.

My guess is if you put an oscilloscope on your existing lines, you will see a hazy blur. That capacitors will help. So will shielding the wires to your motors. That seems to be the only way around this issue for most folks.

scott216
Posts: 228
Joined: Thu Oct 10, 2013 12:35 pm
Location: New Jersey

Re: Enabling Limit Switches

Post by scott216 » Sat May 10, 2014 8:09 pm

lordmundi wrote:I've made a few posts on limit switches in the forum (look it up if you are interested) and I can assure you that noise turns out to be a way bigger issue than it seems possible. I think the stepper motor lines just put out WAY more noise than I (and many others) could have thought possible.

My guess is if you put an oscilloscope on your existing lines, you will see a hazy blur. That capacitors will help. So will shielding the wires to your motors. That seems to be the only way around this issue for most folks.
I've got a scope, that's a good idea. The limit switch wires and 2 of the 3 stepper motor wires are all shielded with shields connected to ground. The unshielded stepper motor wire is not next to the x-axis limit switch wire (that's the one with the problem). I'll probably replace the unshielded stepper motor wire with shielded.
Shapeoko v2 with DW660
GRBL v0.9i
Location: New Jersey

scott216
Posts: 228
Joined: Thu Oct 10, 2013 12:35 pm
Location: New Jersey

Noise on limit switch inputs

Post by scott216 » Sun May 11, 2014 12:32 am

I hooked up my scope and it was pretty interesting. There's about 3 volts p-p noise on the line.

Here's a screenshot with my scope. The top graph is at the Arduino end of the limit switch cable. The bottom graph is at the limit switch end of the cable. One of the stepper motor cables is unshielded.
X-axis with capacitor.jpg
Noise on x-axis with 0.1uF capacitor
X-axis with capacitor.jpg (38.88 KiB) Viewed 5589 times
I replaced the unshielded stepper motor cable with shielded, but it didn't make any difference. Note in this screenshot the scope is set at 1 volt/division. The other two images it's set at 1/2 volt/division.
X-axis with shielded stepper cable.jpg
Noise on x-axis limit switch. Replaced unshielded stepper cable with shielded.
X-axis with shielded stepper cable.jpg (34.5 KiB) Viewed 5589 times
I added a 0.1uF capacitor between the limit switch input and ground - on the Arduino side. It didn't seem to help
X-axis with unshielded stepper cable.jpg
Noise on limit switch input. Top is at Arduino end of cable, bottom is limit switch end of cable. Stepper cable is unshielded.
X-axis with unshielded stepper cable.jpg (36.1 KiB) Viewed 5589 times
Shapeoko v2 with DW660
GRBL v0.9i
Location: New Jersey

scott216
Posts: 228
Joined: Thu Oct 10, 2013 12:35 pm
Location: New Jersey

Re: Enabling Limit Switches

Post by scott216 » Sun May 11, 2014 12:34 am

Here's the noise on Y and X axis
Y-Axis.jpg
Y-Axis limit switch noise
Y-Axis.jpg (31.52 KiB) Viewed 5589 times
Z-Axis.jpg
Z-Axis limit switch noise
Z-Axis.jpg (30.98 KiB) Viewed 5589 times
For fun I took as screenshot of the stepper motor signal. The motor was not moving at the time
Stepper motor pulse.jpg
Stepper motor signal with motor not moving
Stepper motor pulse.jpg (28.54 KiB) Viewed 5589 times
Shapeoko v2 with DW660
GRBL v0.9i
Location: New Jersey

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

Re: Enabling Limit Switches

Post by cvoinescu » Sun May 11, 2014 12:52 am

This is very interesting and baffling at the same time. Having just written a post in a huff about an unclear problem report, I would like to balance the karmic scales by thanking you for the signal traces and for the time you spent researching your own problem and telling us about it. :)

It looks like there's huge ringing on the motor signal, a lot of which makes it to the limit switches. Could it be a problem of grounding? Where do you connect the ground of the limit switches? And where do you connect the shields of the motor cables? I would connect the limit switch GND to one of the Arduino GND pins, and the shields of the motor cables to the earth terminal of the motor supply if you have a cage-type supply, or to the negative pole otherwise (definitely not to one of the Arduino GND pins). Consider connecting the motor end of your shielded motor cable to the motor plate -- I can't see how that would make things worse -- but keep the limit switches and their cables unconnected to the metallic parts of the machine.
Proud owner of ShapeOko #709, eShapeOko #0, and of store.amberspyglass.co.uk

scott216
Posts: 228
Joined: Thu Oct 10, 2013 12:35 pm
Location: New Jersey

Noise on limit switch inputs

Post by scott216 » Sun May 11, 2014 12:59 am

cvoinescu wrote: Where do you connect the ground of the limit switches? And where do you connect the shields of the motor cables?
Shields for limit switch cables and shields for motor cables are all connected to Arduino ground. It's really the only convenient ground point I have. I could as a test connect the shields to earth ground by running a separate wire to the wall outlet. I'll do that as a test, but I don't think it's a good permanent solution. I can also try connecting the shield to the motor plate as you suggest. Since the motor plate is not grounded I don't think it would help much, but it's easy enough to test out.
Shapeoko v2 with DW660
GRBL v0.9i
Location: New Jersey

hanselcj
Posts: 96
Joined: Tue Apr 01, 2014 9:57 pm
Location: Central Florida (east coast)

Re: Enabling Limit Switches

Post by hanselcj » Sun May 11, 2014 9:14 pm

I have read about a number of people having issues with this, and wondered if using coax for the limit switches would help shielding. This stuff: http://amzn.com/B0000511WV seems pretty thin, so it should be easy enough to work with. Cutting off the ends and connecting the center lead and shield to the limit switches would be a bit of work, but should prevent much of the noise. Shouldn't it?

-Chase
Shapeoko 2 #4951: Xbox 360 Pendant, Z-axis lead screw and NEMA23 upgrade, DW660 with Loc-Line dust collection, Googly Eyes, Swivel cutter attachment.

Post Reply