I'm attempting to connect to Loconet(spec) to a PIC32, and I've found a circuit to connect to an Arduino, but I'm not sure what exactly it does:

Loconet to Arduino (source page)

Specifically, I don't know what the LM393N voltage comparator at the top middle of the schematic does. I think that what is going on is that the LM393N is clamping the voltage to a certain level, between 0 and 5V or so in order for a microcontroller to read it as either a 0 or 1. I'm assuming that because of the following statements in the spec, as well as the given that VCC=5v:

Page 3: 
a) High = 1 = "MARK" : LOCONET+/- voltage above +4.0 Volts with respect to ground conductors. 
b) Low =0 = "SPACE" : LOCONET+/- voltage below +4.0 Volts with respect to grounds. 
c) The data should be received with 1.0 volt of HYSTERESIS centered on +4.0 volts. 
d) Maximum LOCONET+/- high voltage is +24V and nominal is +12V

I've seen another circuit that is similar, but uses an opto-isolator after the voltage comparator to actually interface with the microcontroller, which I'm assuming will then drop the voltage down to CMOS levels if it isn't already.

BONUS QUESTION: The LM393N in the center doesn't appear to be connected to anything, what's up with that?

  • 2
    \$\begingroup\$ Bonus answer: To keep it quiet. \$\endgroup\$ Dec 1 '13 at 2:29
  • 3
    \$\begingroup\$ Analog Devices have a nice little article about that: What shall we do with the Unused Op-Amp? \$\endgroup\$
    – PeterJ
    Dec 1 '13 at 3:00
  • 1
    \$\begingroup\$ @IgnacioVazquez-Abrams but it won't keep it quiet: the inputs are biased to zero difference voltage. So the output can still be randomly switching on and off if the input offset voltage should happen to be less than the input noise voltage. \$\endgroup\$
    – markrages
    Dec 1 '13 at 3:00
  • \$\begingroup\$ Also, it's biased at the negative supply rail. This is not really a good thing to do with an op amp, especially if it isn't rail to rail. \$\endgroup\$ Dec 1 '13 at 4:57
  • \$\begingroup\$ @alex.forencich LM393 includes the negative rail in its input common-mode range. \$\endgroup\$
    – markrages
    Dec 2 '13 at 1:33

The inverting input(pin 6) to the comparator is a voltage reference of 3V. This is what you are comparing the non-inverting input(pin 5) to. When the non-inverting input is greater than the inverting input, the output(pin 7) will be high.

Notice that there is a feedback resistor from the non-inverting input to the output. This is for hysteresis. It will keep the voltage at the non-inverting pin slightly higher when the output is high, and keep the voltage slightly lower when the output is low. This will prevent the output from toggling when both inputs are at very similar voltage levels.

This is basically what a schmitt trigger does.

It gives you a nice digital output for your microcontroller.

Bonus: There are two comparators on the LM393N. One is simply not used.

  • \$\begingroup\$ How is pin 6 a 3v reference? The calculation that I did gave me 2.04v at pin 6, but maybe I did the math wrong. \$\endgroup\$
    – rm5248
    Dec 1 '13 at 15:44
  • \$\begingroup\$ V6 =Vcc(R3/(R3+R2)). You must have switched the resistors around. \$\endgroup\$ Dec 1 '13 at 15:56
  • \$\begingroup\$ Apparently it's been a really long time since I did this math, why is it Vcc(R3/(R3+R2))? I was treating R3 and R2 as a series circuit, which would give me 2.04V after R2. \$\endgroup\$
    – rm5248
    Dec 1 '13 at 20:35
  • \$\begingroup\$ Check the definition of a voltage divider (Look at the proof in particular) : en.wikipedia.org/wiki/Voltage_divider \$\endgroup\$ Dec 1 '13 at 21:00

The comparator provides a 5V copy of the data on the LocoNet connection. Here's how -

An LM393 can handle up to 36V on one of its inputs REGARDLESS of the voltage being used to run it (so long as the other input remains below the voltage used to run it), in this application it is being run on 5V (VCC to pin 8) with one input held at 3V while the other input varies between approx 16V and 0V. The 'output' is a connection to the collector of an internal NPN transistor that has its emitter connected internally to 0V through pin 4.

The 47K and 150K provide ~200K, a tiny loading on the LocoNet (16V / 200,000 = 80 mico Amps). The 47K will also protect the comparator from any inrush currents.

The 27K and 39K provide a reference voltage to trigger the comparator (5V * 39K / 68K = 2.9V).

The 240K 'feedback' resistor prevents the comparator from oscillating if the LocoNet signals do not have sharp transistions, effectively 'cleaning up' the copied signal.

The 1K at the 'output' provides 5V at 5mA on the 'LN_RX' connection which is switched to 0V when the comparator trips.

There are 2 comparators in the LM393 package, the second one should be shut down by tying both its inputs to 0V if it is not used.

'LN_TX' uses a transistor to switch the LocoNet to 0V when required. As LocoNet typically uses just 12 to 15mA the output transistor in the unused comparator may be used instead, share the reference voltage by connecting pin 2 to pin 6, connect the 'LN_TX' to pin 3 and connect the LocoNet directly to pin 1.

  • \$\begingroup\$ Unfortunately I don’t think the spare LM393N can be used to replace the transistor; its outputs can’t sink enough current. See e2e.ti.com/support/amplifiers/f/14/t/… The graph of “Output Saturation Voltage” in the datasheet is helpful. \$\endgroup\$
    – tjvr
    Nov 16 '20 at 18:03
  • \$\begingroup\$ Testing with a Digitrax DCS100, I find the LM393N can pull the LocoNet low, but only to about 0.8–0.9V. This seems to match up with the “output saturation voltage” graph from the datasheet. That’s well below 4V, so it should be detected as a logic low, but it might not be good enough for all equipment 🤷‍♂️ \$\endgroup\$
    – tjvr
    Nov 17 '20 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.