Maker Pro
Maker Pro

PIC polled on RS485 link

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
I have a Microchip PIC with a USART port connected to a MAX3485. The PIC is polled over the RS485 link(half duplex) by a controller which I have no control over.

When I run the master polling with no devices connected, I can run a monitor of the RS485 link and see the polls being transmitted. When I connect devices that don't respond (wrong poll address) then I can still see the polls on the monitor. As soon as I poll a valid device address, the transmission gets corrupted. This looks like a turn-around problem. I can look at the RS485 with my scope, but it is not possible to see which side is transmitting at any given point in the trace. If I could see which side is transmitting when, I should be able to fix the problem quite easily. Unfortunately I don't have control over the firmware in the master device(poller) so I cannot change the turnaround or timeout values in the poller device. I am using quite a fast PIC(40MHz) so I might be responding too fast, although I have tried slowing it down and it did not fix the problem. The link runs at 65200bps and the timeout is very short(don't remember off the top of my head).

My question:
Is there a way to set the scope up so I can see which trace belongs to which side? I have thought of inserting a resistor inline on the one side, producing a smaller voltage wave pattern, but I am not sure if this will work. If I had a dual trace scope I could have traced DE/RE on the master and the slave, but unfortunately I only have a single trace scope.:(

Any advice appreciated.

Note: This is really a scope setup question.
 
Last edited:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Does your scope have an external triggger input? You can then use DE/RE to trigger the scope and watch the signal on the single channel.

Your idea to insert a series resistor is interesting. Unfortunately I doubt it will help much. RS485 is a differential signal, therefore current in a line will flow in both directions even if only one master is sending data. You can't distinguish between a master on the "left" end sending a "1" or a master on the "right" end sending a "0". Both will create the same current.
 

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
Thanks for your reponse.

Unfortunately I only have a little scope (Velleman HPS140 and as far as I can see it has no trigger input as I can only connect one probe.

I realse that it is a differential signal, but I thought that meant it measures the voltage differential between the d+ and d- signals, nothing to do with current. Now I am confused:confused:

The idea of the resistor is that the scope is connected to the master side of the resistor, which is in series with the one data line, meaning that the voltage from the slave will be the voltage from the master minus the voltage drop over the resistor. But I might understand this incorrectly.

Timings are quite tight. This is a device connected to the ExpressNet network used by digital model railway controllers, specifically Lenz.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
I realse that it is a differential signal, but I thought that meant it measures the voltage differential between the d+ and d- signals, nothing to do with current. Now I am confused
The RS485 signal is a differential voltage signal. However, when correctly terminated a current will flow. Otherwise the insertion of a resistor, as you suggested in your original post, doesn't make sense.

The idea of the resistor is that the scope is connected to the master side of the resistor, which is in series with the one data line, meaning that the voltage from the slave will be the voltage from the master minus the voltage drop over the resistor. But I might understand this incorrectly.
You'll have a voltage drop only if there is current through the resistor. Unfortunately current flows in both directions (since the polarity of the differential signal changes with the logic level of the data). Therefore you will not be able to distinguish between data from the master or from the slave.

Your PIC SW should monitor the RS485 line and respond only if the line is idle. Google "rs485 collision detection" for some ideas.
 
Last edited:

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
The trouble I have is that the master has a very small timeout after a poll, 110 microseconds, so there is not a lot of time to do extra checks after analysing the message code and address. Only one device can respond to its own address after being polled, so the only possible collision is with the master still transmitting or starting the next poll. This is what I am trying to work out with the scope.
I have a seperate character level monitor on the line where I can see the character strings being transmitted and it shows the corruption happening, as does my firmware in the slave device. I have, blindly, tried speeding up and slowing down my response, without success.
The slave transmits fine when not connected to the master.

I also output state info on another USART on the PIC(RS232) and there everything looks fine on the monitor on the PC.

Any ideas are welcome. I will start looking for a cheapish dual trace scope, but was hoping to avoid that, as they are expensive.
 

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
Another thought:
How about a little circuit that takes 2 x TTL inputs (for DE1 and DE2) which is normally at 0V. When DE1 goes low then the output of the board is +5V and if DE2 goes low then the output is -5V. If both are low then the output is 10V. It could then display the state on a single trace scope.
The transitions are fairly slow as the RS485 is only 62500 bits per second, so the circuit should not introduce significant delays.
By my reconning it should be possible with a binary decoder(74HC238), and 3 trannies and 10V supply voltage.

With the 74HC238 it should even be possible to present a third input as another voltage.

Note that I have these chips/trannies in my bitsbox.

What are your thoughts.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
To create different voltage levels you could use an analog multiplexer. The HC238 is not suited, it will output only digital signals (of course you could combine them into an analog voltage using an R2R network :) ). The voltage levels would be in the range 0V...5V, not -5V to 10V, but that is not relevant, I think.
You can then monitor the analog signal.

Another idea: use an AND gate and feed both DE signals to the input. When both DE are high, the output goes high, too. Use the output of the AND gate to trigger a monoflop, drive an LED from the monoflop. Whenever there's a collision of the DE signals, the LED will flash (the monoflop may be required to increase the time of the flash to make it visible).
 

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
Thanks for that.
So the idea of presenting different states as different voltages is a possible solution. Getting a pure digital output is fine as I am more interested in WHEN/which signals switch than the analogue voltage(provided they switch on/off hard enough). I will try to build a little circuit when I have some time, and report back.

As I predominantly work with digital signals, I will try to make it capable of taking as many inputs as possible, without rebuilding a scope style circuit.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
You CAN insert resistors and/or diodes in the data path so you can see which device is transmitting and when. You could also try changing the VCC voltage of one of the transceivers.

You can also combine your device's transmit enable signal with the data using two resistors - one resistor, say 2k2, from transmit enable to the scope probe, and another resistor, say 10k, from one of the RS-485 data lines to the scope probe. The trace will jump up and down on the scope as the transmitter turns on and off.
 

shumifan50

Jan 16, 2014
579
Joined
Jan 16, 2014
Messages
579
@KrisBlueNZ:
Thanks for that, I thought it should be possible, but not being electroniclly trained, I could not be sure.
I will try and go down this much simpler route.
 
Top