Dr. König´s Märklin-Digital-Page

Software controller using an old PC

No updating - for newest version please read the German Text!

Benutzeroberfläche LOK


The first step to take was to thoroughly understand the old Motorola format and the working principle and circuit of the transmission-IC - the Motorola-chip MC145026, on which the original Märklin Control-Unit and the majority of third party and do-it-yourself products is based. Thereafter the design of an simple controller seemed relatively easy and cost-effective to accomplish, as the prices of original Märklin products are not justified and thus prohibitive. At first I made several attempts to develop a comparably simple circuit consisting of the least number of components possible, which should nevertheless include a turnout control and substitute the Märklin Control-Unit. Some time or other it occurred to me that this would be a perfect task for one of those numerous outdated PCs of which almost everyone has at least one specimen sleeping in the basement, kept just for some nostalgic reasons or to save disposal expenses (unfortunately, these veterans are not to be passed on to the offspring as just them are in the need of nothing less than high-end performance for their latest computer games). Since almost every PC has a gamecard and thus four controllers and four contacts (for the decoder function) can be attached without further ado, the problem to provide for genuine controllers with the least expenditures is solved. To cut a long story short: this PC solution ached to be realised.


The first approach was to control a MC145026 with the PC for signal generation. But then my sporting ambition was aroused to develop a pure software solution, that merely requires four potentiometers, four switches and a booster (apart from sockets, plugs, cables and a housing) as additional hardware. Because that is all a control unit is about (e.g. the EDITS alternative) - a specifically programmed computer. And this is what sets my software LOK apart from nearly all known control programs for model railroads. These programs require the relevant equipment, e.g. from Märklin - at least the Control-Unit (6021) and the Interface (6050/6051) have to be available (the booster is obligatory in every solution). Refrained from the additional expenses all restrictions of the Control-Unit apply, say in the number of turnouts or the data format. On the other hand the priority of these programs is not a pure (manual) control and as far as I know none of these packages allows for the connection of controllers. They aim at an automatic or at least a display oriented control of the layout - which is in turn of no significance to me.

Unfortunately I don´t see a way to run one of those programs parallel to LOK in Windows. LOK needs to control the task-managment to make shure the correct impulse generation - but Windows does not allow this.

The initial idea and the conditio sine qua non was after all that LOK should work on every (outdated) PC with an 80386SX, 80286 or even an 8088/V20 or 8086/V30 processor. These computers do not always provide a RS232C/V24 but usually a parallel interface so that (originally) the latter had to be used for data transmission. So it was not possible to use the RS232-UART but deveolpe own routines. So the software has to be calibrated on every computer. Moreover, after every change in the system installation that has an impact on computing speed the calibration has to be readjusted. By now I have realised an automated calibration as well as a performance check at start-up, but especially with extremely slow computers a fine tuning of individual timing routines may be necessary. The advantage is that the generation of the SelecTRIX-pulses is possible.

The precondition that LOK should work on old PCs had some other implications: (a) Since very short impulse intervals of 13 microseconds had to be realised (note that the PC timer 0 for the system clock has even a cycle of ca. 860 nanoseconds) that I implemented the signal generation in assembler, which of course was out of the question for the main program. (b) Only the text mode was suitable for the screen display so that the user interface looks decidedly spartan and antiquated in present-day spoiled standards and lacks all those gimmicks of graphical user interfaces. It goes without saying that simple DOS was the only reasonable option for the operating system; but this should not keep anyone from trying to run the program in the DOS box of Windows or OS/2, if the appropriate computer is already scrap and the multitasking does not cause any troubles. But surprise, surprise: Esp. with newer PC this does not work.

Present situation

At first the program LOK was only able to control four locos simultaneously and switch up to 324 turnouts or solenoid devices by input of a turnout number, assigned to a specific decoder address. In the course of time several details were added that did not take valuable computing power as well as decelerations for starting/braking and maximum speeds as dependent on direction. As a result of the very inadequate resolution of 15 speed levels I tried to generate intermediates by permanently switching between two speed levels; unfortunately the effect is not as overwhelming as I expected.
When I learned about the new or rather extended data format I implemented it in LOK. In the first place I planned that the desired data format can be selected for each loco separately. It turned out that the old as well as the new decoder tolerate a kind of mixed format, where the new format is used but the basically cancelled switching impulse is transmitted anyway. It can now be adjusted in the configuration if the program should distinguish between the old and new format corresponding to the loco data or if just the mixed format is generated. The four extra functions are switched with F1 to F4 (even if there is no H0-decoder seperately available for this); the normal function is triggered by the hardware switch on the controller.
In the old format a manual impulse of redirection can be generated. It is possible to deactivated the controllers or reassign another loco during operation; speed displays allow for a smooth transition. To give this charity to the actually very practical elder notebook PCs this function can optionally be controlled by keyboard. However, as the turnouts are primarily switched from the keyboard this is conceivably uncomfortable. Incidentally the handling by keyboard is actually a stopgap compared to genuine controllers. The same applies to the mouse as it needs additional working space, which is not necessarily available on model railroad layouts. The built-in or external mouse substitute in numerous notebook PCs will only increase the number of calamities, so that I did not designate their use.
Data are transmitted via output D0. D1 works as an on/off switch for the booster to cut the power supply to the rails in case of a short circuit or a emergency stop. The high-active short circuit output of the booster is connected to the control input BUSY; with an appropriate diode network several emergency stop switches can be attached instead. Alternatively the pins DTR, RTS and DCD of the serial interface can be used. The response time of LOK is adjustable between 0.1 and 3 seconds, thus temporary short circuits which are frequent especially with elderly rolling stock do not cause to a full stop.


Beschaltung des GameportAs mentioned above hardly any additional hardware is necessary except for the booster, as long as the PC provides for a gamecard. Apart from a 15-pole SUB-D plug, a 10-core cable and a housing, only four potentiometers (10k ... 100k linear) and four simple switches are needed. Every control unit can of course be mounted in a separate housing; then the cable needs to have 4 cores only. The potentiometers should be rotary ones with a medial notch for an easy adjustable zero position - unfortunately these components are hard to find nowadays. Rotary potentiometers without a medial notch or sliding controllers leave much to be desired with respect to ease of operation. I happened to get the appropriate potentiometers by mail order from Segor Elektronik in Berlin. Of course the non plus ultra would be a potentiometer like the original Märklin controller that has a contact (not a switch!) at the left stop. Please drop me a note if you know where such controllers are available or how to convert plain rotary potentiometers in this way.
This type of input, however, has a system immanent flaw: the temperature drift of the gamecard components is so great that the controllers are frequently initialised until they reach their working temperature after 20 to 30 minutes. Otherwise zero speed is not where it is supposed to be - namely in the medial position of the controller. Users of notebook PC do not face these problems as they cannot connect controllers for lack of a gamecard.
With the one-controller version of LOK the Märklin operating transformer itself can connected to the/a gameport via a small interface. Then the transformer obtains control of speed, direction and auxiliary function.


Zusätzlicher ADC für vier ReglerAlthough the locos can be controlled by keyboard if the PC does not have a gamecard, but this is just a poor solution. In any case a hardware add-on is to be favoured taking the place of a missing gamecard and transmitting the voltages supplied by the four potentiometers as well as the position of the four contracts to the parallel interface. The selection of channel 1 to 4 will be achieved by a 2-bit word and an appropriate decoder. They switch the output of the respective potentiometer to the input of a simple A/D converter, its seven outputs as well as the respective switch position via a corresponding driver to four of the five control inputs of the parallel interface. As not all PC can receive data through the data lines and thus only the 5 control inputs of the parallel interface are available, data are transmitted as nibble. The fifth control input serves - as before - as short circuit or rather emergency stop input. The additional expenditures for material apart from the controllers do not exceed some 10 DM, so that this solution is to be preferred to a keyboard or mouse stopgap. Owners of normal PCs without a gamecard have the ordeal of choice, since a gamecard is often priced around 10 DM by now. If there is a demand I will develop and present an appropriate circuit; according to present reflections it could look as shown. Suggestions for improvements or even (tested?) own circuits are warmly accepted.

Likewise it is planned a tunrout-control with mouse and a simple switchboard, a programmer-tool for programmable decoders and additional 13 speed steps for newer Märklin-decoders and for private developings. Of course further suggestions, proposals and wishes are welcome.


The available versions of LOK - with one controller and for 20 turnouts and with four controller and for 40+284 turnouts - have proved their applicability on a 16Mhz 80386SX, a 80486DX2-66 PC and several Pentiums PC. The 4 controller version should only be run on a faster PC (386DX or 486DX). Computer slower than the mentioned 386SX will probably have problems even with one controller. Because this veterans will no longer alive I will not change this. Those who want to get an impression of LOK can download the trial version LOK V.T1.2E which is based on the one controller version.


The basic translation was made by Dipl.Ing. Manfred Röhrig from Germany. Many thanks to him for this grateful work. Some mistakes you probably find are my work as result of trying to correct some misunderstandings.

Homepage | Deutsch

© 1996-99 by Dr. M. Michael König | Antoniter-Weg 11 | 65843 Sulzbach/Ts. | Contact | Last updated: 16.3.1999
© 1997 by Dipl.Ing. Manfred Röhrig | Nienstedter Straße 71 | 30890 Barsinghausen | roehrig@gem.uni-hannover.d400.de

Revisit this page