Sunday, March 23, 2014

Motive Power

Those of you who have been reading this blog for a while, might remember that the main motivation behind modelling Jerusalem in N gauge was that I wanted a roundy-roundy layout where I could just watch the trains go by, as I'm not really into the whole shunting business. This preference for just sitting back and watching the trains hasn't changed which leaves me with a bit of a problem, as the new layout is so narrow that it could only ever support an out and back style track plan and personally constantly turning the controller on and off to operate such a layout sounds seriously tedious. To try and solve this problem I've been experimenting with some electronics to see if I can control the layout automatically for those times when I just want to sit back and watch.

What you can see here is my first attempt at controlling the locomotive automatically. The basic idea is that it simply runs the train in one direction for 2 seconds, stops the locomotive, waits for a second, and then runs in the other direction for 2 seconds before repeating the process indefinitely; currently for some reason the locomotive travels faster and hence further in reverse than when going forwards, even though the power supplied is the same.

Given that this isn't a post on my code/electronics blog I'm not going to go into the full details here, but essentially I'm using an Arduino UNO with a L293DNE integrated circuit acting as a H-bridge to provide power to the tracks (the messy collection of wires to the left of the track). Power comes from standard transformer that provides 12V DC at 1.5A, and the speed of the locomotive is set by using pulse-width-modulation (PWM) to vary the duty cycle of the output (i.e. the percentage of the time the power is on versus off). This arrangement seems to work reasonably well, although I have found that the Kato chassis doesn't work as well as I'd hoped at low speed (even with a standard DC controller), although adding some weight to the body shell in the form of Liquid Gravity has helped a little. Interestingly if I put my N gauge locomotive onto the track it performs much better at slow speed. Does anyone have any hints on getting the best out of the Kato chassis (it's model number 11-104)?

Of course basing the change on direction on time is never going to be particularly accurate, especially given that the speed seems to change based on direction, so in practice I'll need some way of determining when the locomotive should stop and reverse direction. My current plan is to re-use some of the ideas from my scale speed trap to sense the presence of the loco at certain points on the layout and then react accordingly.

4 comments:

  1. This looks good Mark, Can't you just programme the PWM differently for forward and reverse? I would just drop a couple of resistors into the reverse power side of things. If I was working on this scale I'd look at servo motors which are cheapish for RC control, or maybe a stepping motor from an old CD drive. They can shuffle along or not.

    ReplyDelete
    Replies
    1. Yes, I could easily have different PWM values for forward and reverse, and in fact it's likely to be even more complex as I'm guessing each locomotive is going to need different settings as well, as the motors in them will all be different. My current plan of attack will be to have some way of telling the circuit which loco is in use, and then a lookup table of PWM values for forward and reverse. In theory I'd like for the circuit to be self contained, but I could of course write an interface to run on the PC as well to make selecting locomotives, and PWM values, even easier.

      Delete
    2. Mark, I'm really dredging what is left of my grey cells. The arduino uses a square wave. With pulse width modulation there is a system to produce a sine wave. It has lots of square waves contained within two sine wave limiters. I can't remember what it's called and suspect I never knew. It may make for a better low speed performance.

      Delete
  2. Sometimes I wish that I were a lot taller.

    ReplyDelete