Correct usage of optoisolator for noise immunity on unshielded connections

Thread Starter

daxliniere

Joined Aug 7, 2021
32
Hi everyone,
I have a small CNC machine and the limit switches (normally closed) are getting false triggers from the stepper motor wires that run inside the same cable trunking. None of the wires are shielded of course.

What's the best way to filter this noise? Current controller is an Arduino GRBL shield. Another controller is on its way, but I would like to solve this induced noise problem.

My first thought was an optoisolator, but as far as I can tell, I would need to add a completely separated power supply otherwise there would be a shared ground connection - that would negate the point of an optoisolator, right?

Otherwise, perhaps I could add a capacitor (value? series/parallel?) to filter the input? Since it's just a 5v DC on/off signal coming from the limit switches, maybe this could work, too?

Any help would be greatly appreciated!

All the best,
Dax Liniere.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
32
Sketch of the current components and wiring - ? If only there were a concise term for such information . . . . .

ak
Hi AnalogKid, thanks for the reply.

Attached is the board in question. NC switches connect between an arduino pin (with internal pullup resistor to 5v) and ground (which is available on the upper row of the header with the limit switches).
 

Attachments

drjohsmith

Joined Dec 13, 2021
401
Hi AnalogKid, thanks for the reply.

Attached is the board in question. NC switches connect between an arduino pin (with internal pullup resistor to 5v) and ground (which is available on the upper row of the header with the limit switches).
Dont suppose you have a scope to show what the "spikes" look like please.

I assume its a home 3D printer of some sort ?

Your best first place would be to wire the limit switches using a shielded two core,
the switch to the two wires, the shield to the ground / case of the printer.
 

MrChips

Joined Oct 2, 2009
26,145
The key here is impedance.

You want the impedance of the sensing circuitry to be low impedance inputs.
Voltage sensing inputs tend to be relatively higher impedance inputs.
Current sensing inputs tend to be low impedance. Opto-isolators are current sensing and hence can provide double protection, i.e. low impedance as well as isolation.

You can still use opto-isolators with common ground connections.

The first step would be to find the circuit schematics of your board, or if not available, try to reverse engineer the input section for the limit switches. If they are voltage sensing, try to locate the input pullup resistors. Try changing the resistors to 220Ω which will provide about 20mA current @ 5V.

Edit:
Thinking about this again, if the limit switches are normally closed to GND then the above may not solve the problem.
It might require putting an RC filter on the inputs at the board.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
32
Thanks guys!
It's an Arduino, so the pullup resistors are internal. That's great to know about running optoisolators with common ground. I guess it's asking too much to run them with common ground and common VCC?

Since posting here, I found some other information relating to RC filters, so this is welcome to hear. OpenBuilds sell a limit switch with integrated RC filter. Pausing the video, I can see a 0.1uF and a 10k. So I'm guessing put the resistor in series and the cap in parallel across the switch? (both as close as possible to the Arduino)
2022-03-03 22_44_45-Low Pass Filter - Passive RC Filter Tutorial.png


At least I had the sense to use shielded 4-core cable for the 3-phase 1.5kW spindle. :rolleyes: (1.5mm^2 and grounded only at the VFD, of course.)
 

MrChips

Joined Oct 2, 2009
26,145
I would put the RC filter at the control board, not at the limit switch.

For starters, try R = 220Ω, C = 1μF.
R goes in series between the switch and the input.
C goes across the input and ground.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
32
Thanks MrChips. I just thought about pluggin' those values into an online RC calculator and this is what I get:
0.1uF+10k = 159Hz
1uF+220R = 723Hz

Any thoughts on that? The limit switches wouldn't be operating at anywhere near even 10Hz.
 

MrChips

Joined Oct 2, 2009
26,145
There must be a pull-up resistor that biases the input pin high. We need to know the value of this resistor.
When the limit switch is activated the switch goes open and the capacitor will charge through this pull-up resistor.
This will determine the time-constant of the Rpullup x C charging circuit.

The added RC is to filter out EMI (electro-magnetic interference) picked up by the unshielded cable. The cable is grounded at the switch end but picks up emi along the way to the controller. This is likely to be at higher frequencies than 10Hz and this is what we are attempting to filter out.
 

MrChips

Joined Oct 2, 2009
26,145
You can try just the 1μF capacitor at the input to ground.

How many inputs do you have?
Are all the limit switches wired in series to a single input?
 

Thread Starter

daxliniere

Joined Aug 7, 2021
32
The Arduino manual says the internal pullup resistor is between 20kΩ and 50kΩ.
I note that on the GRBL support site, they seem to have added an additional pullup resistor. I guess this can't hurt?
They have also omitted the series resistor.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
32
You can try just the 1μF capacitor at the input to ground.

How many inputs do you have?
Are all the limit switches wired in series to a single input?
Just saw this after I posted my reply.
Sure, I'll try the 1uF cap first.

There are 3 inputs (XYZ), X & Y have 2 NC switches (in series) and Z has a single NC switch.
 

MrChips

Joined Oct 2, 2009
26,145
The Arduino manual says the internal pullup resistor is between 20kΩ and 50kΩ.
I note that on the GRBL support site, they seem to have added an additional pullup resistor. I guess this can't hurt?
They have also omitted the series resistor.
Ok. Pull-up resistors 20kΩ-50kΩ are there to just barely pull up the input when the limit switch is open.
I say you can go as low as 100Ω and this should absorb most EMI.

Edit:
Just to make it clear, put the 1μF from input to ground.
The 100-220Ω goes from input to the +ve supply line of your Arduino circuit.
(I don't see why you couldn't put both R and C in parallel from the input to the +ve supply line.)

Make sure that you are connecting to the right voltage. Put a voltmeter across the limit switch. Activate the switch and tell me the voltage reading.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
32
Well, that didn't go to plan. :/ I added 0.1uF caps between inputs and ground, then tied the inputs, each via 100R resistor to +5v.
The 12v reg that powers the Arduino got REALLY hot, as did the Arduino itself. I triple-checked the wiring and everything it correct. I removed the resistors andthe Arduino is still working, but now the X-axis input pin is dead. Y and Z pins (without external 100R) are pulling up to +5v as expected, X pin registers about 0.01v. :(
I tried changing over topin D13 for the X limit switch in the code, but that didn't work,but I didn't have time to try it on D12.
 

drjohsmith

Joined Dec 13, 2021
401
Well, that didn't go to plan. :/ I added 0.1uF caps between inputs and ground, then tied the inputs, each via 100R resistor to +5v.
The 12v reg that powers the Arduino got REALLY hot, as did the Arduino itself. I triple-checked the wiring and everything it correct. I removed the resistors andthe Arduino is still working, but now the X-axis input pin is dead. Y and Z pins (without external 100R) are pulling up to +5v as expected, X pin registers about 0.01v. :(
I tried changing over topin D13 for the X limit switch in the code, but that didn't work,but I didn't have time to try it on D12.
is your arduino 5v tolerant on its inputs ?

the 100 ohm resistor should be in series with the input,
it forms a low pass filter with the switch ,

How about a circuit of what your trying to do ?
 

Thread Starter

daxliniere

Joined Aug 7, 2021
32
is your arduino 5v tolerant on its inputs ?

the 100 ohm resistor should be in series with the input,
it forms a low pass filter with the switch ,

How about a circuit of what your trying to do ?
Yes, they're definitely 5v tolerant (It's a Nano).

Well, yeah, I thought it was supposed to be a LP filter, too, but got this advice above:

Edit:
Just to make it clear, put the 1μF from input to ground.
The 100-220Ω goes from input to the +ve supply line of your Arduino circuit.
(I don't see why you couldn't put both R and C in parallel from the input to the +ve supply line.)
Not sure that a circuit diagram is even necessary since it's just a NC switch going to an Arduino input pin. ¯\_(ツ)_/¯
 

drjohsmith

Joined Dec 13, 2021
401
Yes, they're definitely 5v tolerant (It's a Nano).

Well, yeah, I thought it was supposed to be a LP filter, too, but got this advice above:



Not sure that a circuit diagram is even necessary since it's just a NC switch going to an Arduino input pin. ¯\_(ツ)_/¯
Re "Not sure that a circuit diagram is even necessary"

Whats the saying ?
a picture is worth a 1000 words,


if there was a schematic, then the mistake would have been less likely to be made !

Provide a schematic please,
even a hand drawn sketch is good,
 
Top