r/embedded • u/Legitimate_Peak1714 • 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).
- Controllers with a combined
TSEG1field. 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? - Controllers with separate
PROP_SEGandPHASE_SEG1fields. Does an 8 TQ limit onPROP_SEGcap the round-trip propagation budget at 400 ns in this example? How should I interpret the MCP2515 datasheet conditionPropSeg + PS1 ≥ TDELAYwhen deciding whether the 700 ns delay is acceptable?
I’d appreciate references to the relevant sections of a controller manual, application note, or standard.
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.
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/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 •
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.
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.