Issues receiving frames at 1000Hz

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
VLopez
Posts: 2
Joined: Thu 18. Jan 2024, 11:16

Issues receiving frames at 1000Hz

Post by VLopez » Thu 18. Jan 2024, 12:23

I am using a PCAN-M.2 to communicate with a motor at 1KHz, with Ubuntu 20.04 with RT Preempt patch on kernel 6.4.6-rt8.

Using CAN FD, with these settings:

Code: Select all

  * pcanpcifd3: (/sys/class/pcan/pcanpcifd3)
  	- file: /dev/pcan3
  	- dev: "234:3"
  	- dev_name: "/dev/pcan3"
  	- minor: 3
  	- base: 0x80ED4000
  	- irq: 16
  	-----------------
  	- adapter_name: "PCAN-M.2"
  	- adapter_partnum: "IPEH-004085"
  	- adapter_number: 0
  	- adapter_version: "3.2.1"
  	- type: "pcifd"
  	- hwtype: 19
  	- devid: 0xFFFFFFFF
  	- ctrlr_number: 3
  	-----------------
  	- clock: 80 MHz
  	- nom_bitrate: 1 MBit/s
  	- btr0btr1: 0x4110
  	- data_bitrate: 5 MBit/s
  	- init_flags: 0x80000104
  	- clk_drift: 131073
  	- ts_fixed: 0
  	-----------------
  	- nom_brp: 8
  	- nom_sample_point: 60.00%
  	- nom_sjw: 4
  	- nom_tseg1: 5
  	- nom_tseg2: 4
  	- nom_tq: 100
  	- data_brp: 2
  	- data_sample_point: 62.50%
  	- data_sjw: 3
  	- data_tseg1: 4
  	- data_tseg2: 3
  	- data_tq: 25
  	-----------------
  	- bus_state: OK (1)
  	- bus_load: 0%
  	- rx_error_counter: 0
  	- tx_error_counter: 0
  	- rx_fifo_ratio: 0%
  	- tx_fifo_ratio: 0%
  	-----------------
  	- irqs: 3294
  	- status: 0
  	- errors: 0
  	- read: 1
  	- write: 0
  	-----------------
  	- TPCANHandle: "PCAN_PCIBUS4" (0x044)
Every 1 millisecond I read received messages and publish a SYNC frame.
I have verified with an oscilloscope that the SYNC is sent every 1 ms with 50 us margin of error.
The TPDO sent by the motor is also sent every 1 ms, 200 us after the SYNC frame, with 40 us margin of error.

The problem I am experiencing is that I read every 1 ms, and sometimes I get 0 TPDO and sometimes I get 2 TPDO. I don't know the details of the interaction between the library, the driver and the hardware, but it looks as if there's a buffer the hardware and my application that is not updated as soon as the message is received, but waits for some time, probably for the IRQ.

I have verified the stamps of the CAN FD frames, and they are stamped as being received 1 ms apart, but the CAN_ReadFD function returns PCAN_ERROR_QRCVEMPTY when according to the timestamp the message was received by the device 600-700 us ago.
My system is deterministic, I am using the same structure to control the motor through EtherCAT and don't have this bundling problem.
I have the same problem with the Linux netdev driver as well as with the chardev driver.

Attaching my kernel config.

How can I remove this delay or buffering between the hardware receiving the message and my application being able to read it via CAN_ReadFD function call.
Attachments
config.txt
Kernel config
(267.67 KiB) Downloaded 728 times

M.Maidhof
Support
Support
Posts: 1751
Joined: Wed 22. Sep 2010, 14:00

Re: Issues receiving frames at 1000Hz

Post by M.Maidhof » Thu 18. Jan 2024, 13:06

Hi,

which driver version is installed on your system? Which firmware is used on the PCAN-M.2 card? Please post the output of "cat /proc/pcan" and "sudo dmesg | grep PCAN". This could be an IRQ issue on your PC, which can be solved by switching to MSI mode. Need those outputs to give you more details.

regards

Michael

VLopez
Posts: 2
Joined: Thu 18. Jan 2024, 11:16

Re: Issues receiving frames at 1000Hz

Post by VLopez » Thu 18. Jan 2024, 13:16

Thank you for the swift answer.

Notice that I also have a USB PCan on the system which I use for debugging, the same issue can be produced with the USB PCan, and also happens if the USB PCan is not installed on the system.

Code: Select all

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20230330_n (8.16.0) Jan 17 2024 13:16:50 --------------
*---------------------- [mod] [isa] [pci] [pec] [usb] -----------------------
*--------------------- 5 interfaces @ major 234 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
 0  pcifd   -NA- 80ed1000 016 0x001c 00000000 00000000 00000000 00000000 0x0000
 1  pcifd   -NA- 80ed2000 016 0x001c 00000000 00000000 00000000 00000000 0x0000
 2  pcifd   -NA- 80ed3000 016 0x4110 00000000 00000000 00000001 00000000 0x0000
 3  pcifd   -NA- 80ed4000 016 0x4110 0000ab95 00000000 0000320f 00000000 0x0000
 32  usbfd   -NA- ffffffff 255 0x4110 000269e7 0000000a 0001044d 00000000 0x0000

Code: Select all

[   44.501698] peak_pciefd 0000:01:00.0: 4x CAN-FD PCAN-PCIe FPGA v3.2.1:
[10472.783125] pcan 0000:01:00.0: PCAN-M.2 sub-system id 14h (4 channels)
[15529.251014] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[15579.981542] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[15671.405241] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[15928.262335] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[15957.953583] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[15975.992822] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[15998.832098] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[16008.886729] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[16043.619782] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[17198.978115] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[17493.386272] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[18242.998255] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[18249.182976] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[18267.376187] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[18297.195473] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[18329.887951] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[18335.194135] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[18365.462489] pcan: PCAN-M.2 CAN4 (pcan3): BUS OFF
[22329.521091] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[22793.592906] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[22808.711904] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[23298.676010] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[23541.106199] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[81972.710209] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[81992.476403] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[82178.304544] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[82268.034290] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[82301.184823] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times
[82394.516865] usb 3-4: Product: PCAN-USB FD
[82394.522736] pcan 3-4:1.0: PCAN-USB FD (MCU0ah PCB06h) fw v3.4.3 bl v2.1.0
[84482.727543] pcan: PCAN-M.2 CAN4 can't be initialized when opened 2 times

M.Maidhof
Support
Support
Posts: 1751
Joined: Wed 22. Sep 2010, 14:00

Re: Issues receiving frames at 1000Hz

Post by M.Maidhof » Thu 18. Jan 2024, 13:24

Hi,

as a first step please update the PCAN-M.2 card to the latest firmware version 3.5.7 using the PEAK Flash Tool for Windows. If you could not use Windows for the update process, please send us an email to our support address to send you the needed Linux flash tool. We need the output of "uname -a" to send you the correct tool for your environment.

There are a lot of BusOFF errors visible in dmesg, please check that your CAN cables have termination resistors on both ends. Also the used bitrate settings with different sample points for nominal and data bitrate (60% and 62,5% ) are not well selected for a CAN-FD system. Please use the same prescaler and sample point settings for both bitrates, and use a SP around 80%.

regards

Michael

Post Reply