Showing posts with label controller. Show all posts
Showing posts with label controller. Show all posts

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.

Sunday, 11 February 2007

Railway Electrics and Electronics

So to the electrical and electronic systems for my model railway.

Since I don't have the money for a computer controlled DCC system, I decided to use the tried and trusted methods for wiring up and controlling the layout ... with a few differences.

First and foremost I needed to convert the AC mains current to a usable DC supply. Rather than buy or build one I rummaged through the workshop and came up with an old HP power supply. This either came from an old printer or a laptop, but I remembered picking it up at a car boot sale for less than a fiver. It's output is 18V DC at 3 Amps. More than enough for such a small layout.

The image below shows the PSU installed under the station baseboard.


When using non DCC control for a layout there are a number of systems that need wiring. Firstly you need to be able to vary the output to the tracks in order to control the speed of the locos. Secondly you need to be able to isolate various track sections so that only the locomotive you are using starts to move. Any other locos on the track need to be kept stationary.

If, as in my case, you are using point motors to operate the points, these need a separate control system. I wanted push button operation for mine.

Finally there is the possibility of adding lighting and electronic signals, but I chose not to have these on such a simple layout.

When using non DCC, it is nice to have a good looking control panel, so after designing all the electrical systems on paper I set about making a control panel.

Below is a sheet of anodised aluminium I had left over from a customer job. I bought these on e-bay, just search for 'Aluminium Sheet'. A 2mm thick piece should cost no more than a few pounds.

I next drew out a 'mimic board' which follows the track plan. This allows switches and buttons to be placed in an ordered and easy to follow pattern. I then drew on sections for the various controls. Below you can see the panel part way through construction. I have drilled all the holes and mounted the isolating switches and point motor push buttons. Again these buttons and switches can all be bought on e-bay for pennies.

The next image shows the back of the panel. All these connections will have to be wired up.

Below is the final panel front. Controls have had Dymo clear labels added along with mountings for the LED indicators. The point motor indicator panel is at the bottom left, the speed, direction and inertia panel is at the bottom right and the mimic board covers the top portion of the panel. 'Maes Ifor' ( Ivor's Field), is the name I chose for my fictitious South Wales area station.
Next I built a sloping box from leftovers of the MDF used for the corner section and glued / screwed the panel to the side of the station area. This can be seen below.

The point motors are operated by two solenoid magnets which, when energised pull a bar from side to side. This in turn operates the switch on the points changing their direction. The problem with this is that if the solenoids are directly energised from the PSU the coils may not have enough 'kick' to overcome the spring on the points, and energising them for more than a few seconds will burn out the coils.

In order to get around this problem a 'capacitor discharge unit is used to store up power from the PSU and then release it in a short, powerful burst when the button is pressed. With careful design, the circuit for this can also be used to ensure that once the charge has been sent to the point motor, if the button is held down inadvertently, no further charge reaches the coils until the button is released and the capacitor re-charged.

I set about designing and building the circuit. It is a very simple circuit and quite a few examples are available on the net. I simply used components 'reclaimed' from old devices. The capacitors were reclaimed from an old TV and the power transistor was from a huge number I had left over from another job. Almost any NPN power transistor would do. For example you could substitute a 3055 MOSFET from an old amplifier instead. I will publish all the circuit diagrams that I devised for the layout in another post.

Above is the capacitor discharge unit. The two blue cylinders are the capacitors, and the other minor components on the board for the protection and control circuitry. They are all glued to the base of an old battery box.

Box cover on ......

And finally installed onto the underside of the station baseboard.

Next came the wiring for the tracks. The wires were carried through holes in the baseboard and then through tie wraps to the controller box. Below shows the start of the wiring loom. I used red and black for the fixed feeds and brown and blue for the switched feeds (isolating sections).


The image below shows the wiring loom completed. the white wires are multi-core (six core alarm cable), that I had in the workshop. these will operate the point motors that require three cables each.

You can see the main PSU and the CDU under the board. The huge mass of coiled wires laying on the top of the baseboard will all have to be terminated in the control box! At this stage it is a good idea to ensure that all the cable ends have been clearly labeled.
The next thing to do is to design, build and test a controller. I wanted one that had the option of simulated inertia and braking for more realistic operation. When I checked the prices to buy one of these units I found that they were in excess of £75.00! Some were over a hundred. I thought I could do better for about a fiver!
I also wanted a switchable option for PWM control. This is a method of 'pulsing' the power to give better slow speed control. None of the manufacturers sold a controller that offered the range of features that I wanted, so ultimately I had no choice but to construct my own.
Till next time .......