Hardware

Note: since the hardware is based on Decoder 2 of the OpenDCC project, the description here is basically a translation and adaptation of the original OpenDCC pages.

Circuit

The circuit of the accessory decoder is very similar to the original OpenDCC decoder version 2, and shown below (click to see the high-resolution version). The circuit is available as EAGLE .sch file in the the download section.

DCC-input

The DCC-Signal is connected via X1 or X2 and isolated from the rest of the decoder via an 6N136 opto-coupler. An opto-coupler is needed to guarantee reliable operation. The 6N136 is a high-speed opto-coupler, and provides for DCC kind of applications much better results than the cheaper 4N25 type of opto-couplers. Costs of the 6N136 is around 50 cents, however, thus saving here would be saving at the wrong place.

Tip: if you want to check availability of the DCC signal, the D1 diode may be replaced by a LED.

Switch output

To drive the switches, two standard ULN 2803 driver arrays are used. A single ULN 2803 can deliver a continuous output current of 0,5A; in our case two drivers are used in parallel, so currents up to 1A are supported (if 1A is needed, make sure to select a fuse that supports 1 A). The ULN 2803 has internal free wheeling clamp diodes for suppressing the transients that are generated by inductive loads, such as the coils of common turnout coils. The switches should be connected via the terminal blocks X8 ... X11.

Micro-controller

The micro-controller can be selected from the following Atmel AVR ATMega types: 8535, 16, 32, 164, 324 and 644. The 8535, 16 and 32 belong to the same family, and differ in flash size: 8K, 16K and 32K, respectively. The 164, 324 and 644 are of a newer generation, and support flash sizes of: 16K, 32K and 64K, respectively. To support both families, the software includes a number of alias to deal with the differences in register names and register usage.

Although one would expect that the newest family would provide the best results, it was found that the ATMega 644 suffers from frequent (brown-out) resets. Although such resets may not be noticeable for the user, the better choice would be, but also for reasons of costs and availability, to use the ATMega 16 micro-controller. Compared to the 8535, the ATMega 16 is slightly more expensive, but has more reserve regarding flash memory, so future extensions can be accommodated much easier. Be sure to select the ATMega16-16PU (the second 16 indicates that the maximum clock speed is 16 MHz; PU indicates DIL40 housing).

Note that the ATMega 8515 and 162, which are used by the original OpenDCC project, have a different pin-layout and can therefore not be used with this variant. Also the newer and more powerful XMega AVRs can not be used with this variant, since these AVRs are only available as SMDs.

Clock signal

To achieve maximum timing precision, an external crystal oscillator of 11,0592 MHz, with capacitors of 18 to 22 pF, should be used. Since the crystal will be mounted below the micro-controller, be sure to order the smallest version of the crystal, thus the one with the HC49U-S housing. The value of 11,0592 MHz allows exact generation of a 4000 baud RS-bus signal. Other crystal values between 8 and 16 MHz should also work, however. Note that the Atmel ATMega 16 could also be used with its internal RC-oscillator, but the improved precision of an external crystal is worth the extra costs of roughly 25 cents.

The down-loadable hex-file was compiled for an external crystal oscillator of 11,0592 MHz. If other frequencies are used, or if the internal oscillator is selected, the source-code should be modified and recompiled, and the fuse bits should also be modified.

Power

The decoder can be powered via a normal AC power signal of roughly 15V (connectors X3 and X4). This AC signal is rectified via a bridge. The rectified signal is used to (via a 500mA to 1A fuse) directly feed the ULNs 2803, and thus the switch coils. The rectified signal is also stabilized via an 7805 to obtain the 5V VCC signal needed to drive the micro-controller. Note that a 10 mH coil is included between VCC and Pin 30 of the AVR (AVCC). This coil is not needed for the switch decoder, but is needed for other PCBs, such as the block occupancy decoders, which is currently under development.

Instead of using separate 15V AC power supply lines, the decoder may also receive its power via the DCC lines. In that case the rectifier bridge should not be used, but instead an alternative 1N4004 is needed (any diode between 1N4002 and 1N4007 will do). In this case X3 and X4 can be omitted.

Feedback of switch position

Each switch output signal is feed back to the micro-controller via a resistor and a zener diode. The purpose of these feedback signals is to detect the actual switch position, or to detect whether the switch has changed position. Such detection will work for all drives with with a build in turn-off switch, such as found in most modern drives, like for example those from Roco. The OpenDCC website includes a page that explains the principle operation of such feedback system; the interested reader is referred to that description. Note that, as compared to the original OpenDCC design, extra 100KOhm resistors have been added between the associated AVR input pins and ground, to make the switch feedback signals less susceptible to noise and interference.

If the decoder is equiped with the optional (RS-bus) feedback print, the micro-controller continuously monitors the switch positions. If a change is detected, a RS-bus message is send to notify the master station. Also at start-up all current switch positions are send to the master station.

Feedback socket

The PCB includes an 28 pin IC socket to optionally connect feedback boards. Such boards support the feedback of switch positions towards the master station. Currently a RS-Bus print and associated software has been developed to allow the feedback of switch positions towards master stations that support the RS-bus; an example of such master station is the LENZ LZV 100. For details of this RS-bus board and software, see the RS-bus feedback description.

Note that, as alternative, a Railcom feedback print has also been designed, but software for this alternative still needs to be developed and tested.

The feedback socket has connections to X5 and X6, which can act as RS-bus terminal blocks.

Acknowledge pulse

The decoder has the capability to signal to the master station an acknowledge pulse, as defined in the DCC specifications. For this purpose the DCC input line should be loaded wit at least 60 mA for a short period of 6 ms. If the decoder is connected to the programming track interface of the master station, this master station will be able to detect this extra load. To facilitate this form of feedback, the DCC signal is rectified via four IN4148 diodes and connected via a 100 Ohm resistor to a BC556 transistor, which can be controlled by the micro-controller via PD7 and the PC 817 opto-coupler. Note that for switching at these low speeds, high-speed opto-couplers are not required.

Button and LED

The LED should be a 2mA type, to allow direct connection to the ATMega. The button is needed to initialize the decoder and set the address.

SPI / Extension board connector

The micro-controller should be programmed via the 16 pin connector, which has equivalent pin positions as a traditional 10 pin SPI connector, but carries additionally the remaining Port B pins, as well as 5V and 15V power. The reason to chose such (non-common) SPI connector, is that the same connector can also be used to connect extension boards. One of the extension boards that has already been developed, is an emergency board, to which emergency stop buttons can be connected, as well as LEDs, which blink in case the emergency stop is activated. The extension connector can also be used to drive relays that control motor switches.

Servo output

The PCB has space for two servo connectors, using the common pin layout of GND / +5V / Servo. Several servos (especially the inexpensive ones) take quite some current dumps from the 5V supply. To compensate for this, ceramic SMD capacitors of 47 microF (6,3 Volt) are needed over the servo connectors. The servos are driven via dedicated output lines of the micro-processor, and are controlled via timers to avoid CPU load. Note, however, that a dedicated servo decoder print is planned, which already includes four relays to polarize the switch as well as some other improvements.