| A PICAXE based Model Railway Controller | |
| ||
|
The designs on this page are presented "as is" with no warranty or guarantee of operational correctness. The electronic design has not been built, tested nor proven, and there is no guarantee that the designs are sound or that damage will not occur when used with your own equipment. The software has not been tested, debugged and may not include the functionality described in this article. Anyone using the hardware and software designs or information related to them herein does so entirely at their own risk. No liability whatsoever is accepted by the author. This project is a theoretical exercise and a work in progress and should be considered as an educational resource rather than as a completed or functional project. | ||
|
This article describes the design of a PICAXE based model railway controller
for the control of ancillary systems ( points, signals and lighting ) rather
than trains themselves.
The entire system is based upon a network of PICAXE-08 processors linked to a
master controller through a serial bus. Every PICAXE-08 is a receiver module
which receives commands from the controller which can manipulate the four
output lines from each receiver. Each line can be set high, low or pulsed,
individually or in combination with each other.
This article does not consider how the receivers are connected to additional
hardware to perform their intended tasks ( such as providing the correct
voltage to activate points solenoids ), but it does detail the rest of the
system.
The Network ProtocolThere are two protocols; that between the PC and main controller and that used between the controller and the receivers. The PC to controller protocol is a character based ( command line ) interface and is discussed later. The protocol between the controller and the receivers is a binary, packet-based protocol and is explained here.The controller communicates with the receivers by sending packets of data which are received by all receivers. Every packet contains an address and an action to take; those receivers who recognise the address will take the action requested, while those which do not will simply ignore it. The protocol is extremely simply; send-and-forget, with no error checking capability, no acknowledgements that the packet was received and no retry mechanism. Whether the protocol is robust in real world use or not is a matter of conjecture as I have absolutely no experience of model railways, their control systems or knowledge of issues which affect track electronics. This article is intended to show a design which is flexible and works in ideal circumstances, but it may be necessary to improve upon it to provide a more robust practical implementation. That is however beyond the scope of this article. All commands are three bytes long, with two nibbles in each byte, giving a six nibble command in total ...
.-------------.-------------.-------------.
| aaaa | bbbb | cccc | dddd | wxyz | WXYZ |
`-------------^-------------^-------------'
The first four nibbles 'abcd' are the address of the receiver module which is required to respond to the command. The address is compared with that which set in each receiver using 'SYMBOL UNIT_ADDRESS = ', and if the address matches the action is obeyed. If any of the nibbles of the address are zero, it is considered a 'wildcard digit' and any digit in the same position with the receiver's address will be treated as matched with it. This allows 'wildcard addressing' so a single action can be sent to multiple receivers. The addressing scheme allows 50,625 separate and uniquely identified receiver modules to used on a single network. Over 200,000 lights, 100,000 points and 50,000 signals can be controlled by a single network. Any receiver module can be used to control lights, points and signals. Every command includes an action byte, two nibbles which indicates what the receiver should do when the command is received ...
action
.-------------.
| wxyz | WXYZ |
`-------------'
The bits of each nibble 'wxyz' and 'WXYZ' relate to each of the receiver units digital outputs; w/W is OUT4, x/X is OUT2, y/Y is OUT2 and z/Z is OUT1. When a bit is set (1) in 'wxyz' the corresponding output bit is set high. When a bit is set (1) in 'WXYZ' the corresponding output bit is set low. When a bit is set (1) in both 'wxyz' and 'WXYZ' the corresponding output bit is set high for a period defined by 'SYMBOL PULSE_LENGTH' within that receiver module and is then set low again. Examples ...
.-------------.
| 1000 | 0000 | Sets OUT4 high
`-------------'
.-------------.
| 0000 | 0100 | Sets OUT3 low
`-------------'
.-------------.
| 0000 | 1111 | Sets OUT4, OUT3, OUT2 and OUT1 low
`-------------'
.-------------.
| 1010 | 1001 | Pulses OUT4, sets OUT2 high and sets OUT1 low
`-------------'
.-------------.
| 0000 | 0000 | No changes made
`-------------'
For specific point and signal configurations, the following commands could be used ... Points - OUT1/OUT2 to solenoids, OUT3/OUT4 routing indicators
0101 1011 Pulse OUT1, set OUT3, clear OUT4
1010 0111 Pulse OUT2, clear OUT3, set OUT4
Dual Points - OUT1/OUT2 to solenoids #1, OUT3/OUT4 to solenoids #2
0001 0011 Pulse OUT1 - Points #1 through
0010 0011 Pulse OUT2 - Points #1 turned
0100 1100 Pulse OUT3 - Points #2 through
1000 1100 Pulse OUT4 - Points #2 turned
Three light signals - OUT1=Red, OUT2=Yellow, OUT4=Green
0001 1110 Set Red
0010 1101 Set Yellow
1000 0111 Set Green
Four light signals - OUT1=Red, OUT2/OUT3=Yellow, OUT4=Green
0001 1110 Set Red
0010 1101 Set Yellow Top
0100 1011 Set Yellow Bottom
0110 1001 Set both Yellow
1000 0111 Set Green
Network AddressingEvery receiver module on the network is allocated a unique four-digit address using the numbers 1-9 and A-F. This addressing scheme allows 50,625 separate and uniquely identified receiver modules to used on a single network. Over 200,000 lights, 100,000 points and 50,000 signals can be controlled by a single network.While having four digit addressing may seem like overkill ( few people will ever need 100,000 point controllers ), the addressing scheme allows controllers for various types of hardware to be defined, say, 1nnn for points, 2nnn for signals and 3nnn for lights. Having four digits also allows controllers to be grouped into zones; controllers for street lighting could have the first digit specified to indicate lighting controller, the second a street identifier, the third a house within the street and the fourth a particular room. Such a scheme would allow control over 15 streets, each with 15 fifteen-room houses, with four lights in each room. In most cases it is unlikely that such fine control would be needed, and a two digit address could be used to identify up to 225 streets, each with fifteen four-room houses; one light per room. As can be seen; the type of zoning required will depend very much upon what you want to do in terms of control. In addition to zoning, wildcards can be used to specify whole groups of receivers; whenever a command is sent with an address with one or more digits of value zero contained within it, any receiver which matches that address and has any digit value where the sent address digit is zero will obey that command sent. In our 3/two-digit-street/house addressing and zoning scenario described above, sending a command to 3120 will be obeyed by every house on street 12. If public houses were always considered as house '1' no matter where they were within a street, sending a command to 3001 would be obeyed by every public house and nothing else; ideal for turning the lights off in all pubs at closing time ! Four-digit addressing, zoning and wildcard addressing offers a very flexible mechanism for control, but the allocation of receiver module addresses will often require some thought for maximum optimisation and convenient control. Setting the receiver address for each receiver is very much in the hands of the model railway designer and users and there are few absolute guidelines which will be applicable to all layouts. In many cases, it would be appropriate to allocate addresses sequentially to start with, to get the layout workable, and then consider an addressing scheme which suits the final model. One really big advantage of using the PICAXE processors is that it is incredibly easy to re-program the receivers for a new address, so the configuration can change as the layout grows or changes itself. Receiver ModulesAll receiver modules are identical and are based around a PICAXE-08 processor. Each has a single receive input (RX) which connects to the main controller and is used to received command packets, and has four digital outputs which can be used to control external hardware to perform the function it needs to; LED control can be achieved by driving the LED directly from an output pin through a suitable resistor ( usually 330R to 1K8 ).The design of the receiver is such that each output bit can be set high, low or pulsed individually, as groups or in a variety of combinations. Circuit Diagram
Software Description
Transmitter ModuleCircuit Diagram
Software Description
The controller is designed to be controlled directly from a PC or from another PICAXE which is scanning a 18-digit keypad ( 0-9, A-F, # and * ) and sending each key as its ASCII character equivalent. All communications with the PC or PICAXE keypad controller is done at 9600 baud, 1 stop bit and no parity. Command Line Protocol
These characters should only be sent from the PC at appropriate times and as applicable to the command being entered. LCD Display
Keypad ModuleCircuit Diagram
Software
Description
PICAXE is a trademark of Revolution Education Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
First published on Saturday the 21st of August, 2004 at 20:16:06
Last upload was on Friday the 3rd of September, 2004 at 01:08:45 |