Welcome to the forum   
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post in this topic Go to first unread post in this topic
Offline DaleSchultz  
#1 Posted : 16 December 2019 14:06:13(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
We had some discussion about optocouplers in this thread here:
https://www.marklin-user...-and-Processing-Software
but in order not to hijack that thread, I want to start one specifically about isolating detection tracks from an Arduino type processor...

I plan on using ESP8266 modules to report track detection to my layout software. The software side of it is all working, if I connect pins on the ESP8266 to the GND of the ESP8266 - my software get the message that a sensor has triggered. (Each pin can even be mapped to any s88 address or even higher than 496.)

So now the hardware side, I have never worked with optocouplers before and my understanding is that they should be used to prevent nasty current from getting into my logic circuit on the ESP. I understand that a current on the input side of the optocoupler produces current on the output side, keeping boths sides separate. 'Nasty current' could be a short between the center rail with digital signal to the isolated rail for example.

Usually I connect the section of isolated rail to an input port of an s88 and presumably that s88 has its own opto-isolation and provides some current that is grounded when the isolated rail is grounded by a train axle.

I therefore also have to provide some current that drains to ground when the isolated track is bridged by an axle. It seems to be practical to use the 5V supply that I am using to power the ESP8266 to be the source of that current. Is that true?

Here is what I am thinking:

sensor.png

I am wondering if using the same source and common ground is defeating the optoisolation.

Can anyone suggest the most suitable (and economical) optocoupler to use?
Once I know the input limits of the optocoupler I can calculate the value of R1 and add any capacitor that it may also demand.

Edited by user 25 December 2019 18:46:50(UTC)  | Reason: changed title

Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
thanks 1 user liked this useful post by DaleSchultz
Offline blid  
#2 Posted : 16 December 2019 16:56:26(UTC)
blid

Sweden   
Joined: 02/01/2012(UTC)
Posts: 228
Location: Stockholm, Sweden
I don't know much about electronics, but I'm using LDT RM-88 Opto variants. They are connected to the 3rd rail/red instead of the ground/brown like the standard S88s. Maybe you can do the same and use the digital current?
OneGauge Marklin and MTH, ESU ECoS 2.1 on LGB tracks. MTH 3-rail 0-gauge, DCS on GarGraves tracks. Z: Rokuhan tracks, analog or DCC+TC Gold.
thanks 1 user liked this useful post by blid
Offline DaleSchultz  
#3 Posted : 16 December 2019 17:21:50(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
I understand that commercial feedback sensors can also use the center rail current but I prefer not to use valuable digital current for this purpose.
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
thanks 1 user liked this useful post by DaleSchultz
Offline mario54i  
#4 Posted : 16 December 2019 19:55:49(UTC)
mario54i

Italy   
Joined: 28/03/2007(UTC)
Posts: 283
Location: Torino,
Originally Posted by: DaleSchultz Go to Quoted Post

I am wondering if using the same source and common ground is defeating the optoisolation.


Optocouplers are used to connect two circuits with different supply and ground.
Here you have common ground so it's useless.
As you are connecting to outside world through wifi you could get the 5 V supply from rectified digital signal, but I'm afraid that spikes and so could give problems.

Regards

Offline DaleSchultz  
#5 Posted : 16 December 2019 20:33:35(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
yes, this was my impression... but.....
the digital track current is coming from a separate power source, if that got connected (by a derailment) to the isolated rail, it would start putting that current into the logic circuit. Would the optocoupler help then?

How do s88s do opto-isolation if its power supply and ground are all common?
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline DaleSchultz  
#6 Posted : 16 December 2019 20:50:29(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
assuming an optocoupler is of little help here (the Digital pin in actually 3.3V and the source power 5V) what do people suggest? Do I dare run the D3 pin directly to the isolated track and hence to GND?
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline clapcott  
#7 Posted : 16 December 2019 21:15:02(UTC)
clapcott

New Zealand   
Joined: 12/12/2005(UTC)
Posts: 2,433
Location: Wellington, New_Zealand
Originally Posted by: DaleSchultz Go to Quoted Post
... assuming an optocoupler is of little help here ...

I think that statement is misdirected. The reason it is of little help is in part because the supply and return rails are common anyway.

Removing both the +5 and the Gnd linkages between track circuit and the Arduino is a start.

The power rail (left side of optocoupler) could (should) be the same as the power for that circuit (i.e. the track red)
Of course throw in a diode and a (small) capacitor - rate the current limiting resistor based on (say 20v(24v)) divided by the optocouplers current specifications.

If ambient electrical noise is a suspected issue, then a pullup resistor on the contact track would help

Assumption : Arduino pin has internal pullup resistor enabled
Peter
Offline Purellum  
#8 Posted : 16 December 2019 21:24:29(UTC)
Purellum

Denmark   
Joined: 08/11/2005(UTC)
Posts: 3,500
Location: Mullerup, 4200 Slagelse
Cool

Originally Posted by: DaleSchultz Go to Quoted Post
I understand that a current on the input side of the optocoupler produces current on the output side, keeping boths sides separate.


Almost correct, it's like a transistor on the output side that opens.

I would either just use the digital current to power the input side of the optocoupler, since the current draw is very small,
and I guess only few of them will be powered at the same time. ( Larger R1 and a diode to prevent reverse current to the optocoupler )

Otherwise any cheap power supply could do the trick.

Originally Posted by: DaleSchultz Go to Quoted Post
I understand that commercial feedback sensors can also use the center rail current but I prefer not to use valuable digital current for this purpose.


No current is used; but a small voltage drop.

Think of it like this: On ALL wires going to center rails, both detection zones and "not detection" zones, you insert 2 ( *or 4* )
diodes in anti-parallel.

Your detection is then to measure if there's a voltage on the diodes, which means that there's current passing through them.

Your optocouplers then measures if there's a voltage drop or not.

( *or 4*) is depending on type of optocoupler and if you want a diode in series with the optocoupler.

By mounting the anti-parallel diodes on both detection zones and "not detection" zones you'll have the same voltage drop on all tracks everywhere on your layout, and you'll not be able to see any difference - and even better if you can raise the track voltage the same as the voltage drop on the one or two diodes, then everything will be as is has always been.

Per.

Cool

If you can dream it, you can do it!

I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.

In case this is not legally possible:
I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.

UserPostedImage
thanks 1 user liked this useful post by Purellum
Hax
Offline hxmiesa  
#9 Posted : 17 December 2019 14:19:58(UTC)
hxmiesa

Spain   
Joined: 15/12/2005(UTC)
Posts: 3,520
Location: Spain
I dont know if this could help, but on my own PLC-controlled system, -thansk to the help of Josep (jcp_ate on this forum), I power the PLC inputs constantly, and when a wheel bridges the contact-track, the input turns OFF, as the signal is now grounded.
That way I can use any kind of power on the input, as long as the 0/ground is common.
(Might be with what you guys call a pull-up (or d-down) resistance¿?)
Best regards
Henrik Hoexbroe ("The Dane In Spain")
http://hoexbroe.tripod.com
thanks 1 user liked this useful post by hxmiesa
Offline DaleSchultz  
#10 Posted : 17 December 2019 19:30:12(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
Thanks for all the replies, let me see if I can make sense of it all....

So yes, as I expected, the diagram I showed does not really achieve anything with the optocoupler.....

If the goal is to use an optocoupler, yes, I could add an additional power supply to the small processor, (such as a 120V AC to 5V USB charger) but my mind suggests to me that in fact everything in my house ultimately has a common ground.. the charger and the power supply for the layout would be connected to the same power supply. (Even with AC, the neutral is bonded to ground at the breaker box.)

My entire layout system; Intellibox, two boosters, signals, s88 modules, track, 12V and 5V DC, circuits all use a common ground, and that ground is also tied to the ground of the house and the PC connected to the Intellibox. This allows all the accessory consumers of current to have a simple wiring system that ties back into a ground bus around the layout. Does it make sense to now introduce a quasi-separate set of power supplies?

Given that the goal is to know when the rail is no longer isolated, if I tied the GND of the ESP8266 to the layout ground, what are the possible bad side effects?

Possible dangers:

  1. Digital current could find its way to the isolated rail (by a derailment or metal object bridging the center rail to the isolated rail), and only to that rail and not to ground, allowing a large current to run into ESP8288 digital pin and let the smoke out.
  2. Noise?
  3. Static discharge?


Is the solution perhaps to simply prevent those dangers from being realised?

Clearly I could add a diode to the circuit between the rail and the ESP8266 pin to prevent current running into the ESP8266.
I could also add a resistor to that circuit, (the 3.3V pins I will be using have pull-up resistors already but not sure if that is the same thing)
The pins can sink to 0V or supply 3.3 V with a maximum current of just 12mA.

Something like this:

sensor2.png
(I added orange digital center rail signal - most likely source of stray current)

Does that sort out the danger of stray current?

For noise, what sort of capacitor is suggested and where? (I struggle to understand electrical filtering.)

I do expect some detection tracks to be bridged for extended periods of time. When a train stops on one, it will be bridged continuously.
I also expect many of these to be bridged simultaneously.

Per, If there is a voltage drop, current must be flowing, no?
You lost me completely on all the diodes stuff... I understand what anti-parallel is, but don't understand what you are suggesting.

I am also perfectly happy to have the sensors normally 'high' and go low when activated. I can flip the logic trivially in the software.

Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline mario54i  
#11 Posted : 17 December 2019 19:39:18(UTC)
mario54i

Italy   
Joined: 28/03/2007(UTC)
Posts: 283
Location: Torino,
Originally Posted by: clapcott Go to Quoted Post

Of course throw in a diode and a (small) capacitor - rate the current limiting resistor based on (say 20v(24v)) divided by the optocouplers current specifications.

There are AC input optocouplers, they have two opposite LEDs. So no need for external diode and capacitor.
I'm using the Avago/Broadcom ACPL844 quad AC input optocoupler.
This are my sensor modules.



Regards

thanks 1 user liked this useful post by mario54i
Offline DaleSchultz  
#12 Posted : 17 December 2019 21:18:26(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
Mario, are you then encoding all the sensor data serially? Are you creating s88 bus signals?
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline mario54i  
#13 Posted : 18 December 2019 10:25:46(UTC)
mario54i

Italy   
Joined: 28/03/2007(UTC)
Posts: 283
Location: Torino,
Originally Posted by: DaleSchultz Go to Quoted Post
Mario, are you then encoding all the sensor data serially? Are you creating s88 bus signals?


I don't know exactly how a S88 works but it should be something similar.
Arduino sends a command that loads the status of all inputs in parallel into a cascade of shift registers (parallel in serial out) and then reads them serially.

thanks 1 user liked this useful post by mario54i
Offline DaleSchultz  
#14 Posted : 24 December 2019 20:25:43(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
well, I just did a test on my actual layout power system, with this configuration: (R1 = 0 Ohms)

sensor2.png

and it works.

I thought I had built in debounce functionality but I need to look into that as I am getting a slew of sensor reports each time. (Just a software issue)
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline hxmiesa  
#15 Posted : 24 December 2019 21:19:17(UTC)
hxmiesa

Spain   
Joined: 15/12/2005(UTC)
Posts: 3,520
Location: Spain
Originally Posted by: DaleSchultz Go to Quoted Post
I thought I had built in debounce functionality but I need to look into that as I am getting a slew of sensor reports each time. (Just a software issue)

Yeah! I use a lot of TOF (Time Off) functions in the PLC software, to filter out the correct triggering; trains passing, trains occupying)
Especially needed when not all axels in the consist are conductive AC-axles; Some slow-starting long trains can often report a track free, just because of a couple of consecutive waggons with DC-wheels passes the detection-strip. A good long TOF time takes care of that.

Best regards
Henrik Hoexbroe ("The Dane In Spain")
http://hoexbroe.tripod.com
Offline DaleSchultz  
#16 Posted : 24 December 2019 23:11:29(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
I already handle all the mutiple axles and chatter in my layout software so this is just fine tuning really, I increased the time from 50ms to 90ms in the debounce code.
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline DaleSchultz  
#17 Posted : 25 December 2019 00:01:35(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
well, I got braver.... as a test, I applied some digital center rail current to the diode.... and it cooked the ESP8266... The experiment was well designed with a clear result.

It seems that the ESP8266 died before the booster detected a short.

So the diode will only protect against positive stray voltages, and not the negative voltage (as found in half of the digital signal and any AC 16 Volt current) that could arrive on the diode.

So any suggestions?

Back to the optocoupler idea? even if the ground is common...?

Assume there is a 1n4004 diode in series with R1 too...
sensor.png

If, in the setup above, the center rail digital signal was accidentally bridged to the isolated rail, it would be bringing 5V (through R1) into the digital circuit. - Is that likely to damage the digital booster? I don't think that would harm the ESP8266.
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Offline DaleSchultz  
#18 Posted : 25 December 2019 18:45:18(UTC)
DaleSchultz

United States   
Joined: 10/02/2006(UTC)
Posts: 3,997
so I have spent some time reading up on stray voltage protection, and here is my current idea:

sensor3.png

C1 0.01uF
D1 1N5817
D2 1N5817
R1 1k Ohm
R2 10 Ohm
Dale
Intellibox + own software, K-Track
My current layout: https://cabin-layout.mixmox.com
Arrival and Departure signs: https://remotesign.mixmox.com
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

| Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.611 seconds.