{"id":529,"date":"2016-01-02T12:57:46","date_gmt":"2016-01-02T20:57:46","guid":{"rendered":"http:\/\/thenscaler.com\/?p=529"},"modified":"2016-01-02T12:57:46","modified_gmt":"2016-01-02T20:57:46","slug":"block-occupancy-detection-for-dc-and-dcc-part-2","status":"publish","type":"post","link":"https:\/\/thenscaler.com\/?p=529","title":{"rendered":"Block Occupancy Detection for DC and DCC, Part 2"},"content":{"rendered":"<p>In <a href=\"https:\/\/thenscaler.com\/?p=514\">Block Occupancy Detection for DC and DCC<\/a> I demonstrated the use of an ACS712 sensor and an Arduino Uno to sense current draw across the rails, the basis for most block occupancy detection systems. Assuming that one has also equipped some rolling stock with resistor wheel-sets, lighting or sound decoders, so that the entire length of a train is detectable, the theory is that current draw indicates that a block is occupied &#8212; and lack of current draw indicates that a block is clear.<\/p>\n<p>In reality, it may not be that simple if you have devices drawing from track power other than locomotives and rolling stock. Any background current draw on rail power can interfere with the current sensing model.<\/p>\n<h2>Rail Powered Accessories<\/h2>\n<div id=\"attachment_572\" style=\"width: 310px\" class=\"wp-caption alignright\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-under-lights.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-572\" class=\"size-medium wp-image-572\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-under-lights-300x131.jpg\" alt=\"The Test Loop\" width=\"300\" height=\"131\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-under-lights-300x131.jpg 300w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-under-lights-1024x446.jpg 1024w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-under-lights.jpg 1356w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-572\" class=\"wp-caption-text\">The Test Loop<\/p><\/div>\n<p>Keen eyes will notice that the test loop has a rail powered light on the Atlas track bumper at the end of the siding. <a href=\"https:\/\/thenscaler.com\/?p=99\">I laid the track on the test loop long before I understood block occupancy detection<\/a>.\u00a0 I won&#8217;t do that again as I build the <a href=\"https:\/\/thenscaler.com\/?p=254\">L&amp;NC<\/a>.<\/p>\n<p>The problem is that the bumper light draws from the track itself and thus presents a constant load on that block. The draw of the lamp forces a slightly higher threshold for determining occupancy than would otherwise be appropriate.\u00a0 Static loads on monitored blocks greatly complicate current sensing.<\/p>\n<p>The best practice where current sensing is used to detect block occupancy is to feed accessories from a separate power bus. To use track power (as you might with a stationary decoder running a turnout motor), draw from outside monitored blocks\u2014from a separate branch or sub-bus\u2014to avoid confusing the occupancy detection system.<strong><br \/>\n<\/strong><\/p>\n<h2 style=\"text-align: justify;\">Solving the Continuity Problem.<\/h2>\n<p>While current sensing works well on a DC layout, as shown in the <a href=\"https:\/\/www.youtube.com\/watch?v=ObjIysigIKU\" target=\"_blank\">first video demonstration<\/a>, the use of current as a control mechanism means that block occupancy is undetectable at times because of normal operation. Similarly, any transient loss of DCC track power (as with a short) will throw the occupancy detection system off for the same reasons. I think of this as a continuity problem.<\/p>\n<p>The solution in both cases is to monitor the track bus with an extra sensor and lock the state of the system whenever the track bus is off. The simplest algorithm, puts it a slightly different way:<\/p>\n<p style=\"text-align: justify;\"><em><strong>if<\/strong> track current is flowing <strong>then<\/strong> check blocks and update <strong>else<\/strong> maintain current state<\/em><\/p>\n<p>E.g. ( in C++, where &#8220;master.on&#8221; represents the master current status):<\/p>\n<pre>if(master.on == true) {\r\n  for ( i = 0, i &lt; NUMBER_BLOCKS; i++) {\r\n    \/\/ check block sensor <strong>i<\/strong> and update block status\r\netc......<\/pre>\n<p>For the cost of a sensor and a few lines of code the block occupancy system will now maintain its state correctly whenever there is a total loss of track power.<\/p>\n<h2>Wiring for Detection<\/h2>\n<p>Preparing the test loop for the Arduino &amp; ACS712 sensor based occupancy detection system was a bit of a chore, primarily because current sensing requires some rethinking of the standard approach to layout wiring.<\/p>\n<div id=\"attachment_563\" style=\"width: 620px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-wiring-phase2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-563\" class=\"wp-image-563 size-large\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-wiring-phase2-1024x667.jpg\" alt=\"Wiring. Block sensors were added in Phase 2. Phase 3 signals and lighting in progress.\" width=\"610\" height=\"397\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-wiring-phase2-1024x667.jpg 1024w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-wiring-phase2-300x195.jpg 300w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/test-loop-wiring-phase2.jpg 1834w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><p id=\"caption-attachment-563\" class=\"wp-caption-text\">Test Loop Wiring. Block sensors were added in Phase 2. Phase 3 signals and lighting were in progress when this picture was taken.<\/p><\/div>\n<p>The test loop represents my first crack at it. Needless to say, there is a list of things that will be done differently on the L&amp;NC.<\/p>\n<h3>Routing Buses<\/h3>\n<p>The loop has a bus structure that, except for the lack of the DCC command bus (I connect my throttle directly to the booster when it is attached to the test loop), is the prototype for the <a href=\"https:\/\/thenscaler.com\/?p=254\">L&amp;NC<\/a>.<\/p>\n<div id=\"attachment_565\" style=\"width: 210px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-565\" class=\"size-medium wp-image-565\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel-200x300.jpg\" alt=\"Test Loop Connection Panel\" width=\"200\" height=\"300\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel-200x300.jpg 200w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel.jpg 600w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><p id=\"caption-attachment-565\" class=\"wp-caption-text\">Test Loop Connection Panel<\/p><\/div>\n<p>The bus structure begins with the connection points on one end of the layout, mounted on a connection panel made from .080 styrene sheet. Every module on the L&amp;NC will have one of these, with matching cables at the opposite side where it adjoins the next module.<\/p>\n<p>Starting from the top the first two connection groups are polarized power connections made with color coded Anderson Powerpole connectors. A <a href=\"http:\/\/ntrak.org\/documents\/Manual.pdf\" target=\"_blank\">&#8220;Recommended Practice&#8221; per the Ntrak Manual<\/a>, these things are a reliable solution for creating polarized power connections.\u00a0 Some parts are available from <a href=\"http:\/\/amzn.to\/1QCu3d0\" target=\"_blank\">Amazon<\/a>; I find that <a href=\"http:\/\/www.powerwerx.com\/anderson-powerpoles\" target=\"_blank\">Powerwerx.com<\/a> has the best selection of PowerPole parts and supplies. The 15 amp gear should be sufficient for most N Scale layouts (an N Scale layout requiring more than that would be something to see!). Kudos to <a href=\"http:\/\/ntrak.org\" target=\"_blank\">Ntrak <\/a>for finding and adopting these connectors. BTW: the <a href=\"http:\/\/amzn.to\/1NlpMKs\" target=\"_blank\">crimper is expensive but indispensable<\/a> if one is going to make a bunch of Powerpole connectors.<\/p>\n<p>The top group is the main DC power bus in three voltages: 12 (yellow), 5 (red) and 3.3 (blue) plus ground (black). This was also where I attached a label with the loop&#8217;s <a href=\"https:\/\/thenscaler.com\/?page_id=380\" target=\"_blank\">assigned IP address<\/a>.<\/p>\n<p>The next group down is the track bus (red &amp; black); my DC power pack and my DCC booster can connect to the loop here with a matching plug.<\/p>\n<p>The next two connections are an RJ45 port for Ethernet and a USB connection to the UNO. Both are\u00a0 assemblies I got from <a href=\"http:\/\/www.adafruit.com\">Adafruit Industries<\/a>. On the <a href=\"https:\/\/thenscaler.com\/?p=254\">L&amp;NC<\/a>, the USB port(s) for attached Arduino boards will be located in an accessible place, away from the other connection groups (which will generally be hidden).<\/p>\n<div id=\"attachment_566\" style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel-Rear.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-566\" class=\"size-medium wp-image-566\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel-Rear-300x148.jpg\" alt=\"Connection Panel Bus Connections\" width=\"300\" height=\"148\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel-Rear-300x148.jpg 300w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Connection-Panel-Rear.jpg 902w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-566\" class=\"wp-caption-text\">Panel Bus Connections<\/p><\/div>\n<p>Color coded power buses are routed along the edge to a central barrier strip where feeders take off to supply power where needed. On the L&amp;NC I&#8217;ll choose different, unique colors for the track bus and feeders to reserve black for system ground and red for system Vcc (+5 volts DC).<\/p>\n<p>Suitcase connectors are really popular these days for connecting wires without soldering. If you are not going to do occupancy detection then directly connecting feeders to bus wires with suitcase connectors is a clean solution. However, once you start down the road I&#8217;m traveling&#8211;whether your solution is off-the-shelf or homemade&#8211;suitcase connectors are not helpful. Instead, I find that PC board mounted screw terminals make easy wiring connections that are reliable and easily changed when necessary. When dealing with magnet wire, which you have to use in N scale if you want to run wires through scale light poles, conduits, etc., top-of-the-line PC board terminal systems are the ONLY reliable solution (the cheap versions will drive you crazy with intermittent connectivity).<\/p>\n<div id=\"attachment_523\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/11\/ACS712-Board.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-523\" class=\"wp-image-523 size-thumbnail\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/11\/ACS712-Board-150x150.jpg\" alt=\"ACS712 Board\" width=\"150\" height=\"150\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/11\/ACS712-Board-150x150.jpg 150w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/11\/ACS712-Board-50x50.jpg 50w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><p id=\"caption-attachment-523\" class=\"wp-caption-text\">ACS712 Board<\/p><\/div>\n<p>The ACS712 sensor boards come with screw terminals for the monitored load, plus 3 pin headers that take standard 3 wire servo connectors for connecting to system power and the microcontroller. Wires that connect to the central barrier strip have crimped terminals.\u00a0 I mostly solder at the PC board level and, less often, to make special cables (I solder track connections too, but that is a different issue).<\/p>\n<div id=\"attachment_569\" style=\"width: 210px\" class=\"wp-caption alignright\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Power-Distribution.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-569\" class=\"size-medium wp-image-569\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Power-Distribution-200x300.jpg\" alt=\"Power Distribution on the Test Loop\" width=\"200\" height=\"300\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Power-Distribution-200x300.jpg 200w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Power-Distribution.jpg 600w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><p id=\"caption-attachment-569\" class=\"wp-caption-text\">Power Distribution on the Test Loop. The board in the upper right corner is for distributing 5 volt power to the signal system via PC board terminals.<\/p><\/div>\n<p>On an <a href=\"https:\/\/thenscaler.com\/?p=254\">L&amp;NC module<\/a>, the bus will continue from the central distributions point out to the edge configured to connect to the next module. One big change in module construction on the L&amp;NC will make wiring easier: the cross frame members will be pre-drilled with large holes. That &#8220;little&#8221; gouge you see where wires cross the frame member at the bottom of the picture taught me that lesson.<\/p>\n<p>On the test loop the 12 volt bus supplies the attached UNO with its Ethernet shield; the 5 volt bus supplies all sensors and actuators attached to the UNO and is generally considered system Vcc. The 3.3 volt bus is not currently being used on the test loop (but would be great for low current lighting or animations). All share a common ground (really important!). NB: I use modified Computer power supplies that\u00a0 produce all three voltages at once with a common ground. Multiple DC power supplies can be combined to the same effect; just tie their grounds together to create the common ground.<\/p>\n<p>Even on the test loop, the 5 volt bus is used so much that I need to create a distribution system to get power where needed. The lesson for the L&amp;NC is\u00a0 I will need to have distribution nodes for the whole power bundle in a few strategic locations on each module. Obviously, I need to do some more detailed wiring planning in advance so I know where everything has to go.<\/p>\n<h3>Routing Feeders<\/h3>\n<p>Current sensing encourages a nodal distribution system for track power. Instead of attaching feeders to the nearest track bus, the feeders are routed to an area where the sensors have been mounted. You could mount individual sensors at the points where feeders descend from the tracks above. In some situations that may work better; in other situations, aggregating the sensors in groups is the easier and more effective method.<\/p>\n<div id=\"attachment_592\" style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Track-power-and-block-detection-connections-1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-592\" class=\"wp-image-592 size-medium\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Track-power-and-block-detection-connections-1-300x199.jpg\" alt=\"Current Sensors and Block Feeder Connections.\" width=\"300\" height=\"199\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Track-power-and-block-detection-connections-1-300x199.jpg 300w, https:\/\/thenscaler.com\/wp-content\/uploads\/2015\/12\/Track-power-and-block-detection-connections-1.jpg 576w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-592\" class=\"wp-caption-text\">Current Sensors and Block Feeder Connections.<\/p><\/div>\n<p>ACS712 sensors read only one of the two rail conductors. On the test loop sensors are attached to the red rail.<\/p>\n<p>I tried to complete the rail feeder connection with a board (with terminals) across from the sensors for the black rail connection points. I also ended up using the same board to centralize the power and data connections for the sensors and the servo for the turnout. In the future I will not mix track \/ control system connection points in this way.<\/p>\n<h2>Block Occupancy Detection in Action<\/h2>\n<p>Here is demonstration of the progress so far, with block occupancy detection active on all 4 blocks of the test loop. The signals are programmed to respond to block occupancy and the state of the turnout (the turnout actually has three unique states: &#8220;aligned main&#8221;, &#8220;aligned divergent&#8221;, and &#8220;in motion&#8221;), allowing you to see the system responding as trains move along the track. You&#8217;ll see it work in both DC and DCC &#8212; the layout works whether a power pack or a DCC booster is plugged into the track bus port. I have yet to see a single commercial occupancy detection solution that moves as easily between DC and DCC as this one does. I added a station with internal lights (connected to the same nodal system that supports the signals) to give just a little hint of the capabilities that will be unlocked on the L&amp;NC.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/KleQt1fx2Go\" width=\"480\" height=\"270\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>In future installments, I&#8217;ll dig into the occupancy detect code again to give more insight into how it works. I&#8217;ll also go into the details of how I&#8217;ve implemented signalling on the test loop, including some special (and inexpensive) gear I&#8217;ve designed to allow a single microcontroller to run up to 255 nodes of signals and other kinds of lighting or animation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Block Occupancy Detection for DC and DCC I demonstrated the use of an ACS712 sensor and an Arduino Uno to sense current draw across the rails, the basis for most block occupancy detection systems. Assuming that one has also equipped some rolling stock with resistor wheel-sets, lighting or sound decoders, so that the entire [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":572,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,21,34,14],"tags":[46,48,47,52],"class_list":["post-529","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-electronics","category-layout-control","category-lighting-and-animation","category-test-loop","tag-acs712-sensor","tag-anderson-powerpole","tag-block-occupancy-detection","tag-layout-wiring"],"_links":{"self":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts\/529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=529"}],"version-history":[{"count":37,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":599,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts\/529\/revisions\/599"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/media\/572"}],"wp:attachment":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}