RS-Bus Hardware
Circuit
The circuit is basically the same as the one described on the der-moba website (in German) and decoders from LDT. To isolate the RS-bus from the rest of the decoder, two opto-couplers are being used.
The sender logic is isolated via a CNY17 (or equivalent, such as 4N35 or 4N37) opto-coupler, connected to a NPN transistor (like the BC547). The goal of this transistor is to create a current source of 20 mA. If the opto-coupler starts conducting, the voltage drop over the 33 Ohm resistor, and thus the base-emitter of the transistor, increases. If the flow is 20mA, the transistor's base-emitter voltage becomes 660mV and the transistor starts conducting. Since the collector of the transistor is connected to the "base of the opto-coupler" (pin 6 of the CNY17), current is "taken away" from the optocoupler's base. As a consequence, the opto-coupler get's less "sensitive" and reduces its output current. In this way the current remains nicely at 20mA.
The current flow is switched on and off based on the value of RS_SEND. As opposed to the
The receiver logic acts as 3 mA current source. The description on the der-moba website proposes a LM334 with an associated 22 Ohm resistor as current source (see also LM334 Version). My experience, however, was that the LM334 seems quite susceptible to interference and therefore the better choice for me was to create a "standard" current source, using two transistors and resistors. The transistors are standard BC547 (or equivalents); the 220 Ohm determines the amount of current that flows (3 mA through 220 Ohm gives 660 mV). The second resistor is relatively uncritical and can be around 22 KOhm. As described on the der-moba website a zener diode of 5,6V is needed to "decouple" the receiver whenever the sender is active. The 1N4148 protects the circuitry against accidental interchanging the R and S signals. The opto-coupler at the receiver side is a PC817 or similar; note that it is also possible to use AC versions, such as the LTV814. The output of the opto-coupler (pin 3) is connected to an interrupt line of the micro-controller (RS_RECEIVE) and via a 1K5 resistor to GND.
A DIL 28 socket is used to connect the RS-bus circuit to the decoder print.
Note: other optocouplers, without an external base pin, may work as well. By accident I ordered a large number of CNY17F optocouplers (the F version doesn't connect the base to pin 1) and used them without any problems for years.
Receiver logic
Although the receiver logic seems relatively simple, certain aspects are still important. The Current Transfer Ratio (CTR) of the PC817 is specified between 50 and 600, depending on the exact model (PC817: 50-600 / PC817A: 80-160% / PC817B: 130-260% / PC817C: 200-400). If the CTR is low (thus 50), the output current through the 1K5 resistor may not be sufficient to create a High (+5V) signal. In such cases the value of the output resistor could be increased. On the other hand, if the output resistor is increased, the response to fast changes gets worse.
The figure at the left below shows in white a resistor value of 1K5, versus a 1K value in purple. In the right figure the purple resistor value is 4K7.
PCB
There are multiple versions of the PCB board; a version with normal through-hole (=no SMD) components, as well as a version with SMD components. The schematics and PCB can be found on my EasyEda page.
For historical reasons my original schematics and PCB in Eagle version 5.1 can also be retrieved from the download page.