Hello
I had Problems with the CAN communication (250k) to a device using a stm32 with a internal clock with +-1% Tolerance.
Sometimes, the communiaction worked without any can errors, other times a lot of communication errors occured.
The discussion occred about the Bit Timing of my can device, which I am not really familiar with.
A collegue voiced that my device could be configured to not allow for big Oscillator Tolerances.
He talked about the configuration of "tseg1, tseg2", "brp" and "sjw" and mentioned a paper of Bosch which writes about the Configuration of the CAN Bit timing and the configuration of mentioned values to allow for a increased oscillator tolerance range.
Currently, I am not configuring the bit timing values in my application, I am using the pcan_open(..) function as follow:
::pcanfd_open(pcan2, OFD_BITRATE, 250000)
I read in the "PCAN Driver for Linux v8 - User Manual" that the flagg OFD_BRPTSEGSJW can be passed to the pcanfd_open function to configure the values for "tseg1, tseg2", "brp" and "sjw". I am having a hard time understanding what the use-case for that would be.
Using the ::pcanfd_open(pcan2, OFD_BITRATE, 250000) function I am getting the following output:
cat /sys/class/pcan/pcanpcifd2/nom_tseg1
139
cat /sys/class/pcan/pcanpcifd2/nom_tseg2
20
cat /sys/class/pcan/pcanpcifd2/nom_brp
2
cat /sys/class/pcan/pcanpcifd2/nom_sjw
1
my cat /proc/pcan output is:
*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20200701_n (8.10.2) Apr 11 2022 09:24:39 --------------
*------------------------- [mod] [pci] [pec] [rt] ---------------------------
*--------------------- 4 interfaces @ major 000 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
0 pcifd -NA- 13e1000 136 0x001c 00000000 00000000 00000000 00000000 0x0000
1 pcifd -NA- 13e2000 137 0x001c 00000000 00000000 00000000 00000000 0x0000
2 pcifd -NA- 13e3000 138 0x011c 00008ad6 00008140 001dfc6b 00000000 0x0000
3 pcifd -NA- 13e4000 139 0x011c 000060a4 00000000 001df849 00000000 0x0000
Can I reach significant higher oscillator tolerances setting up the values with the OFD_BRPTSEGSJW flagg? What would be typical use-cases to configure the bit-timing values manually instead of simply using the OFD_BITRATE flagg?
Any advice or information is highly appriciated
Kind Regards
Petar
pcanfd_open(..)
-
- Software Development
- Posts: 305
- Joined: Mon 9. Sep 2013, 12:21
Re: pcanfd_open(..)
Hello Petar,
When using pcanfd_open with only the bitrate specified as bit-per-second, you specify the API to compute for you the internal parameters (brp, tseg1, tseg2, sjw).
It will find the best values to obtain a sample point of 87.50%: this is the default value if OFD_SAMPLEPT is not specified.
If 2 CAN devices are not using the same sample point on a CAN bus, it will probably lead to communication errors. As a result, a common use-case is to specify the bitrate and the sample point (OFD_SAMPLEPT):
only a few combinations of [brp, tseg1,etc.] lead to a specific sample point, the API will compute and choose one of them for you.
Choosing to initialize the device with OFD_BRPTSEGSJW is the best way if you know exactly what are the settings of your CAN bus.
You can take a look at our Bit Rate Calculation tool to see the numerous combinations you can have for a specific bitrate: https://www.peak-system.com/Bit-Rate-Ca ... .html?&L=1
When using pcanfd_open with only the bitrate specified as bit-per-second, you specify the API to compute for you the internal parameters (brp, tseg1, tseg2, sjw).
It will find the best values to obtain a sample point of 87.50%: this is the default value if OFD_SAMPLEPT is not specified.
If 2 CAN devices are not using the same sample point on a CAN bus, it will probably lead to communication errors. As a result, a common use-case is to specify the bitrate and the sample point (OFD_SAMPLEPT):
only a few combinations of [brp, tseg1,etc.] lead to a specific sample point, the API will compute and choose one of them for you.
Choosing to initialize the device with OFD_BRPTSEGSJW is the best way if you know exactly what are the settings of your CAN bus.
You can take a look at our Bit Rate Calculation tool to see the numerous combinations you can have for a specific bitrate: https://www.peak-system.com/Bit-Rate-Ca ... .html?&L=1
Best regards,
Fabrice
Fabrice
Re: pcanfd_open(..)
Hallo,
Thanks for the reply.
A question a bit off topic:
Is using a clock for CAN Communication with +-1% Tolerance within the CAN-Spec? What are your thoughts on than? Do you think it is a "hack"?
Kind Regards,
Petar
Thanks for the reply.
A question a bit off topic:
Is using a clock for CAN Communication with +-1% Tolerance within the CAN-Spec? What are your thoughts on than? Do you think it is a "hack"?
Kind Regards,
Petar
-
- Software Development
- Posts: 305
- Joined: Mon 9. Sep 2013, 12:21
Re: pcanfd_open(..)
Hello,
1% tolerance is too high. Without resynchronization and with a CAN frame which could have more than 100bits, you will be completely out of the bittime!
If you want to have a more complex answer, read this: https://www.can-cia.org/fileadmin/resou ... mutter.pdf
1% tolerance is too high. Without resynchronization and with a CAN frame which could have more than 100bits, you will be completely out of the bittime!
If you want to have a more complex answer, read this: https://www.can-cia.org/fileadmin/resou ... mutter.pdf
Best regards,
Fabrice
Fabrice