Electronic – Most efficient way to handle addressing / termination in a daisy-chained CAN bus

can

I'm working on some devices that will talk to each other over CAN. The simple idea is to daisy chain essential signals between each device: power (+12V and ground), enable and CAN high / low.

Now, there main two problems I have with introducing this daisy-chaining set up are node addressing and bus termination. My current solution to these two problems are:

Current Solutions

Node Addressing

I'd have some sort of switch (analog switch, MOSFETs, something) break the CAN bus between the input connector and output connector of every device. They would be, at start up, configured to essentially only be "attached" to the input connector portion of the bus wiring. Thus, when all devices power up, node #1 (connected directly to the master node) will be the only node connected, and will be able to pull an address. Once a node pulls an address, it closes its bus wiring switches and lets the next node connect. The master keeps assigning IDs until it determines no other nodes are out there waiting.

Bus Termination

I have worked up a way to use extra pins in the connectors as a "sense" signal… driving a voltage to the output connector and seeing it if comes back (each device shorts the pins on their input connectors) to tell us if we are the end of the bus or not.. and whether we should apply termination.

What I'm Not Sure On / Want To Make Better

Using Analog Switches

The analog switch thing works conceptually, but the electrical aspect confuses me. For example, a lot of the bit rate charts you see for CAN are referenced by how long the network is… this makes total sense. Harder to drive a signal farther without repeating, etc. Now, my confusion is… would an analog switch, with it's inherently high (compared to raw wire) resistance be killing my maximum bit rate on the bus?

From calculating it out, if my bus was entirely 20AWG wire… adding in an analog switch with a really low Ron (lowest I've found is 0.3 ohms so far) to each node to provide the circuitry to do node addressing would be the equivalent of adding an extra ~30 feet of wiring for every node. Am I overestimating the impact these switches would have? The bus is already terminated at each end by 120 ohm termination resistors so it's not adding a ton in terms of the passive bus resistance… but calculating it in terms of how much extra wiring it appears as makes it seem bad.

Remote Node Sensing

Also, as far as sensing remote nodes…. I'd like to avoid an approach that relies on using dedicated pins in the connectors. Long story short, being able to ditch the sense pins lets me save money on a lower pin count connector AND it lets me switch to thicker wiring which means I can carry more power and support more end nodes. I'd also like to be able to slightly reduce the component count of the driving/receiving circuitry of the sense functionality which involves a lot of passives, zeners for clamping, discrete logic ICs, etc.

So… thoughts? 🙂

Best Answer

Background Information

I have used CAN a few times now for multiple devices distributed over a physically small area, like within a few 10s of meters. In each case, the CAN bus was internal to the system and we could specify exactly what the protocol over CAN would be. None of these systems had to, for example, interface with OBDII, NMEA2000, etc, where a specific protocol was already defined. One case was a large industrial machine that required lots of distributed sensors and actuators. The outside world interface just dealt with the overall operation of the machine. How the controller got the sensor information and caused the actuators to do stuff was a internal implementation choice that we happened to use CAN for. In another case, a company needed a good way for their customers to control multiple (up to a few dozen) of the gizmos they make within a single larger system. In this case we specified CAN as one communication means and documented the protocol. This protocol would be implemented by the controller of this system, but not surfaced to the end customer which bought this system as a whole and communicated with it thru different means at a higher level.

The EmCan solution

I have converged on a way of dealing with this over several implementations. I am now in the middle of two more such implementations, and this time I decided to use the previous experience to create a formal spec for a infrastructure layer immediately above CAN. CAN is a well designed protocol as far as it goes, and is directly implemented in a number of microcontrollers nowadays. It seems a natural way to connect multiple little devices over a limited physical distance as long as the data rate isn't too high. Basically, it can do everything you probably would have used RS-485 for 20 years ago, except that more protocol layers are specified, the specification makes sense, and hardware implementations are available built into low cost microcontrollers.

The result of this is what I call EmCan (EMbed CAN). I am slowly filling out the formal protocol specification as I migrate code from the previous implementations, generalize the concepts a bit, and make re-usable firmware modules where the EmCan protocol code can be used without change accross a variety of projects. I'm not really ready to officially publish the spec yet and provide the reference implementations, but you can look at what is there to see where things are heading. The current document is a work in progress, as it itself says.

So far I have PIC 18 and dsPIC 33 implementations of the EmCan device side, a stripped down host implementation for PIC 18, and a more full (more things handled locally) implementation for the dsPIC 33. Everything documented in the current version is implemented and seems to be working. I am working on the byte stream interface right now. I did this before in one of the previous systems, but it was more tied into the application and not a nice separable layer like EmCan.

The issue with a switched load

I think trying to switch the CAN bus with FETs or analog switches is a really bad idea. The main reason for the bit rate versus length tradeoff is not the total resistance of the cable, but the round trip propagation. Look at how CAN detects collisions, and you will see this mechanism assumes signal propagation from one end to the other within a fraction of a bit time. The CAN bus needs to be kept a transmission line. For most implementations, such as when using the common MCP2551 bus driver, the characteristic impedance should be close to 120 Ω. That means a 120 Ω resistor at each end of the bus, so any point on the bus looks like a 60 Ω load.

How EmCan fixes this

EmCan solves the node address problem without requiring special hardware. For details, see the EmCan spec, but basically, each node has a globally unique 7 byte ID. Each node periodically requests a bus address and sends this ID. The collision detection mechanism will guarantee that the bus master sees only one of these requests even if multiple nodes send a address request at the same time. The bus master sends a address assignment message that includes the 7 byte ID and the assigned address, so at most one single node is assigned a new address at a time.

If you are interested in this concept and are willing to discuss details of your system, talk to me. My biggest fear right now is specifying something that will be awkward later or prohibit certain usage that I hadn't considered. Having another implementation in progress as the spec is being finalized would be good for spec development and to test out the reference implemenation if you plan to implement it on Microchip PICs.