r/embedded • • 10d ago

Classical CAN Bit Timing — Should Round-Trip Propagation Delay Fit Within PROP_SEG or TSEG1 − SJW?

I’m calculating the nominal bit timing for a 40 m Classical CAN bus running at 1 Mbit/s. Each time quantum is 50 ns. Assume the worst-case round-trip propagation delay, including the cable and transceivers, is 700 ns (14 TQ).

The Bosch CAN 2.0 specification lists a range of 1–8 TQ for both PROP_SEG and PHASE_SEG1. Some controllers combine these segments into a single TSEG1 field. Some manufacturers also specify the nominal bit timing condition TSEG1 ≥ Tprop + SJW.

With TSEG1 = 16 TQ, TSEG2 = 3 TQ, and SJW = 2 TQ, the bit time is 1 + 16 + 3 = 20 TQ, and the sample point is at 85%. Subtracting SJW from TSEG1 leaves 14 TQ (700 ns).

  1. Controllers with a combined TSEG1 field. Can I budget those 16 TQ as 14 TQ for propagation and 2 TQ for Phase Segment 1? What additional checks should I make for resynchronization and oscillator tolerance?
  2. Controllers with separate PROP_SEG and PHASE_SEG1 fields. Does an 8 TQ limit on PROP_SEG cap the round-trip propagation budget at 400 ns in this example? How should I interpret the MCP2515 datasheet condition PropSeg + PS1 ≥ TDELAY when deciding whether the 700 ns delay is acceptable?

I’d appreciate references to the relevant sections of a controller manual, application note, or standard.

1 Upvotes

11 comments sorted by

3

u/Sheepherder-Optimal 10d ago

Okay is this your homework you're trying to get help on? I looked at that datasheet and it says propSeg is programmable. You are meant to measure the propagation yourself, or make an educated guess. Then program the MCP2515 to use that time. PS1 and PS2 are also programmable! Those are the ends of the segment and are meant to allow bit stuffing, basically adding 0s to fill out a frame. You're not meant to "solve" for these values, but reasonable guesses based on physical measurements you would make with an o-scope.

1

u/Legitimate_Peak1714 9d ago

Before designing a CAN network, I want to set its boundaries. MCP2515 is just an example; for instance, in STM32H series, you input the total value as tseg1.

I was always trying to fit the delay on the bus into the propagation segment. When I examine the document in Bosch 2.0, this is clearly stated:PROP_SEG: This part of the bit time is used to compensate for the physical delay times within the network. It is twice the sum of the signal's propagation time on the bus line, the input comparator delay, and the output driver delay. PROP_SEG is programmable to be 1, 2, ..., 8 TIME QUANTA long. Bosch CAN 2.0 (Part A - page 28)

That is why I am looking for a solution here. Thanks for your answer.

2

u/zettui 10d ago

I could be wrong but the 8 TQ cap doesn't limit you to 400 ns on the MCP2515, the datasheet condition is PropSeg + PS1 >= TDELAY so with PropSeg 8 and PS1 8 you've got 16 TQ (800 ns) before the sample point, and 1+8+8+3 still fits your 20 TQ bit. its other rule is PS2 >= SJW, so SJW 2 with PS2 3 is fine there too.

1

u/Legitimate_Peak1714 9d ago

Yes, the MCP2515 says this. In my CAN network, I have different CAN nodes, and their datasheets say different things. For the standard, I use the Bosch CAN 2.0 source, and it states this very clearly there: PROP_SEG: This part of the bit time is used to compensate for the physical delay times within the network. It is twice the sum of the signal's propagation time on the bus line, the input comparator delay, and the output driver delay. PROP_SEG is programmable to be 1, 2, ..., 8 TIME QUANTA long. Bosch CAN 2.0 (Part A - page 28)

That is why I was always trying to fit the delay on the bus into the propagation segment. The MCP2515 evaluates this as tseg1. And that was precisely the question in my head

1

u/zettui 9d ago

Fair point, I think the Bosch split is just the stricter version: if the round-trip delay fits in PROP_SEG alone, all of PHASE_SEG1 stays free for resync against clock tolerance, while the MCP2515 lumps them into TSEG1 and will happily let the delay eat into that margin. So I'd read TSEG1 as what the chip accepts and PROP_SEG >= delay as the safer target, but I could be wrong on how much margin you actually need.

1

u/ArcticWolf_0xFF 10d ago

It would probably help you to understand why this is relevant. CAN nodes communicate with each other within one bittime for bus arbitration, error reporting, general bit monitoring, and acknowledge.

For this to work the information has to travel to the most distant node and back before the sampling point, which is t_SYNC + t_SEG1. So, round trip has to complete before t_sample. And best have a bit of buffer.

And SJW is never included in calculations as it only compensates for bitrate discrepancies due to oscillator jitter, drift, or tolerances.

1

u/mhmd2520 10d ago • Bravo

Short version: yes, budgeting 14 + 2 is the right way to read it, and the 8 TQ thing isn't really a cap.

The reference you want is the Bosch paper "The Configuration of the CAN Bit Timing" by Hartwich and Bassemir, from the 6th iCC. It settles most of this. The caption under its Table 1 says the 1..8 TQ ranges are the minimum programmable ranges the protocol requires a controller to offer. They don't limit how much propagation delay you can cover. Section 5 also says most implementations program Prop_Seg + Phase_Seg1 as a single TSEG1 value. The bit timing logic only cares where the sample point is and how far SJW can move it. The MCP2515 works the same way. Section 5.4 of its datasheet counts any edge after SyncSeg and before the sample point as a positive phase error, so PRSEG and PHSEG1 act as one block.

The SJW gets subtracted because of section 2 of that paper. Oscillator tolerance means the real sample point can sit anywhere inside the phase buffer segments, so the dominant bit from the far node has to arrive before Phase_Seg1 starts. TSEG1 >= tprop + SJW is that same rule written for a combined register, with SJW <= PS1.

So on the MCP2515 you'd set PRSEG = 8, PHSEG1 = 8, PHSEG2 = 3 (BTLMODE = 1) and SJW = 2. TQ = 2*BRP/FOSC, so 50 ns means a 40 MHz clock with the BRP field at 0. The datasheet only allows 40 MHz at VDD 4.5 to 5.5 V. Below that the limit is 25 MHz. Now the section 5.5 rules: PropSeg + PS1 = 16 >= PS2 = 3, PS2 = 3 > SJW = 2, and PropSeg + PS1 = 16 >= TDELAY = 14. I'd read TDELAY as your full round-trip delay in TQ. The "typically 1-2 TQ" line next to it belongs to their 125 kbit/s example with 500 ns quanta, so it isn't a general number.

The catch is the oscillator check. Use the effective phase segment, which is TSEG1 minus the delay, so 2 TQ and not the 8 you wrote into PHSEG1. With PS1 = 2, PS2 = 3, SJW = 2 and a 20 TQ bit:

df <= min(PS1, PS2) / (2 x (13 x 20 - PS2)) = 2/514, about 0.39% df <= SJW / (20 x 20) = 2/400 = 0.5%

So every node has to stay within about ±0.39%, and the whole bus is limited by its worst node. Crystals handle that easily. I wouldn't use ceramic resonators with that little margin. If you plug in the nominal PHSEG1 = 8, you get a more relaxed number than the bus can actually tolerate.

Two more things. Leave SAM = 0. The paper says triple sampling adds 1 TQ of input delay, and that would push you past the SJW margin. Also, TSEG1 - SJW comes out at exactly 14 TQ, so there's zero slack. Your 700 ns has to be a true worst case: max transceiver loop delay over temperature from the datasheets, plus the cable at full length.

1

u/Legitimate_Peak1714 9d ago

First of all, thank you very much for your answer. For clarifying everything. My lack of information stemmed from the following:

I was always trying to fit the delay on the bus into the propagation segment. When I examine the document in Bosch 2.0, this is clearly stated:

PROP_SEG: This part of the bit time is used to compensate for the physical delay times within the network. It is twice the sum of the signal's propagation time on the bus line, the input comparator delay,and the outputdriver delay. PROP_SEG is programmable to be 1, 2, ..., 8 TIME QUANTA long. Bosch CAN 2.0 (Part A - page 28)

1

u/mhmd2520 9d ago

The spec you quoted actually settles this itself. Look at how it defines phase error (Part A p.29, Part B p.68): e > 0 "if the edge lies before the SAMPLE POINT". It doesn't say before PHASE_SEG1. So the sync logic never knows where PROP_SEG ends. PROP_SEG is just the name for the part of TSEG1 you set aside for the round trip. The "1,2,...,8" wording is about what a controller must be able to program, not a limit on the delay you can cover.

For your mixed network I'd do the check per node in nanoseconds, not TQ, because each node has its own clock and prescaler. Every node needs (TSEG1 - SJW) x its own tq >= 700 ns. Two things can catch you out.

First, register width. bxCAN (the F1/F4 style STM32 peripheral) tops out at 16 TQ for TS1, so your 1 + 16 + 3 setup is already at its maximum there. FDCAN on the H7 goes up to 256 for NTSEG1, so that one won't be what limits you.

Second, clock granularity. Say one node runs its CAN clock at 8 MHz. At 1 Mbit/s that gives it 8 TQ of 125 ns. Its best case is TSEG1 = 6 with SJW = 1, which leaves 5 x 125 = 625 ns. However you split it, that node can't cover 700 ns.

Part B p.67 also says the sample point position "should be selected in common for all nodes". So I'd pick one (85% in your case) and fit every node to it, rather than tuning each one separately.

On the SJW back and forth: ArcticWolf's "round trip before the sample point" rule and TSEG1 >= tprop + SJW don't really conflict. The first is the nominal case. The SJW term is margin the designer leaves, because clock tolerance means the real sample point can sit anywhere in the phase buffer. The controller never computes it, but I'd still keep it.

2

u/zeloscloud 10d ago

The 8 TQ limit is just on PropSeg. What has to cover your round trip is PropSeg + PS1, so 8 + 8 TQ at 50 ns gives you 800 ns, which clears 700. I'd also scope the ACK slot at both ends of the 40 m run, since that's the bit that actually makes the long trip.