Z-Scale train controller III: controlling turnouts

In part I and II of this series, I described how I implemented a simple locomotive speed controller. The second feature of this train controller is to control turnouts and uncoupler tracks. This part III describes how this is done.

Small-scale track accessories

The first question to ask, is exactly what we want to control: in our case, we are talking about Märklin turnouts for Z-scale tracks. These turnouts have three wires, which control two small coils, as shown below:

Turnout simplified

Those turnouts are usually driven by the Märklin controller, using a 14VAC power source. That said, driving the coils of these turnouts works just as well using DC, the only caveat being that we have to be careful not to leave them powered too long so that they don’t overheat. A quick 10VDC pulse works perfectly.

The second important goal of the design, is to find a way to drive 16 turnouts, which means 32 coils altogether. One design decision I took early in the design, was to drive only one coil at a time. This decision meant we can multiplex those coils in order to reduce the number of components required to drive them.

I ended up splitting those 32 outputs in four banks of 8: four ‘high side’ bank power supplies are connected to four ‘low side’ 8 pin connectors connected in parallel: this way, when we want to drive one output, we just need to apply power to the correct bank power supply, and set the corresponding low-side connector to ground while the rest remains in high impedance state. Very simple, very effective.

Driver circuit

I did some research to find compact solutions that would enable me to implement this multiplexed architecture. I found out that there are chips designed to do just this, designed primarily for the automotive industry where you typically need to drive lots of low power relays, or for consumer products such as dishwashers or air conditioners. I ended up selecting the Freescale MC33880: an 8 output switch with serial control designed to drive inductive charges, exactly what we need! And one important point: this chip can actually be bought in small quantities on the Freescale site. While I had found other alternatives to this chip, nearly all of them were designed for the automotive industry and were not possible to purchase in quantities lower than several thousands!

MC33880

The MC33880 supports up to 2A power switching, which is way more than what we need for the turnout coils. The control interface is a simple SPI serial I/O, wich chip select, data and clock. The AVR supports hardware SPI, so this makes it very easy to drive those chips too.

The final design for this multiplexed driver looks as follows:

Turnout Control

On the right side, the high-side driver – I could have leveraged the 8 outputs there to get 8×8=64 outputs or 32 accessories, but that would have lead to a mess of connectors, so I only implemented 4 outputs. The bottom side driver is the low-side or sink driver, which connects the accessories to the ground in order to activate them.

At this stage, you might wonder why I connected the wires to the four low-side connectors the way I did, instead of a simple logical pin 1 to pin 8 connection? This was done in order to simplify PCB layout. And a simple firmware mapping is enough to make sure the right command will lead to the right accessory being activated.

Last, both 33880 chips are connected serially on the SPI bus, and are activated at the same time using the “~CS” line. This way, we can configure them together by writing two bytes on the SPI bus, we will see how this is done in the article on turnout controller firmware.

Driving inductive loads

You might be wondering about the absence of diodes on this circuit: since we are driving small coils, we can expect some kickback when switching them off: this is the case, but the MC33880 is designed to cope with this, as stated in its datasheet. It limits the amount of kickback to a value it can withstand and moving in the prototype phase, I checked that this was the case:

Turnout Pulse

We can easily make out the kickback spike on the image above. Zooming in – keep in mind this is a 200MHz scope, so precision is limited in such situations:

Turnout Kickback

With a 10V power supply, this leads to a short 32V kick-back. The data sheet states that “When Low-Side Drive is used, the 33880 limits the positive transient for inductive loads to 45 V” which I interpreted as a confirmation that the chip is able to manage transients with no help from additional diodes on the outside. The 32V value we read is consistent with this statement in the data sheet, and further investigations on the power bus and digital lines on the prototypes confirmed that none of this energy is sent back where we don’t want it.

Bonus!

There is not much more to say about the whole circuit, except maybe for one really cool feature: as you might have noticed on the first scope capture above, there are two steps occuring when a turnout is driven: first, power is applied to the turnout when the high-side driver is switched on. Second, voltage goes to zero when the low-side driver is switched on in turn, until we switch it off which triggers the kick-back pulse that gets dissipated into the 33880 as discussed above.

The cool feature is the following: during the time the high-side driver is switched on, the 33880 actually lets a little bit of current through the coil (about 650µA) and tests whether that pin is ‘open’ or connected to something. And it reports this on the SPI bus. This is a core feature of the 33880, which is probably very useful when that chip is used in cars, for instance, where it can then report failure of relays. In our case, this gives us a “free” way of telling whether a turnout is connected: we will leverage this in a “Diagnostics” screen on the web app. That way, if you ever encounter problems when trying to drive a turnout, you will quickly be able to tell if there is a connection problem!

Conclusion

This closes our description of turnout driving, the next article will focus on how we implement the corresponding firmware on an AVR.

But before doing this, I actually wrote a part IIIb about making an Arduino shield for basic tests.

Leave a Reply

Your email address will not be published. Required fields are marked *