Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Dealing with multiple CAN terminations in a master-slave-BMS setup

+1
−0

I’m running into a CAN bus termination issue in one of my designs and wanted to get some opinions on the best way to handle it.

Setup

I have a master controller made up of two PCBs connected in a piggyback fashion. Each board has its own MCU and CAN transceiver, and both currently have 120 Ω termination resistors. These two boards talk to each other over CAN.

The same CAN lines also go out of the master to connect to a battery BMS, and sometimes a slave controller.

Here’s what gets added to the bus depending on configuration:

  • Battery A (Li-ion) - has its own BMS with a built-in 120 Ω terminator.

  • Battery B (NiMH) - doesn’t have CAN or any termination.

  • Slave board - basically the same hardware as the master, but with only one MCU and CAN transceiver, and it also has a 120 Ω terminator.

So depending on what’s connected, I end up with more than two terminations on the same CAN bus, which is not desirable.

What I’m thinking

  1. The master logic board will always keep its termination enabled.

  2. The piggyback board by default will have it's termination disconnected and on power up will detect (through a GPIO line) if a slave is connected:

  3. If slave is connected, the piggyback board turns its termination OFF.

  4. If no slave, it connects the termination, so that the master+piggyback still form the two ends.

  5. I will remove the CAN termination resistor from the battery BMS even though it’s physically at the far end (around 12 inches away). Should I be doing it ?

Bus details

  • CAN baud rate: 500 kbps, 11 bit, Classic CAN 2.0

  • Frame size: about 12 bytes

  • Total bus length: roughly 12 inches

Questions

  1. Is it acceptable to skip the termination on the battery side even though it’s technically the far end (~12 in)?

  2. I came across an application note that uses an optocoupler to control termination. Has anyone here tried that approach, or is there a cleaner way to do MCU-controlled termination? Link CAN Selectable Termination Application note bLOCK Diagram Waveform

The noticed the photorelay part has a max turn-on/turn-off time of 5ms. Which is slow compared to analog switches but I don't have to keep changing the termination when the communication is happening only needs to check once on power up and set appropriate can termination.

  1. Last one, where should I put the control circuit? On the Piggyback PCB or Logic board PCB ? The CAN bus is going out from the Logic board PCB and PiggbyBack and Logic board are connected with B2B connectors inside an enclosure.

Appreciate any thoughts or examples from people who’ve handled similar setups especially where you have modular boards and removable CAN nodes.

History

0 comment threads

2 answers

+2
−0

Your bus length is so short that you can consider the battery connection a stub. As long as there is 60Ω between CANH and CANL and the cable to the battery is not ridiculously long (many meters), it will work just fine.

If you add a third termination you end up with (1/120 + 1/120 + 1/120 = 1/Rtot) 40Ω, which isn't recommended, but in practice that will very likely work too (I do this all the time by mistake on all manner of CAN hardware and have yet to see it fail or causing error frames).

You usually just get problems when there is one or several missing terminators and you get >120Ω.


I came across an application note that uses an optocoupler to control termination.

It needs to be fast enough to switch on before CAN communication goes live and accumulates too many errors. If you are using something like a generic Cortex M then it boots out of power-on very fast. On the other hand if you have lots of overhead like RTOS, or in case you run on some low frequency = low power oscillator, then it won't.

CAN error frames are always expected during the boot-up stage because not all nodes will start in sync, someone has to be the first one and not getting anyone to talk with. That first node will send an error frame and then keep trying. If its error counter passes 127 then it will go error passive and depending on how you deal with errors that could be a problem. 128 more errors and it goes bus off.

So the critical time is: bit rate * bits * 128.

  • 500kbps = (1/500*10^3) = 2μs per bit
  • Assume worse case = no payload and 11 bit id, around 46 overhead bits in a CAN frame (+/- some stuffing).
  • 2μs x 46 = 92μs
  • 92μs x 128 = 11.78ms

Meaning that if the optocoupler has 5ms toggle time, the MCU then has 11.78 - 5 = 6.78 ms to come out of power-on reset, initialize everything and send out a CAN frame. That can either be an eternity or far too quick, depending on which MCU you've got, how you clock it and how much boot-up code there is.

I've encountered problems with this in real life when someone attempted to do with this with an even slower relay, which therefore brought down the whole bus sporadically, depending on how the relay contact bouncing ended up.

What's recommended instead of an optocoupler is an analog switch IC. And if you need galvanic isolation (doesn't sound like you do in this specific case) then add that on the line controlling the analog switch. Preferably with an inductive "digital isolator" rather than an optocoupler, since they are faster.


where should I put the control circuit?

Usually you do not want to control termination through the MCU, because normally the MCU will not have a clue of what hardware configuration that is present.

The plain and simple way is instead to add something like a terminal block connector to the board and if you put a wire between pin 1 and 2 on it, then a SMD 120Ω resistor on-board is connected between CANH and CANL, otherwise it just sits floating connected to just one of them. If you pick a terminal block with a removable cable connector part, then you can just move that cable part around between boards depending on where the termination needs to be.

The advantage of this is no soldering, so all boards are the same and even the end user can be taught to do it.

History

1 comment thread

Thanks for the input Lundin. I have done some research on analog switches and found this part TS5A316... (2 comments)
+0
−0

I see Lundin has already given you a detailed response, so I'll only answer what I do.

The company I work for uses CAN extensively to tie together various systems on board a ship. We use 250 kbit/s to allow for reasonable bus length.

All our hardware has a movable jumper near the CAN port. This is one of those .1 inch "shorting jumpers" that can be installed in either of two positions on three pins. In one position the 120 Ω terminator is left open, and in the other position it is connected between the CANH and CANL lines.

In our case, it's usually our own field people that install a system. Making sure the CAN bus is wired as one trunk with the terminator enabled on each end device only is just part of the normal installation procedure. There haven't been any problems due to CAN bus termination that I recall.

MCU-controlled termination

I have never done this. One thing to watch out for is the voltage drop of the output of an enabled opto-isolator. The CAN lines are only 1.8 V apart in the dominant state. The 200 mV or so of a saturated BJT is a noticeable fraction of that.

While no termination below 200 mV is probably OK, I'd still use a FET opto-isolator. Fortunately the body diode doesn't get in the way because the polarity from CANH to CANL is always either 0 or positive.

History

1 comment thread

I wish I had the flexibility to add moveable jumpers but once the machine's are out it's difficult to... (1 comment)

Sign up to answer this question »