Wednesday, 14 February 2007

Controller Electronics

Well, I fitted the new shower unit today without any problems. The leak appears to be from around the shower tray itself, so lots of silicone sealant and we'll now have to wait and see if it has stopped.

Due to being on-site all day I haven't had a chance to do any work on the point motor situation, so I thought I'd start on a discussion about the electronics for the controller.

Before we begin, please be aware of two things, firstly I am not an electronics engineer, nor even an electrician. All the information given here is self taught, and experience of 25 years working in industry, books are a wonderful thing and a helpful electrical expert can teach you many things (thanks Keith).
Secondly - electricity can KILL. Usually the statement given is 'mains voltages can kill', but a 12 volt car battery can deliver upwards of 40 amps, which is enough to weld steel! Believe me. I've seen an expert weld 5mm mild steel plates using a car battery, so beware!

OK, as to our controller, we need to do three things:



  • Convert the mains AC electricity to a nominal 12V DC for the locomotive motor.
  • Vary the output to the tracks from 0V to 12V with as much control as possible.
  • Be able to change direction (polarity) of the tracks
In addition it has to be cheap, simple to understand and use readily available parts.


In converting the 240V AC mains (or 110V in the US), to 12V DC (nominal) we need to either use a transformer or a switching power supply. You can build these yourself but there are so many cheap alternatives that a secondhand supply is an easy option. A used car battery charger, CB radio power supply, a printer or laptop power supply or even on old PC desktop power supply would do the trick.

The magic numbers you are looking for are an output of between 12V and 18V DC capable of supplying 1.5 Amps to 3 Amps (lower than 1 Amp will not be enough). Most PSU's used for in-car equipment run at 13.8V - ideal for our needs. For these circuits an output of 14 - 18 volts is best as will be seen.

The image below shows what would happen if we simply connected the PSU to the tracks. The only way to start and stop the loco would be to turn the PSU on and off. Also the loco would have two speeds, stopped and flat out! There is only one direction of travel since the positive and negative supplies are always connected to the same points on the motor. Not very good.




In order to alter the voltage to the tracks, and therefore the speed, we need to use a voltage divider. This is a very well known and common circuit. There is a mathematical formula for calculating voltage division, but lets forget that, in simple terms if you place a resistor between V1 and the positive side of the motor, and another between the positive side of the motor and earth, by varying the value of the resistors we can vary the positive voltage reaching the motor. If the two values of the resistors are equal, exactly half the voltage (6 volts) will reach the motor.
Obviously we don't want to keep physically changing the resistors, so we use a 'variable resistor' or potentiometer. There is one shown in the image below, these cost about £1.50 at time of writing. You need a 'linear potentiometer'.

























As you can see, there are three connections.
Inside the 'POT' there is a track of resistor material, one end is connected to one of the outer connectors, the other end to the other outer connector. The central connector is joined to a 'wiper' which moves along the track. By turning the control knob, the resistances on each side of the wiper vary, thus the output at the central wiper changes due to voltage division. Simple.

These pots are used for volume controls, gain controls, all sorts of things and are very common.

In theory, any value (given in Ohms) will work because it is the relationship in percentages between the two resistances that we are interested in. However in practice the amount of control to the loco is affected by the value. This is because we are really only interested in the voltages between about 4 volts (at which the loco starts to move) and maximum.



Here is our circuit with the pot fitted in as a speed controller. Will this circuit work then? Well, yes and no. In theory it should work at least to control the speed, but in reality it would last only a few seconds. The reason for this is that the track in the pot is very thin. In order to change the voltage, the resistor must dissipate the difference as heat. The more current drawn by the motor (in Amps) the more heat will need to be dissipated (this value is given in Watts just like a light bulb). Most pots will only sink a very small amount of current and a loco motor will force it to overheat and break very quickly.

A well run in and smooth loco motor will draw around 250mA at start up dropping back to around 100mA whilst cruising. An old sticky or stubborn motor could draw around an Amp at start up, so our circuit must allow for around 1.5A normal running.

We need to 'boost' or amplify the output from the POT so that it is not destroyed. Enter the transistor. This acts as an amplifier, a switch and a gate valve all in one. Pictured below is a very common transistor, the 2N2222A. This is a 'small signal' transistor, which has very fast switching and good amplification. They are small and cost pennies.



















The transistor has three connectors, the 'Base' which in our case acts as the control connector, the 'Collector' which takes the incoming current, and the 'Emitter' which gives the outgoing current.

The transistor will take 0.7v from the circuit to operate, we must allow for this 'Tax' in calculating the final output. As the potentiometer output voltage reaches 0.7v the transistor 'turns on' and starts to pass current from the collector to the emitter, as you can see from the diagram below, this bypasses the potentiometer and protects it from burning out.
As the voltage at the base of the transistor increases, so the output at the emitter increases, always 0.7v below the input voltage. So over all our 12V output will now only be 11.3V, additional transistors will add to this effectively dropping the final output, hence the requirement for a PSU between 14 and 18 Volts.

Here is the diagram with the 2N2222 fitted. So will this circuit work? Again yes and no. The 2N2222 is only capable of sinking around 800mA, and we need 1.5A. The reason for using this transistor is its good amplification, and fast switching.


















What we are going to need for the final output stage is a power transistor capable of sinking more power.

As you can also see, there is still only one direction of travel, this will be dealt with right at the end.

So far the total cost of our circuit, if we allow for some hook up wire and a bit of strip board to build it on, has reached the grand total of £2.00

Next we shall add a power transistor, this is fed off the 2N2222 in the same way as the potentiometer fed the first transistor. This configuration is known as a ' Darlington Pair' and is one of the most common transistor circuits used in electronics.

















In the new circuit diagram you can see the addition of a 2N3055 power transistor. The only reason I chose it was because I had taken one out of an old amplifier when I was designing my circuit. A better choice for our application could be a TIP 41a. These are cheaper, smaller and easier to fit than the 3055. Again they cost pennies.


You will need to use a small heat sink for the power transistor. Heat sinks are available for all power transistors, these range from a small flat plate of metal to huge elaborate finned contraptions. You only need a small one to help dissipate some of the heat. If you reclaim a transistor from an old, broken bit of gear, then the chances are that it will already have the heat sink attached.

Next - direction of travel. Reversing the polarity at the tracks is very simple. The outputs from the controller are wired through a Double Pole Double Throw (DPDT) switch. You only need a miniature toggle switch (about £1.00).

Here's one.























To incorporate it into our circuit, you wire the two outputs to the centre two connectors on the switch, wire two new outputs to one pair of end connections on the switch then wire a crossover between the four outer connectors. Trowing the switch now reverses the polarity.
The addition of a small value resistor ahead of the base of Q1 acts as a protection for both the track on the pot and the base on the transistor.















Here is the final diagram of the super simple controller. S1 and S2 are the DPDT switch.
So will this one work? Well yes and no.

I use one of these to carry out very basic running tests because it's so small and cheap. It is perfectly capable of driving a loco, and using a 10K pot it is fairly controllable. So whats wrong with it? Well there's no on off switch for a start, there's no overload cut out, there's no indicators as to whats going on and very slow speed running can be a little erratic. For the overload protection you could use a 1A fuse in the positive rail of the output from Q2. If you use a refittable type than you can just change it if it blows.

Fitting a SPST switch into the input from the PSU will give an on off switch. Fit an LED with a 1K resistor behind the switch and across the negative rail for an on off indicator.

Very slow running will always be an issue, one I'll discuss in the next post.

Bear in mind with this circuit the following when choosing the value of the pot:

12V electric motors, like all electric motors are designed to run at maximum torque and maximum power when fed with the recommended voltage. The motor designer will then build in some overload allowance such that our little loco motor will probably accept 15 - 16V before it starts to complain. The designer will also take into account that there needs to be some slower speed running so its a compromise.

If we say that at 16V the loco will be doing the equivalent of 125mph, then the vast majority of running is done at a speed nearer a third of that (around 5V) and shunting at even less (say 3V). The motor designer cannot possibly allow for that amount of variation and still have the motor run at full torque. Most locos need around 4V just to start moving, or the electronics in the controller need to give it a 'kick' start, then once on the move the speed can be turned down a bit.

Now, since the circuits transistors are taxing 1.4V before there is any output at the tracks, and the loco needs around 4V to start moving, the voltage divider has to be supplying 5.4V before anything happens. For a 12V system this means that the control knob is going to be at nearly half way before it start to move the train!

I tested loads of pots with values from 100 Ohms to 2 Mega Ohms (2 million Ohms). The higher the value the further I had to advance the control before the train moved, if the value was too low full speed was reached too early. I suggest you try values from 1K Ohms to about 20K Ohms for your pot. This range seems to give the best control over the 4 - 12V we want. You can bias the circuit with an additional resistor between the pot and the negative (earth) rail so that the pot begins to operate earlier. Experiment!

Next time, the capacitor discharge unit for the point motors, the overload protection circuit and simulated inertia and braking.

No comments: