Please help, train control problem

djh82uk

Member
Hey guys, ok my father is really into his model railway stuff, for those that don't know, most modern model railway systems use a system called DCC, whereby 0v and 16V are constantly sent through the track, then each train has a decoder which receives a signal through through the track which tells the decoder how fast to make the train go, how to stop and how to control the lights. Each decoder has it's own address which allows like 5 trains to be running at once.

Now these systems can be expensive, many different companies make different versions, but all tend to use the NMRA protocol for communications.

Now I want to make something similar but much cheaper, I want it to be PC controlled, and it will no be using the NMRA protocol.

Now I here is how I was going to have it setup.

I want a power supply to power the tracks (no big problem), I need a command circuit connected to the PC (no big problem) and a very small circuit on the train to control lights and motor etc via FETs.

The command and train circuits I want to be picaxe controlled for simplicity.

My problem is, how do i send, 0v, 16V and a serial signal down just 2 tracks? Is there anyway of doing it?

The only other idea i could think of was to switch off power to the tracks while a serial signal is being sent, so how long does it take to send the serial signal? as I guess that would depend if it is possible as it would be no good if it noticably affects the train, but then the picaxe on the train will not have any power to run itself, remembering this circut must be very small.

I will eventualyl then make a PC program hopefully to control it all via the PC.

My only big problem at the moment is sending the signal down the track. Any ideas? Any was of making a filter or something?

Your thoughts would be greatly appreciated

Regards

DJH
 

xstamp

Senior Member
One way to do this would be to use an audio transformer to superimpose frequency shift key (FSK) data onto the DC rail supply. You would need a miniature audio transformer on the train to extract these audio tones from the rail supply. The main challenge would be rejecting the motor noise from the signal but fortunately your data rate can be real slow and narrow filters can be used at the receiver. I would suggest using single chip 300bpi FSK modems at either end of the rail link as this would be directly compatible with the PICXE serial port and need no special communications software. A good source of information on this type of technique can be found by doing a web search for X-10 technology, as this is a home automation standard for sending data over mains power lines.

 

ljg

New Member
A possibly simpler method would be to send PWM power and signal down the tracks at 16 volts

use a rectifier for the Power, and read the PWM with a optical isolator.
 

hippy

Ex-Staff (retired)
Given the work which has gone in to NMRA DCC and the number of homebrew projects which utilise it, something based around DCC would seem to be the way to go.

DCC appears to rely upon switching between +V/0V and 0V/-V ( or maybe +V/0V and -V/0V ) and the switching is used to indicate bits being sent down the track. The trains get their DC voltage by using a simple bridge rectifier. The beauty of the DCC system is that trains are always powered.

Power controllers which can generate these switching voltages are readily available commercially or homebuilt and it would make sense to use those to put signals on the track like DCC does but at a speed which the PICAXE can deal with. I can't see any reason why the signal controlling the track polarity can't be driven from the serial out of a PICAXE, with the train PICAXE decoding the signal straight back to serial in.

Details of the actual DCC protocol can be found here ...

http://www.dcc.info/standards_rps

A simple PICmicro DCC transmitter and DCC decoder can be found here ...

http://technology.niagarac.on.ca/staff/mcsele/dcc.htm

Note in the decoder, the bridge rectifier to create +5V/0V, and the 22K resistor used to get High/Low serial bits in just like in the standard PICAXE download interface. Google offers up similar circuits.

With that setup, PICAXE using SEROUT through the interface to a genuine DCC controller PSU, and a PICAXE in the train, there should be little else to worry about. The DCC protocol is actually byte oriented, so you can handle genuine DCC compatible commands which should allow PC-based track control software to be used with little effort.
 

hippy

Ex-Staff (retired)
You can try prototyping track control using two PICAXE-08's and a 74HC04 Hex Invertor or similar to see if it will work. If it does, all you need to do is replace the 74HC04 with something which can switch the track voltage at greater than 5V and delivers more than a few mA of current, plus add a 5V regulator in the receiver. Note that the receiver is only connected to the transmitter via the 'track'.
Code:
5V--.                                      10K     .----------.------------.
    |                                      ___     |          |            |
.---^---.                           .-----|___|----|--.   .---^---.      __|__
|       |     |\    |\              |              |  |   |       |      =====
|    O1 |--.--| >O--| >O--( ==== )--^--.---|>|--.--'  `-->| I2 O1 |---.    |
|       |  |  |/    |/                 |        |         |       |   |    |
|       |  |                           `---|<|--|--.      |       |   R    |
`---.---'  |               'Track'              |  |      `---.---'  _|_   |
    |      |                           .---|>|--'  |          |     _\ /_  |
    |      |        |\                 |           |          |  LED  |    |
0V--'      `--------| >O--( ==== )-----^---|<|-----^----------^-------^----'
                    |/
Code:
Transmitter:
  b0 = $00                              ; Send LED Off Command
  GOSUB SendCommand
  b0 = $01                              ; Send LED On Command
  GOSUB SendCommand
  GOTO Transmitter
SendCommand:
  b1 = b0 ^ $FF
  SEROUT 1,N2400,($AA,b0,b1,$55)
  PAUSE 1000
  RETURN
Code:
Receiver:
  SERIN 2,N2400,($AA),b0,b1,b2          ; Get Packet
  IF b2 <> $55 THEN Receiver            ; Framing Error
  b1 = b1 ^ $FF                         ; Determine Checksum
  IF b0 <> b1 THEN Receiver             ; Invalid Checksum
  IF b0 = $00 THEN LedOff               ; LED On command
  IF b0 = $01 THEN LedOn                ; LED Off command
  GOTO Receiver                         ; Unknown Command
LedOff:
  LOW 1                                 ; Turn LED Off
  GOTO Receiver
LedOn:
  HIGH 1                                ; Turn LED On
  GOTO Receiver
Edited by - hippy on 23/07/2006 21:19:09
 
Last edited:

djh82uk

Member
Thanks guys thats great, i like your idea hippy.

I have been looking at this:

http://www.minidcc.com/628schematic.gif

It seems his pic is directly connected to the input on the booster/power supply so I can see how a picaxe can send serout commands as they are at a TTL level?

so the booster uses a bi-polar supply down the track, the rectifier takes this and gives a constant voltage for the motor which could be controlled via a fet and motor control IC?

The only thing I am wondering is if the booster sends the polarity changed in such a way they can be converted back to serin, I am guessing they can, but what converts it back to something that the picaxe can understand, thats all im confused about I think.

I am not that clever with this stuff, but I am hoping it will help me to learn. I guess i should start making a booster/PSu circuit.

Regards

DJH
 

hippy

Ex-Staff (retired)
Take a look at this ...

http://home.cogeco.ca/~rpaisley4/MyDCC.html

Should have realised ... Ignoring what's on the tracks, the driving signal is exactly what is churned out by a motor control H-Bridge channel.

So all you need is a hefty DC power supply, H-Bridge, TTL to H-Bridge level conversion, and the over-current cut-out. That simplifies things quite a bit.
 

Mycroft2152

Senior Member
Neat project, your dad will be thrilled.

There is a good example at the bottom of the page of Professor Csele's DCC decoder circuit. It shows how power and signals are taken from the track to the PIC decoder.

http://technology.niagarac.on.ca/staff/mcsele/dcc.htm

The lower left portion of the schematic has the circuit.

Your booster circuit will need the capability of also powering the train's motors. A driver that provides at least a couple of amps is needed.

Myc



Myc

 

djh82uk

Member
yeh, he he, I rather him getting me to do this than trying to fit led's in silly small places, ive converting cars (smaller than matchbox) to have flashing blue lights and headlights/breaklights all week.

so hippy this h-bridge and ttl - hbridge is basically what the booster does? while supply a good few amps too?

Average train seems to be about 0.2A I think, not much more anyway, but is a big layout and so a good 5A supply?

DJH

DJH
 

hippy

Ex-Staff (retired)
Myc : Thanks, I hadn't twigged that what is at the bottom-left of that first diagram was the PICmicro to track interface in its entirety - Eyesight not what is was !

DJH : You have inadvertently solved a problem I have been contemplating for a while - How to send serial and power to a PICAXE-08 alarm clock ( it just beeps until shaken ! ) which doesn't have an RTC and will need synchronising each day. Using the 74HC04 method I can run power plus PC serial straight to it up just two wires. Bingo. Thanks.
 

djh82uk

Member
oh btw, This H-bridge says it has Cmos and TTl input pins, so does that mean it converts the serout commands to polarity changes (bipolar)?

So would I just send normal serout commands, and how would the picaxe on the train convert them back?
 

Mycroft2152

Senior Member
After sleeping on it, here are a few thoughts on your train project.

Start simply, breakdown the project into simple blocks that can be breadboarded and tested.

Make a list of the things you want to do on the the train. Do you want all the PICAXE modules on all the trains to do the same thing or do you want to have each PICAXE module do something different? You'll need to assign a letter or number code to each function / module.

Set up 2 picaxes to communicate directly (forget about the track interface) and make the PICAXE#2 (on the train) do what you need using your defined code.

After that is done, then and only then, build the track interface and connect the working PICAXE system to it.

Finally, remember the quirk with PICAXE serial communication, everything stops while the PICAXE is waiting for the next serial input. This could be a real problem.

I've never looked at model train motors, but I am wondering if a non-Dcc equipped locomotive can be run at different speeds on a DCC track.

Is the speed on non-DCC tracks controlled by voltage changes or by limiting the currrent on the track?

Myc
 

djh82uk

Member
Hiya

Well I see it consisting of 3 parts, the train decoder, the command circuit and the psu/booster. The track will always have +12v and the decoder simply varies the voltage it gives to the motor.

I see what you mean by the problem of the picaxe not doing anything while waiting for serin.

Basically each decoder will have it's own address, so i guess it will have to take every serout from the command circuit, and check if the transmitted address matches it's own.


Each decoder will control the motor and the cab lights.

The booster/psu should be easily done as I have found various plans.

My only problem big problem now is as you say that the picaxe will not do anything while waiting for a serin.

Is it not able to carry on what it was doing before? Say it was told to output a certain speed (pwm), and then it waits for a serin, will than motor stop?

If so that is deffo going to be an issue.

DJH

 

Mycroft2152

Senior Member
There is actually a fourth part, the command center to send the control info. The plans you referred to earlier had a hex keypad and LCD screen.

You will need to send at least 2 characters, one for the address of the module and the secpond one for the action needed. Three, if you want to specify Speed 50%. If you look at the standard protocol, it is only 4 characters and may give you some ideas.

I think the PWM will continue when looking for serial input as well as any output states, but haven't tried it. Any help on this guys?

Again, break the project down into manageable bites and BREADBOARD it. It may be fun to start building right away, but you will have to spend a lot of time fixing problems later.

Myc
 

djh82uk

Member
Good point, i was initially going to interface the command circuit to a PC, and send it commands via hyperterm, then try learning a bit of VB or something easier to have some sort of program to send the info, only when that was all working was I going to try a standalone unit with lcd/pad etc.

I was going to get 2 18 project boards and get them talking first to control a motor and lights.

Then i was going to breadboard the circuits as i require them, then make the pcb's. the decoder side has to be small so I will be using surface mount components mainly.

while those 2 are at breadboard stage and talking to each other, i will then work on breadboarding the booster/h-bridge circuit, and then try to get them talking down the train track.

Once all is working I will finalise the code and come up with some sort of final protocol.

I am currently un-employed so Im going to have to wait to buy all the components etc, but hopefully that will be soon.

This all depends on whether the outputs are left unchanged when using serin, if so then it can just keep doing the last command while waiting for the next input.

Im really interested in getting to work on this project as once I have it all going I want to implement other things such as train tracking, automatic stopping at signals etc.

DJH
 

djh82uk

Member
Actually, just realise I have a 18 project board here, as well as an 18x and 18a picaxe, so i could use one project board and make up the other on stripboard.

Obviously the decoder will not be complete as it will not have the bridge rectifier etc

DJH
 

Mycroft2152

Senior Member
You may be able to use a PICAXE 08M on the train. Much smaller, even surface mount.

If you have an old PDA floating around, you could convert it to the command console. they also can be used as a quick and dirty serial display/keyboad. Hippy has a link.

Myc
 

djh82uk

Member
yes the pda is a nice idea as is the 08m, if hippy could paste the link would love to see what pda's would work, I have a dell axim lying around somewhere

DJH
 

hippy

Ex-Staff (retired)
PWMOUT should run while waiting for SERIN because it's entirely generated in hardware so won't interfere with the bit-bang timing for serial.

As for a link to a PDA interface, I'm not sure I ever had one, but it could be my mind which is going :)
 

eclectic

Moderator
DJ

This link is NOT for a Dell, but might help;

Home
Links
Stan Swan

then look for &quot;Casio&quot; in blue text.

e.
 

djh82uk

Member
He he, eclectic, you did not post a link?

Hippy, thanks for that, makes me think it can be done without too many problems.

Thanks Guys

DJH
 
Top