How to drive train models
#1
Posted 30 March 2012 - 09:36 PM
#2
Posted 31 March 2012 - 07:59 AM
If I understand your project correctly, you are trying to control a lots of ON/OFF devices that use 16V AC, but you are not trying to control the locomotives with a variable power. Some of the devices need a pulse "rail exchange" (point / turnout motors), others need to stay ON for a long time (lights / traffic lights).
Since you are trying to control AC devices, the most straight forward way would be to use some small relays. These will allow you to control AC using the Netduino's DC outputs.
There are two halves of a relay to consider: the coil and the contacts (the switch).
Coil:
Most relay coils can be driven with DC, and this is what we want. There are a wide range of coil voltages available. Since you will need to use a transistor to drive the relay coil (this protects the Netduino), the coil voltage is not too important. What you should do is find out what DC voltages are available on the model railway. For example, there might be 5V DC, 9V DC, 12V DC or 16V DC, etc. Once you know what is available, you can select one voltage and look for relays that have a matching coil voltage.
Most small relays will be able to control 16V AC. I imagine that the current (Amps) required will not be very large, so again most small relays will be OK. You need to find out how much current the motors and lights use, and check that any relay you select is suitable.
Most relays have changeover contacts, these could be useful for controlling devices like the traffic lights. For example, when the relay is ON, the relay could power the Green light, when it is OFF, the relay would power the Red light. For a point motor, you would need two relays one for each direction. You don't need change over contacts for this; if the relay is not changeover, make sure it relay has a Normally Open "N.O." contact.
For the point motors, you only want to deliver a pulse of current. This will either mean having the software pulse the relay ON and then OFF, or building an electronic timer circuit (e.g. using a 555-timer). There is one other possibility, doing a Google search I believe there are some relays that have momentary contacts. I imagine these will be hard to find and possibly expensive - but worth considering.
So, find out how much current each device needs, find out what DC supply voltages are available. Then try and select some suitable relays. Once you know which relays you are using, then you can design the transistor circuit.
I have not done much with SPI and I2C, so I'll let someone else answer for that. Be careful about the startup condition of any device you use. For example, make sure that the relays don't all turn on when the power is first connected to the railway - this might be disastrous.
(Your English is great - I hope I have not used too many strange words!)
Hope this gets you started - Paul
#3
Posted 31 March 2012 - 10:16 AM
#4
Posted 31 March 2012 - 12:26 PM
Paul gave you an excellent panoramic about how to move in your project.
I'd add something about the "AC" doubt, because a while ago I was wondering your same question.
Most of the railroad model manufacturers chosen to switch from DC (in the past) to AC, essentially because there are few problems of polatiry when you have very large tracks. Moreover, in the past the DC polarity was the only way to drive back and forth a loco, but...what if you have two or more locos on the same track?...Thus the DC became uselessly.
If you check, the whole track is always powered at 16VAC, then every loco embeds a small microcontroller that converts the driving signals to concrete actions, such as the motor speed, direction, and the lights. As for "signals" I guess there are two kinds: infrared and CAN. The latest is "running" over the AC power.
About the (AC) relays for the track exchange (scambio), I am *NOT* sure, but to change direction you probably need just a short pulse, half a second should be enough, I suppose. You might check for that, because if it works, you could dramatically simplify the remote driving by using DC, which is much simpler (and cheaper) than using AC.
Please, also notice that 16V (AC) is the RMS (=Root mean square) of the actual peak of the sine wave. Just try with a normal 9V battery: it's much below the needing, but it should work at least for an experiment. If you have any +12VDC supply, it's better.
Finally, I do *NOT* suggest the I2C. That's because it's an (awesome) bus, but it's not targeted for long wiring, nor for "noisy" environments, such where are motors, AC, etc. If you wish to transfer the data "far" from the central command, the best way would be the CAN bus, but is an overkill.
At this point the question is mandatory: which brand of railroad are you planning to drive?
A couple of months ago I was able to remotely drive a Maerkiln loco using IR and a Netduino.
http://highfieldtale...r-for-netduino/
Ciao.
#5
Posted 31 March 2012 - 01:48 PM
I had a point motor on a Hornby OO-gauge railway, it was 12V DC, and also had three wires: left, right, common.
It came with a switch that looked like a lever in a signal box. As the lever was pushed from one end to the other it would connect either the left or the right wire as it passed through the middle. This sent a short pulse of current for about half a second (as Mario suggested) to one of the coils in the motor.
Just to clarify, I was suggesting that you use a relay to switch the AC to the point motors, but that you use DC to drive the relay coil. This is done often with Netduinos (via a transistor) and is safe to do.
I agree with Mario, I think you should be able to drive the point motors with DC (but using a lower voltage) - try a 9V battery and see if the track moves with a short pulse of current. If it does you could skip the relays altogether and just use transistors to drive the motors - much simpler.
The warnings you found on the internet are probably because of the risk of leaving the motor coil connected to the current. If you are using DC to drive the point motor and the switch (relay) gets left ON accidentally, a high current will flow in the coil and this could damage it. If you are using AC, then the current will not build up as much in the coil and so it is less likely that the coil will overheat and be damaged.
Remember to consider how you will attach the new circuit to the existing wiring. What happens if the Netduino stops working? If you have chosen relays, you can connect them "across" the existing switches so that your friend can use Netduino or manual control with out changing anything.
So there is a choice to make here - are you happy driving the point motors with DC and saving two relays per point, or would you like to stick with AC? I do like the idea of using less relays, but I also like the idea of having Netduino/manual control.
Since your lights are LEDs, then you don't need relays to drive them. Stefan has a web page about using 74HC595 shift registers to drive outputs. (I am using a single 74HC595 to drive a set of 8 LEDs.)
This would be a reasonable way to drive lots of LEDs (with resistors) in groups of 8 LEDs. BUT, I am not sure how well the SPI will work on a noisy railway circuit.
The last problem is the most fun! Controlling the locomotives.
If we assume your observation is correct, then the locomotives use DC voltage to drive their motors, and if you reverse the polarity, the train goes backwards.
My old Hornby system had a knob that rotated clockwise for forward and anticlockwise for backwards. It was a big variable resistor and a clever switch all in one.
I have another power supply that has a simple knob and forward-backward switch to swap the polarity.
There are lots of ways to drive DC motors, often it is done using "PWM" Pulse Width Modulation. The Netduino has four PWM outputs, it can be configured to turn each output ON for a given pulse length every period. When the pulse is ON, it is used to turn ON a pair of transistors that supply current to the rails. When a short period is used, the pulse length will control the speed of the motor. A separate Netduino output is used to select a different direction by selecting two other transistors.
The transistors come in a single chip e.g. "L298" called a "bridge":
There are shields (just one example) already made up that you could use.
Did you spot the problem? - The Netduino only has 4 PWM outputs, so you might need to use a PWM shield to get enough PWM outputs for your 5 sets of rails.
Lots of questions - and even more answers!
Hope this helps - Paul
#6
Posted 31 March 2012 - 04:48 PM
#7
Posted 31 March 2012 - 07:58 PM
#8
Posted 04 April 2012 - 02:48 PM
After reading books, googling around, I decided to start from the first problem (probably the easy one): controlling a lot of leds or similar devices on a wide surface (10 meters x 4 meters). Since actually there are really a lot of wires and cables, I think that using shift registers chain-linked each other and put in smart positions can save a lot of these cables.
This simple drawing can give the idea, I hope: the shift registers act as local 'pits' where to connect leds to, so I need only a three wires cable going all around, and the local (short) connection to peripherals.
Moreover, I think that netduino cannot power everything, so I'll have to add a power line going all around, and transistors to act as switches to activate the single peripheral, when put on.
It looks like it can become all very clean and simple, if this is a feasible solution...
Before starting testing, I would like some good advice, if possible: thanks in advance, as always!
Andrea
#9
Posted 04 April 2012 - 07:57 PM
"Maybe it's because you're a crap programmer"
#10
Posted 04 April 2012 - 08:37 PM
#11
Posted 04 April 2012 - 08:39 PM
#12
Posted 04 April 2012 - 09:10 PM
Yes, each 74HC595 would act as a connection point for a set of up to 8 LEDs. You might put each one (or multiples) in a small plastic box with some screw terminals for the LED connections.
In your diagram you show a closed loop. The shift registers would actually be connected in a long chain rather than a loop.
I don't think you will need any transistors if the loads you are driving are LEDs. I am using a 74HC595 with 8 standard LEDs without any issues. Having said that, you might need to use a transistor to drive high current LEDs or some blue/white LEDs that use a higher voltage.
When it comes to wiring it all up, I think you will probably need 6 wires (but you may want to add more):
- Ground,
- Power (one of 3.3V / 5V / 9V / etc),
- reset,
- serial clock (SPCK),
- serial data (MOSI),
- strobe/latch.
The reset is important if you want to ensure the shift register outputs can all be turned off at power on or when the user presses the reset button. If not there might be a few seconds of delay before the Netduino clears them at startup. Alternatively you could use a simple electrical circuit at each shift register "pit" to hold the 74HC595 reset line low as the power is turned on.
The clock, data and latch are the standard signals you must have to use SPI.
You might want to add another serial data line (MISO) to allow future expansion where you read inputs.
There is a big decision to make for selecting the power supply voltage to take to each block.
- The simple option would be to use the 3.3V output from the Netduino, but this has a limited output current and will not allow any flexibility with higher voltage loads. (You could use this initially to just get started.)
- Supplying the power from another source will allow you to supply more current to the LEDs - this will be essential given the number you are trying to drive. To do this you need to make sure that the shift registers and the Netduino use the same ground.
- Using a higher voltage will allow those higher voltage loads if they are necessary - but you will need to provide a 3.3V regulator for each 74HC595 to reduce the logic supply voltage down to 3.3V.
- You could have a hybrid - take two power wires around the circuit, the first 3.3V from the Netduino for the shift registers, the second a higher voltage (and current) for the LEDs. This would however require that you use a transistor for each output.
Even more to think about - but it is all quite straight forward. Start off simple with a test circuit based on Stefan's wiring diagram and try out driving a small set of LEDs.
Paul
#13
Posted 04 April 2012 - 10:11 PM
#14
Posted 05 April 2012 - 03:59 AM
#15
Posted 05 April 2012 - 05:46 AM
#17
Posted 05 April 2012 - 07:19 AM
Mario,
Thanks for stepping in. I was not sure whether the noise would prevent SPI working.
Do you think it might be possible to use RS422/485 drivers to carry the clock, data and strobe?
Paul
Hello Paul, and many thanks for your excellent proposals: they deserve a bit better light, such as in the Wiki section, for instance.
The noise is perhaps the secondary problem involving problems in a long wired SPI. The first one is surely the not-adapted impedance.
It's a complex task, but I'll try to show a brief explanation.
You know, any waveform shape could be seen as a composition of sine waves, so called "harmonics". That's what basically Mr. Fourier explained a couple of centuries ago.
As it were a stainless steel string, the current/voltage can reach a stationary frequency, also called "resonance".
Since the SPI is a kind of "square wave" (i.e. full of sharp edges), the involved harmonics are decaying very slow on the spectrum (as 1/N), thus even a 100MHz component could be somewhat important.
When you are dealing with short wiring, the effect of the resonance could be insignificant, and your circuit works all the times.
Now, let's take a steel string (e.g. a guitar string). It's tight fixed on both edges, so there's no vibration on these points: only in the middle.
What if you take a steel stick, fixed on one edge only? The free edge is vibrating.
Now let's compare a "fixed" edge, to a point where the voltage is kept stable. For instance an output port. The logic imposes a voltage on that out, and you should make an effort to "move" that voltage.
At contrary, on an input, there's no "fixing", and the voltage is free to "move".
Whereas the delay/period (or whatever you want to call it) of this "resonance" could be significant, the related signals are not "adapted", and the actual signal will be distorted.
This could help: http://en.wikipedia...._of_electricity
There are other factors involving problems, but they are easily solved. The only "real" problem is that the cost will get higher!
Main factors to improve the communication:
- low-impedance;
- low-speed;
- low-noise (good immunity);
- good protocol.
Cheers
#18
Posted 05 April 2012 - 09:42 AM
#19
Posted 05 April 2012 - 11:38 AM
#20
Posted 05 April 2012 - 12:22 PM
Apart from this, I don't want to throw anything away, I'm not that kind of guy... only, I'll have to study much more, and understand how I can solve the problem: challenges are made to be solved! :-)
Done with Paint, here is an image of how the model is: 10mx4m, there are a lot of different devices to control (the image cannot convey how many different, and small, electric devices there are), and my friend kept adding every single device, linking cables from any single device to the control center.
So, other than the wires, other problems are all the power adapters (from 220VAC to 9V, to 12V, to 6V, to 16VAC..., many for each voltage), buttons, pulse buttons...
And he would like to go on adding other devices, so reordering things, finding a different solution than the brute force, is becoming NOT an option!
I was pretty sure that I could send signals over a 10meters span, it didn't look a so great distance, but I believe in you, so I only have to explore other possibile solutions!
Andrea
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users