So far, we have looked at the basic idea of wiring up our train layout to a PC - to actually communicate effectively, we really need an interface that doesn't require exploring the inside of your PC with a screw-driver.
The basic computer nowadays has serial and parallel ports, and as USB is taking over from the serial port then utilising the parallel port is the best option.
The interface that I will describe starts small, but is expandable with add-on modules to allow for 128 inputs and 128 outputs - this should be more than enough for most modellers purposes.
Initial communication is by using IN and OUT commands through QBasic, although eventually a small Windows application will come along that insulates the future users from the programming side of this interface and only requires defining port numbers related to connections on the interface itself ...... but less technical rubbish and on with the circuit diagram.
First, go to the circuit diagram and print it out so that when I start rambling, you can understand what is happening !!
Now lets go over this interface section by section, so that you can all figure out what is going on in each section.
At the top left, we have a pair of 74LS137's that basically take data off of the top 6 data lines (numbered D7 to D2) and convert this to switch on one of 64 address lines - these can be seen numbered 0, 4, 8, 12 etc. in the middle-right of the diagram.
The main data port is accessed through the parallel i/o Data Port address which is usually 0378h - to power up the data line numbered 12, we feed the outputs with the data 0Ch. (It should be noted that values here are specified in hexadecimal or base-16 - whereas some programming langauges use decimal format, so I will eventually add a table of decimal equivalents !)
If you were to put a test link to data line 12, nothing would be showing as the data lines are dead until the 137's are enabled by setting the /SELECT data line to a low state (sending data 04h to address 037Ah, as it is data bit D3 of the Control Port 037Ah) - then all lights up !!
The chips marked 74LS75 are the latching IC's. Data is fed into the D pins and when a pulse is passed through LE, the data is held for output from the Q pins.
One point worthy of note is that there are two inputs and two outputs specified for each of the two derived data lines (D0 and D1 from the Data Port 0378h) - data outwards arrives from D0 and D1, and data inwards is sent to the PE (data pin D5 of Status Port 0379h) and SELECT (data pin D4 of Status Port 0379h) data lines.
To store data in the latches , we have to apply the data and use the lines /AUTO (data pin D1 of Control Port 037Ah) to latch the inputs, or /STROBE (data pin D0 of Control Port 037Ah) to latch the outputs.
To store data in the output latches,
To store data in the input latches,
So what can we do in real terms - well let's assume that we have a turnout connected to port no. 7 (data addresses 12 and 13) and let's go through the motions of switching it to curved and confirming that what we have done has actually worked.
A good convention to use is to connect the outputs and inputs as matching pairs, so that a turnout connected to data outputs 12/13 has a feedback switch connected to data inputs 12/13 ..... when you've seen the example, you'll see just why this is a great idea !!
Firstly we have to check to see whether we actually need to change the turnout at all. If the turnout is set to straight then it's data value is 12 whereas set to curve is 13.
 
| Load up the address lines to select the multiplexer | OUT 0378H, 0CH |
| Enable the multiplexer | OUT 037AH, 08H |
| Pulse the latch | OUT 037AH, 0AH OUT 037AH, 08H |
| Read the data lines | INP 0379H |
Lets say that we had a reading of 00h or 10h - that means that the SELECT line was set with a logic 0, and that means that we are looking at the turnout set to data value 12 or set straight, so we need to move it to the curve.
 
| Load up the address lines to select the multiplexer and load the data to set 13. |
OUT 0378H, 0DH |
| Enable the multiplexer. | OUT 037AH, 08H |
| Pulse the latch | OUT 037AH, 09H OUT 037AH, 08H |
Now that wasn't that grim, was it !!
The obvious suggestion is to build a small 16-port interface, and test it with lots of in's and out's and learn what it can and can not do for you.
Next month, we will explore what happens on the far side of the interface, as we begin to connect to the component parts of the layout itself with turnout driver cards and section detector cards.
Return to: 3MT on the Internet