Correct usage of optoisolator for noise immunity on unshielded connections

drjohsmith

Joined Dec 13, 2021
852
As drj says, this is just for discussion and thinking out loud.

I cannot see a reason why the Arduino got fried.
100Ω pull-up to Vcc would not kill a GPIO if it is always set to input mode.
Pullup to +12V would destroy the chip.
Enabling the GPIO in output mode would also kill the chip.

I can see that debouncing the input in software could alleviate the problem if the code only responds to sustained constant level. Debouncing code commonly waits for 50ms for the switch to settle. We would have to determine the impact of this long delay knowing the linear speed of the translation motor. The purpose of limit switches is to stop the motor dead in its tracks as soon as the limit is reached. This is a fault condition.

As for input threshold voltages, I am going by the Atmel ATmega328 data sheet.
At Vcc = 5V, high level threshold is 2.6V, low level threshold is 2.1V.


In the picture, there is no proper place for resistor termination.
At the switch, the signal line is grounded.
At the Arduino, the input pin sees a very long antenna with 50kΩ input termination. It would be impractical to put resistor termination to GND at the input. The proper solution is to use an optocoupler.
Hi

yes, Opto is the way to go

QED: don't put low value resistor to ground on the wires.

Debounce
As far as I understand things,
the debounce code, switches its output on the first edge, then disregards any further edges for a time
i.e as I understand things, the debounce library code does not add a delay till the output is detected, over a few machine code cycles, certainty a lot less than the inherent delay a RC input filter as described above would produce
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
Hey everyone!
My ESP32-based CNC controller arrived and I've started building a case for the whole controller setup.

275396675_1316555115527210_8670950046268433017_n111.jpg275480191_361240659198679_1953070071082314112_n.jpg

I've got a TLP281-based optoisolator board and want to run the switches from 12v. I discovered that the VFD has a dedicated 12v output, rated for 200mA max. The 120mm fan is labeled as 100mA, but I measured it as 59mA (63mA on spin-up), so there should be plenty of 'headroom' to run 3 limit switches on their own isolated power supply. The main PSU (seen in photo 2) is 24v 320w.

Optoisolator schematic.jpg

I'm a little confused about how to hook up this particular opto board, since all the examples show it with microcontroller input to control a higher powered device (where you would normally use a relay or transistor). (I know I'll need to add some extra series resistance to supplement the 220R LED series resistors (which is intended for 5v). I believe the IR LEDs inside the TLP281 are Vf=1.15v and I=20mA. So for 12v, 540R minus the existing 220R = 330R.)

The ESP32 CNC board has easy access to +5v at the limit switch connectors.
1647114384722.png

Any suggestions on this would be greatly appreciated!

All the best,
Dax.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
Hey Mr Chips. The CNC board is MakerBase DLC32.
This is the best I can find as a schematic as it's a proprietary product, but with a little bit of multimeter probing I did find that the limit switch headers connect to the ESP32 pins via 1k series resistors. (There may be other connections (i.e. to GND or +5v) that I didn't find.)

https://github.com/makerbase-mks/MKS-DLC32/blob/main/hardware/MKS DLC32 V1.1_001/MKS DLC32 V1.1_001 SCH.pdf

As for the optoisolator board, it's an AliExpress special, so nothing fancy, but the schematic I attached in my last post is correct. (https://forum.allaboutcircuits.com/attachments/optoisolator-schematic-jpg.262586/)

Datasheet for the chip on the 4-ch optoisolator board can be found here: https://www.mouser.com/datasheet/2/408/4195-37827.pdf
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
I also have a handful of various 4-pin optoisolator ICs recovered from various things over the years. I wonder if it's best to just use those.

The TLP281 board seems to need power on the output side, which doesn't seem like what the ESP32 would want to see.
 

MrChips

Joined Oct 2, 2009
30,824
This is the schematics of the opto isolator board you posted.
opto isolator.jpg
LED series resistor R9-R12 is shown as 220Ω.
LED current at 12V is 45mA
LED current at 5V is 14mA

I would consider this current to be too high for 12V supply but ok for 5V supply.
I would connect NC limit switches between +5V and IN1-IN4.

In NC state, limit switches will supply current to LED. Photo-transistor is turned on, grounding base to Q1-Q2,
Q1-Q2 are turned off, presenting high output at Out1-Out4.

Here is your limit switch input to the MKS DL32.
There are no values indicated for series resistor R21-R23.
There are no values indicated for pull-up resistors R18-R20.
Try to find the values of these resistors on the board.

The inputs are pulled up to +3V3.
I would be reluctant to drive your opto-isolator board at +5V on HVCC until you determine the values of those resistors mentioned.

Does your control software have the ability to change the logic to active-LOW input on limit switch fault condition?

MKS DLC32 Limit Switches.jpg
 

MrChips

Joined Oct 2, 2009
30,824
I also have a handful of various 4-pin optoisolator ICs recovered from various things over the years. I wonder if it's best to just use those.

The TLP281 board seems to need power on the output side, which doesn't seem like what the ESP32 would want to see.
If you are going to suggest using any other opto-isolator we need to see the circuit schematics.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
This is the schematics of the opto isolator board you posted.
View attachment 262658
LED series resistor R9-R12 is show as 220Ω.
LED current at 12V is 45mA
LED current at 5V is 14mA

I would consider this current to be to high for 12V supply but ok for 5V supply.
I would connect NC limit switches between +5V and IN1-IN4.

In NC state, limit switches will supply current to LED. Photo-transistor is turned on, grounding base to Q1-Q2,
Q1-Q2 are turned off, presenting high output at Out1-Out4.

Here is your limit switch input to the MKS DL32.
There are no values indicated for series resistor R21-R23.
There are no values indicated for pull-up resistors R18-R20.
Try to find the values of these resistors on the board.

The inputs are pulled up to +3V3.
I would be reluctant to drive your opto-isolator board at +5V on HVCC until you determine the values of those resistors mentioned.

Does your control software have the ability to change the logic to active-LOW input on limit switch fault condition?

View attachment 262659
Thanks again Mr Chips.
Just probed the PCB. Pull ups (R18-20) are 4k7 and series (21-23) are 1k. I can also confirm that the pull up resistors are indeed tied to +3.3v
 

MrChips

Joined Oct 2, 2009
30,824
I would try a different opto isolator board. You don't need extra transistors or supply voltage.
The pull-up resistors R18-R20 plus the series resistors R21-R23 present 5k7 loads to the phototransistors.
I am not too crazy about the R21-R23 series resistors. They will raise the LOW level voltage to 1/6 of Vcc.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
I am not too crazy about the R21-R23 series resistors. They will raise the LOW level voltage to 1/6 of Vcc.
There's not really much I can do about them, unfortunately, as SMD is not something I'm able to do. (plus, I'd need to buy a bunch of SMD resistors I'd rarely have need for.)

What about this: 3x PC817 opto coupler, +12v on NC limit switches and phototransistor connected directly between limit switch input pins and ESP32's ground.

1647209630147.png
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
Hey MrChips et al.
I built the board using PC123 ICs recovered from an old printer and it works perfectly. First time, even!
I've had the unit jogging at 3000mm/min and no false triggers for the limit switches. Thanks so much for your help and direction on this.

I did realise that if I want to control the spindle speed from the ESP32 board, I'm going to end up de-isolating the 12v power I'm obtaining from the VFD as I'll need to connect to GND & +5v PWM input. I guess I'll see if I get false triggers when I try that.


All the best,
Dax Liniere.
 

Attachments

Top