CAN Bit Timing Calculator
embedcalc_can_bit_timingCompute exact CAN bit timing (BRP, segments, SJW, register values) for STM32 bxCAN, FDCAN, and MCP2515 controllers from clock frequency, bitrate, and target sample point. Returns register-ready configuration closest to target sample point.
Instructions
Compute exact CAN bit timing (BRP, segments, SJW, register values) for STM32 bxCAN, STM32 FDCAN (nominal/arbitration phase), and MCP2515 from clock, bitrate, and target sample point.
Searches all valid prescaler/segment combinations and returns, per controller, the configuration whose sample point is closest to the target (ties: more TQ per bit, then smaller BRP). Register values are ready to write: bxCAN CAN_BTR, FDCAN FDCAN_NBTP, MCP2515 CNF1/CNF2/CNF3 (BTLMODE=1). All values follow the controller datasheets; BRP/TS values are 1-based (register encoding = value - 1 is already applied inside the hex words).
Args:
clock_hz (int): controller input clock in Hz. bxCAN: APB1; FDCAN: kernel clock; MCP2515: crystal Fosc (MCP2515 uses TQ = 2*BRP/Fosc).
bitrate_bps (int): nominal bitrate in bit/s (classic CAN: up to 1000000).
sample_point_percent (50-95, default 87.5): CiA 301 recommends 87.5.
Returns (structured): { bxcan, fdcan, mcp2515 } — each a timing object or null when the clock/bitrate ratio has no exact integer divider for that controller (a null means: change the clock or bitrate, do not approximate).
Examples:
"500 kbit/s on STM32F103 (APB1 36 MHz)" -> clock_hz=36000000, bitrate_bps=500000
"1 Mbit/s, 16 MHz MCP2515, sample point 75%" -> clock_hz=16000000, bitrate_bps=1000000, sample_point_percent=75 Do not guess CAN timing registers — call this tool.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clock_hz | Yes | CAN controller input clock in Hz (bxCAN: APB1 clock; FDCAN: kernel clock; MCP2515: crystal Fosc). E.g. 36000000 for 36 MHz. | |
| bitrate_bps | Yes | Target nominal bitrate in bit/s, e.g. 500000 for 500 kbit/s. | |
| sample_point_percent | No | Target sample point in percent. CiA 301 recommends 87.5 (the default). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bxcan | Yes | STM32 bxCAN solution, or null if no exact divider exists | |
| fdcan | Yes | STM32 FDCAN nominal (arbitration phase) solution, or null | |
| mcp2515 | Yes | MCP2515 solution (BTLMODE=1, SAM=0), or null |