I am attempting to build a circuit to run my [HO trains](http://en.wikipedia.org/wiki/HO_scale) with a common rail. When I use this circuit LM317 works for a period of time then gets stuck at the input voltage (At that point the LM317 fails and needs to be replaced). The train draws 300 mA. The input power is a center tapped 16-0-16 transformer. The voltage adjustment at JP2-1 is a PWM signal.

The input voltage to the LM317 is 17.1 and the output after the failure is 17.0 V. Before the failure everything is operational and the output voltage varies according to the PWM input. The heat sinks are .667" × .654" × .987". The train has only been drawing less than 0.5 A. The max. voltage required by the train is 18 volts but we are only looking for approximately 17 volts as the output.

The PWM source comes from an ATmega2560. One of the problems I have is that the train layout is broken into 8 sections with separation on only one of the rails. The other rail is common to all of the tracks. This is a normal way to create a layout for HO trains, but is not as easy when creating a system of 3 power supplies that can run forward and reverse. My original plan was to use a power supply and a H-bridge, but that had problems when sending one of the trains in reverse due to the common rail.

The schematic is now black/white and if you right click the image and select view you will get an image that is full screen.

The datasheet for the LM317 does have internal thermal overlad protection and internal short-circuit current limiting.  

As to using DCC - the train layout is old with block switching. It was put away for years but now that the grandchildren are interested I thought that they could have some fun with the old set. I have read that DCC can be problematic for old trains and also they can be more challenging for the young. Thense the main reasons I am trying to stay with the common rail system. 

[![Schematic](https://i.stack.imgur.com/wSjhC.jpg)](https://i.stack.imgur.com/wSjhC.jpg)

[![Bottom of PCB](https://i.stack.imgur.com/ujuaH.jpg)](https://i.stack.imgur.com/ujuaH.jpg)

[![Top of PCB](https://i.stack.imgur.com/g10gH.jpg)](https://i.stack.imgur.com/g10gH.jpg)