Auxiliary outputs

The XnTcp interface offers three auxiliary outputs that can be employed to drive LEDs or Relays:

Tcp On pad A0 ON (5 Volt) when a computer program is connected to the interface.
OFF (0 Volt) when the interface is idle.
Power On pad A1 ON (5 Volt) when tracks are powered by the Command Station.
OFF (0 Volt) when the Command Station is in Emergency Off status. A relay controlled by this output can be used to switch off accessories not controlled by the Command Station when an emergency situation occurs.
Service Mode pad A2 ON (5 Volt) when the Command Station is in Service Mode. A relay controlled by this output can be used to commute power from the Main Track to the Programming Track.
OFF (0 Volt) when the Command Station is not in Service Mode.

To use the above outputs:
Led scheme

Driving a LED

The scheme to drive a LED is very simple. The resistor R limits the current flowing through the LED and protects also the auxiliary output that cannot source more then 20 mA. By inserting the technical data of the LED in the following table, you can compute the value of the resistor.

LED forward current
mA. (1-20)
LED forward voltage
Volts (1-5)
Resistor
≥ 1/8 W


For a 3 mm. red LED (that has a typical forward voltage of 1.6-2 Volts and can be fed with just 3-5 mA) you can use for instance a 1 Kilohm resistor. Available on the market are also LEDs with built-in resistors and a forward voltage of 5 Volt that can be employed without any external resistor. If you use them, make sure that the forward current does not exceed 20 mA. Be aware that the auxiliary outputs are connected directly to the PIC microprocessor and an overload or an improper voltage can damage it. Do not connect any inductive load (e.g. solenoid) to the auxiliary outputs.

Relay scheme

Driving a Relay

The coil of a relay cannot be connected directly to an auxiliary output and a transistor is thus used to control the relay. A general purpose or switching NPN transistor, with voltage rating of at least 30 Volt (45 Volt, if Vin is over 20 Volts), like BC107, BC109 or 2N3904, can be used in the majority of cases. The resistor R1 limits the current flowing through the base of the transistor and protects also the auxiliary output that cannot source more then 20 mA. R2 insures that the transistor is completely switched off when the auxiliary output is in the OFF state (or disconnected!). The following table allows you to compute the value of the resistors.

Coil current in mA.
(typically 25-70 mA.)
Transistor
minimum gain
(typically 100)
R1
≥ 1/8 W
R2
≥ 1/8 W


Connect the coil of the relay to Vin (not to Vcc!) and note that the diode is "reversed", i.e. the cathode is connected to the positive voltage. Its purpose is to protect the transistor from the back-EFM pulse generated by the coil when the transistor is switched off. Choose a relay with coil voltage equal to Vin (i.e. the voltage of your power supply).

The scheme shows a SPDT (Single Pole Double Throw) relay, but you can obviously choose the type most suitable for your application. Make sure that the voltage and amperage ratings of the contacts are suited for the use, keeping in mind that currents flowing on a model train layout are often in the range of several Amperes. For the same reason, use wires of a suitable gauge. If you use a printed circuit, check that the width of the tracks be adequate for the current and the distance between them adequate for the voltage.

If you use the relay to switch hazardous voltages (i.e. ≥30 Volts AC (rms) or ≥50 Volts DC), take necessary safety precautions to prevent electrical shock, install the board in a suitable insulated enclosure with no part under tension accessible from the outside, and respect the electrical norms applicable in your country.