Expanding my CAN knowledge

"Chuck Hackett" <[email protected]> Tue, 18 Jul 2017 08:39:24 -0400
Newsgroups gmane.comp.hardware.bus.can
Message-ID <[email protected]>
(try #2 - very strange.  When I create a message to the list from scratch it
doesn't work.  When I reply to a message it works ... oh well ...)

(try #3 - maybe messages can't have attachments so I moved the docs to my
DropBox.  When the message below references attachments, use the following
links:
    CurrentSettings.pdf ->
https://www.dropbox.com/s/a3hb5360rt3yhey/CurrentSettings.pdf?dl=0
    NewSettings_1_Mile.pdf ->
https://www.dropbox.com/s/cuudi05zlhx8lo4/NewSettings_1_Mile.pdf?dl=0
    NewSettings.pdf ->
https://www.dropbox.com/s/5nlj7bt182189ie/NewSettings.pdf?dl=0
)

First, thanks to John Dammeyer for helping me get 'reconnected' to the list.

For about seven years I have been working on a project to develop an
automatic signal system for the ride-on railroad hobby (mostly 1.5" scale
but also 1").  

My locomotive (1.5" scale, 7.5" gauge):
http://whitetrout.net/Chuck/images/8444%20Joan%20&%20Chuck%20at%20KC.jpg 

The system is based on distributed logic (no central PC).  The controllers
are distributed along the right-of-way and connected by a power bus (pair of
#16) and a data bus (CAT-5 cable).  The controllers detect the presence of a
train in a track segment by detecting the wheels shorting the two rails
together.

The controllers are my own design and manufacture (ATMega1284p with MCP2515
CAN ctlr and MCP2550 bus driver among other things).  Also, I have a 20k
resistor on the 'slope control' pin of the MCP2550 which limits the slew
rate to about 17 volts per usec.

The largest installation is my test installation at Central Pasco and Gulf
Railroad (http://www.cpgrr.org).  We have 19 controllers installed
controlling about 60 three-lamp(LED) signal heads and sampling about 100
tracks.  The entire system draws about 2A at 16VDC.

The current power/data bus length is approximately 3,500 to 4,000 feet (have
not measured it).

When I started I know nothing about CAN but I had done a lot of
communications software and I liked the multi-master capabilities along with
the automatic bus arbitration.  With the help of some examples and help from
this email list things have gone well so far.

Living in Florida (lightning capitol of the world) It has been a challenge
dealing with 4 wires >3,000 feet long along a railroad in the woods
connecting controllers which also have to be connected to 1,000's of feet of
aluminum rail in intimate contact with the ground.  Protecting the MCP2550
CAN driver has been the most challenging (should have mounted them in
sockets!) but I think I finally have a handle on it now.

All of the parameters to the MCP2515 (PSEG, SEG1, SEG2, etc.) were confusing
but, with the example code I got up and running.  As the bus length grew and
I started getting errors due to speed & cable length.  All I did was turn
down the bus speed (changed the clock source).

(finally) My issue: As I mentioned, the bus is now over 3,500 feet in length
and I'm getting situations (lost messages) where it 'smells' like
controllers at one end of the bus are causing errors at the other end -- or,
maybe I'm at the limit of the ability for the signal to get through
(resistance) as opposed to a 'length' issue.

I am currently running at 19,200 bps bus speed.  The parameters to the
MCP2515 are (remember, these came from example code and these numbers were
originally for a higher bit rate):

SJW = 4 TQ
BTLMODE = True
Sampling = once
PRSEG (propagation segment) = 5 TQ
PHSEG1 (Phase Segment 1) = 6 TQ
PHSEG2 (Phase Segment 2) = 4 TQ

I made up a spreadsheet to get more familiar with all the interactions.  See
attached "CurrentSettings.pdf" for details like TQ, etc.  Note that this
spreadsheet implies that, with those parameters, I should be able to cope
with a 4,012 foot bus length.

I don't know why they had SJW set to 4.  From my reading, when using xtals,
SJW of 1 should be good enough.  In some of my reading (MCP2515 datasheet
and AN754) it says that PS2 must be greater than SJW but in other readings
(can't find at the moment) it implied that PS2 had to be greater than ** or
equal ** to SJW.  Anyone have insight into this?

After some CAN literature study, I now know that this gives a 'sample point'
of 75%.  

Question: It is my understanding that a sample point of more like 85% is
more desirable, true?

Question: For "Long Slow" busses does it make any sense to change the
sampling from 1 to 3?  If not, when would one use a setting of three?

I did a trial of some settings that result in a sample point of 83% (See
"NewSettings.pdf"):

SJW = 1 TQ
BTLMODE = True
Sampling = once (as opposed to 3)
PRSEG (propagation segment) = 8 TQ
PHSEG1 (Phase Segment 1) = 1 TQ
PHSEG2 (Phase Segment 2) = 2 TQ

The new spreadsheet implies that I should be able to keep the bus rate at
19,200 but now cope with a length up to 9,056 feet.

In my application I will never need megabit speeds on the bus but I would
like to raise the bus speed above the current 19,200 bps to deal better with
some application issues but still be able to cope with a bus length of about
5,280 feet for a margin of safety.

The attached spreadsheet NewSettings_1_Mile.pdf suggests that I could run at
36,141 bps up to 5,347 feet and a sample point of 88.2.  Reasonable?

What other factors (other than ground differential) would come into play for
"Long Slow" busses?

In the past I have tried to look at the bus with a scope (difficult, because
it's outdoors away from power source) but difficult to tell anything because
signal levels vary due to the sender but I can't tell who the sender is
because this would take expensive equipment.  All I have access to is a
scope and the "Start Of Frame" pin on the MCP2515 which is set to indicate
when a "start of frame" is detected so this gives me a bit of a "trigger"
source for the scope.  Suggestions of how to look at the bus with a scope to
detect problems?  I know that there will be lots of ringing, etc. to wade
through.

Well, I think that's enough for this email.  Thanks for listening and thanks
in advance for any guidance you can give me.
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck


--
Archives and useful links: http://groups.yahoo.com/group/CANbus
Subscribe and unsubscribe at www.vector.com/canlist/
Report any problems to <[email protected]>