Model Electronic Railway Group

Leading Model Railway Electronics since 1967

Celebrating 50 years of Innovation: 1967-2017

Copyright for items on this page is retained by the authors identified.

The use or misuse for the sale, design, supply, process, installation, delivery, test, repair, servicing, and alteration of the designs, instructions, computer code, photographs, circuits, and any other information that appear on this web site is entirely at the risk of the user or visitor to the web site. The information is made available in good faith without warranty of any kind strictly on the basis that no liability will attach to the Model Electronic Railway Group (MERG), its officers and members.

MERG DCC System -Supplementary Page

Revised 17 August 2007

Alternative software for the locomotive decoder

Gil Fuchs provided the alternative available on the previous page as 'mbint104.asm', the CVs available are listed in 'INTDEC10version103.pdf' Here is Gil's description of the new software.

Decoder software

Date: 03 February 2001 Gil Fuchs.

The following is a short list of features and comparison:

  1. MBINT10 uses a different approach for detecting DCC than the Dean Probst based software (decod10x); it utilizes the interrupt capabilities of the PIC to sample the signal every 22us, thus allowing to differentiate between short DCC half-bits '1' and long ones '0' by counting the number of signals between polarity changes. Once a series of at least 18 short half bits followed by a long half-bit is detected (preamble) it synchronizes on the beginning of the packet. The sample rate is now dropped to 1/44us and full bits are detected, assembled to bytes and packets which are buffered. Since interrupts are used, this entire detection procedure occurs intependently of the main execution thread - processing DCC commands, and both threads continuously run in parallel. This wastes less resources in polling for bit changes, and allows for simplified code maintenance. In the Probst code, during packet detection a close count of instructions must be kept to start the next sample iteration exactly at the next 22us slot (this makes code changes a challenge); once a packet is fully detected, instruction counting is stopped and bits are dropped until that packet processing is completed.
  2. MBINT10 supports a larger number of Configuration Variables (CVs). Documentation is provided with the software. All CV29 (control 1) bits are supported.
  3. 2 and 4 digit addressing, advanced consisting, automatic analog conversion (which can be disabled) are supported
  4. 14, 27 and 128 speed step modes are fully supported. Speed is controlled either by a splined curve calculated by 3 points: (VMin (CV2), VMax (CV5) and VMid(CV6)) or by a 28 entry speed table. The curve is independent of the number of speed steps, which is not the case with most commercial decoders. Decod10x allows for straight-line speed control or a 28 entry speed table.
  5. Acceleration and Deceleration are supported and the rate is per NMRA specifications (CV3, CV4).
  6. Control of 5 outputs and logical functions, including a mapping of logical functions to outputs that conforms to NMRA specifications (decod10x has this capability but does not comply with NMRA specs since they did not exist at the time it was developed; hence it uses "vendor defined" CVs rather than the standard ones).
  7. Support for special effects is similar to decod10x; any combination of effects can be applied to any logical function, and controlled by CVs. Added a special effect which is a pulse at a rate dependent on speed; used for "chaf" sound timing.
  8. All programming methods, including programming on-the-main, are supported.
  9. PWM maximum rate is lower than decod10x; this is a tradeoff to allow for improved performance of the main code. Both programs provide control of PWM frequency.
  10. Both programs support motor damping via CV29.
  11. Due to the added functionality, program memory is almost completely used. There is little room for addition unless a different PIC is to be used, which has a larger program space.

Update: 26 February 2001

A new version of MBINT10 is now available (1.04). Fixes in this version:

  1. Adapted to handle higher frequency processors (compile time, by setting the preprocessor constant FREQ to the desired frequency and assembling).
  2. CV7-8 fixed protection (so they cannot be overwritten).
  3. CV1 addresses (short) are truncated to the range 0-127
  4. CV17-18 limited to 0xC000 - 0xE7FF
  5. Optimized code, now has 8 words of program space free.


Software for the Accessory Decoder

The accessory decoder code has been updated to version 4. See following description for features of this version. This version is included in the kits.

Following from the various problems users have had with the MERG accessory decoders and Lenz systems, I have made some changes (with help from Rod Lancaster) to give a Lenz compatibility mode in addition to the original.

Rod had changed the PIC code so it could be programmed with a Lenz Compact and also with programmers that were limited to CVs upto 255. (Officially, accessory decoder CVs start at 513.) For Lenz compatibility, I have added another CV of CV545 (CV33 for low range programming).

The timing range is still in multiples of 10 millisecond - 1 to 255 - or if set to 0 then is continuous on.

Programming modes available now are:

1. Register mode

Set register R6 to 0 (R6 is the page register)

R1 is decoder address (0 to 63)

R2 is time for output pair 1. (0 to 255)

R3 is time for output pair 2. (0 to 255)

R4 is time for output pair 3. (0 to 255)

R5 is time for output pair 4. (0 to 255)

R6 is the page register. Must be 0 for register mode.

R7is the version number. Fixed at 4

R8 is the manufacturer.Fixed at 165 for MERG.

2. Page mode or direct mode (will accept either)

CV513 or CV1 low address bits (0 to 63) Default = 1

CV514 or CV2 output on or off. (0 to 255) Default = 255 (all on)

CV515 or CV3 time for output pair 1. (0 to 255) Default = 5

CV516 or CV4 time for output pair 2. (0 to 255) Default = 5

CV517 or CV5 time for output pair 3. (0 to 255)Default = 5

CV518 or CV6 time for output pair 4. (0 to 255) Default = 5

CV519 or CV7 Version number set at 4

CV520 or CV8 Manufacturer's ID set at 165

CV521 or CV9 high address bits (0 to 7) Default = 0

CV541 or CV29 Configuration (set to 128)

CV545 or CV33 Lenz (toggle) mode. See notes below. Default = 15

CV513 and CV521 together form a 9 bit binary address for the decoder giving a range from 0 to 511. (512 possible decoders)

CV545 (CV33) now gives the ability to set individual output pairs into a Lenz compatible toggle mode. Each of the low four bits of this CV, if set to 1, enables toggle mode for that output pair. The decoder actually has 8 outputs but these can be paired as 1a,1b - 2a,2b - 3a,3b - 4a,4b when used for point motors or dual aspect signals. When in toggle mode, an activate signal sent to 1a will automatically turn off 1b and vice versa. Further, as some Lenz systems seem to send continuous activate packets, the output will only give a single pulse (provided the time is not set to continuous) irrespective of subsequent activates. This prevents all possibility of point motor burn-out and allows the MERG CDU to recharge after each pulse. In this toggle mode, there is no need for any deactivate packets, their presence will be ignored.

Individual pairs can be set to toggle mode and others left in normal mode. In normal mode, each output is individually controlled with activate and deactivate packets. However, where an output needs to be on while a button is held down (continuous activates) you can set to normal mode with a time set to whatever is needed to avoid `flicker'. This depends on how often the activate command is refreshed. The output will now cease when the button is released (plus whatever the pulse time is).

The default for the Acc4 PICs will be with toggle set on all outputs. They will then be compatible with the MERG accessory encoder and Lenz systems without modifying the CV545. Only where individual outputs are needed, as in signalling or lighting effects will CV545 need setting to normal mode.

Acc4 will work with both types of MERG accessory decoder, the CDU (pulse) type and the steady state (Tortoise) type. However, for a steady state output, the time CVs must be set to 0. The default is for pulses of 50 milliseconds to suit the CDU. I have tested the program with a computer simulation of a Lenz system. I don't actually have one myself. Would welcome anyone who can try the real thing.


There is a new version of the code which allows a decoder to work in dual mode. This can give 8 separate outputs when used with a Lenz system (Acc5). The code is available for download below as well as a description (acc5txt.pdf). Mike Bolton will reprogram existing PICs if you send them with a SAE for return.

Stefano Curtarolo has provided an alternative, this is available in the download section. It supports the "Accessory decoder configuration variable access instruction". This instruction is similar to a OPS program mode for accessory decoders. NCE and SYS1 stations support this useful instruction, and they make life much easier.

dbacc5 is the version for PIC16F628. It should work with the PIC16F627 too. The F628 is cheaper, faster, and more powerful than the obsolete F84.

Copyright to all information on these pages is held by the Authors identified.