Shop OBEX P1 Docs P2 Docs Learn Events
SX RS485 Communications — Parallax Forums

SX RS485 Communications

william chanwilliam chan Posts: 1,326
edited 2007-10-14 06:46 in General Discussion
Hi,

Has anybody implemented RS-485 differential communications using the built it comparator in the SX?
Seems like I can use the same UART assembly code with very little modifications to make it work with RS-485.

How many meters can it go if the SX directly drives the copper wires?

Thanks.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-10-12 08:52
    If you need to communicate with standard rs485 devices you will need
    a rs485 driver chip because of the 120 ohm termination resistor.
    This means a current of 5V/120ohm = 42mA. The sx I/O pins
    cannot deliver this current.

    regards peter
  • william chanwilliam chan Posts: 1,326
    edited 2007-10-12 11:42
    Peter,

    Even if the SX IO pins cannot source 45mA, it can still talk to standard RS-485 devices because the only thing that happens is that the voltage across the 2 wires will drop to much less than 5V but still within readable levels.

    Can I ask you about the behavior of the SX built-in comparator.
    Will the comparator still work correctly if the input pin's voltage is near 5V or near ground?

    I have had experiences with TL082 and TL084 op-amps where if both inputs were near the power supply rails, the comparator does not compare the 2 values properly.
    For example, if the non-inverting input voltage is at 0.02 volts and the inverting input is at 0.03 volts, the output may incorrectly swing high.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-10-12 12:46
    According to this:
    http://www.sxlist.com/techref/ubicom/lib/io/dev/video/hsync-ng.htm
    lowest level input voltage for the comparator is 0.4V

    You state the output voltage drops if the output cannot supply
    enough current. I think there is a real change the pin gets damaged
    if you sink/source more than 25mA per pin, or 50mA per port
    (sum of 8 pins), whichever comes first.

    Just use a max487 driver chip (which is available in DIP8) and you will have no·trouble.

    regards peter
  • william chanwilliam chan Posts: 1,326
    edited 2007-10-12 13:00
    Peter,

    Thanks for the 0.4v tip. I really needed it.
    I think if there is a 10 ohm resistor on each IO pin before connecting to the wires will keep the pins alive.
    Do you think I should put 5.1v zeners on each wire to ground to prevent EMI pickup on the longish wire from re-starting the SX?
    or should i use MOVs?

    Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-10-12 13:12
    william chan said...
    I have had experiences with TL082 and TL084 op-amps where if both inputs were near the power supply rails, the comparator does not compare the 2 values properly.
    For example, if the non-inverting input voltage is at 0.02 volts and the inverting input is at 0.03 volts, the output may incorrectly swing high.
    At this point·consider using a comparator (LM339) or even better, a precision comparator (LT1016), instead of an op-amp configured as a comparator.

    I reckon the SX's comparator is a good one, as they go, but it's not a precision comparator.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-10-12 13:22
    Read this article (scroll down to Applications Information):
    http://www.linear.com/pc/downloadDocument.do?navId=H0,C1,C1007,C1017,P1352,D3197

    It also shows AC coupling to reduce DC currents. And it shows the effects when
    termination is incorrect.

    regards peter
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2007-10-12 17:29
    Hi William,

    This message has results of tests I made on the SX comparator. I found that the common mode range went much lower than 0.4 volts. On a 5 volt supply it worked from 0.05 volts up to 4.9 volts, although above 4 volts the accuracy (offset) was degraded. The propagation delay degrades below 0.1 volt and above 3.8 volts.

    While I agree that in general a qualified RS485 driver is a good bet, it is also true that short, local RS485 connections seldom use the 120 ohm termination. When that is the case, the SX could drive the line with no problem. There are other reasons for using the qualified parts. They can operate into an extended common mode voltage, (like -7 to + 12 volts), as might occur if the ground potentials are different at the two ends. Some modern drivers can survive large ESD spikes or accidental connection to power lines as might occur in an industrial environment. Isolated drivers can operate into and survive huge insults to the RS232 line. But if none of those considerations are going to apply to what you are doing, and you have short and well controlled RS485 with >1000 ohm termination, then the SX direct. could hack it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-10-12 17:44
    If you need to, you can extend the input common mode range of the SX's comparator with a resistor network. The idea is to use series resistors from the RS485 cable to the SX's input pins. Then bias the input pins between Vdd and Vss with resistive dividers. You may even want to bias the D+ pin a little higher than the D- pin to guarantee a marking condition on an undriven network. Because of the series resistance, you won't be able to use the same pins as an RS485 driver. You'll have to dedicate a separate pair of pins to that task.

    Also, you don't need to terminate your lines with a pure resistance. A 120-ohm resistor in series with a 0.01uF cap wil provide 120 ohms of dynamic impedance for edges, without the DC loading that just a resistor would provide.

    I actually tried this scheme years ago. It worked, but the tradeoff in complexity, as compared to a cheap RS485 transceiver chip, just wasn't worth it.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 10/12/2007 5:50:14 PM GMT
  • william chanwilliam chan Posts: 1,326
    edited 2007-10-12 23:43
    Phil,

    If I were to use a slow 2400 baud rate, would I need to increase the termination capacitance to 0.1 uF?
    If the cable is short, termination becomes unnecessary right?
    If I use CAT-5e cables, would the impedance still be 120 ohms?
    I still like the idea of using only 1 pair of pins and let the software switch between input and output modes.

    What is the usual protocol used to decide whose turn to talk?

    Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2007-10-14 01:22
    Slow baud rates have less need for termination than high baud rates, other things being equal. Line transients due to reflections die out in microseconds. The free space wavelength at 2400 baud is around 409821 feet, and divide that by 100 conservatively to allow for shorter wavelength on the cable and a for a fudge factor, the cable is going to look almost like a capacitor, not a transmission line, out to lengths of over 4000 feet.
    0.1 uF and 120 ohms is adequate for cables up to 4000 feet.
    CAT-5 cable characteristic impedance is around 100 ohms. 120 is close enough.

    In a one master-many slave scenario, the master sends a command or a request for data, then it turns to input mode, and the slave takes control and sends back a packet, then repeat. Some devices have a configuration parameter for how long the slave will delay before returning its packet, to allow for turnaround. One can imagine other schemes, token passing etc., but RS485 and RS422 are a physical layer spec only, no protocol implied.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-10-14 06:46
    Thanks, Tracy. This thread fell off my radar somehow...

    -Phil
Sign In or Register to comment.