Can bus diagnostics
Over the weekend I've built a pair of CAN nodes to assist with dianosis and benchmarking of CAN bus systems. The setup is essentially a ping-pong test between two nodes (Alice and Bob) attached at two ends of a CAN bus.
- Alice sends incremental counter and waits for reply from Bob.
- Bob checks for missing messages and returns messages with diagnostic data appended.
As both nodes are written in Circuitpython, this was an opportunity to perform a benchmark with this setup.
Setup
- Two Feather M4 CAN boards, running Circuitpython 9.2
- can bus configured at 500kHz
Results
- 16-bit counter - 950 msg/sec
- 32-bit counter - 840 msg/sec
log example with max echo time jumping to 2.4ms, probably due to garbage collector.
Messages per second: 738.7, avg echo time: 0.4 ms, max echo time: 1.3 ms
Messages per second: 744.1, avg echo time: 0.4 ms, max echo time: 1.3 ms
Messages per second: 741.4, avg echo time: 0.4 ms, max echo time: 1.3 ms
Messages per second: 736.0, avg echo time: 0.4 ms, max echo time: 2.4 ms
Messages per second: 742.0, avg echo time: 0.4 ms, max echo time: 1.3 ms
Messages per second: 744.1, avg echo time: 0.4 ms, max echo time: 1.3 ms
Messages per second: 742.0, avg echo time: 0.4 ms, max echo time: 1.3 ms
Note that thesea are turnaround times, so actual message rate on the bus is around 1.6-2 kHz. Not too bad!
Source code