Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger on CAN-bus activity

Hello you all,

I'm using a PCI series 2 CAN card and I would like to generate a trigger signal when there is activity on the CAN-bus. The situation is that there is only one device connected to the CAN-bus and I would like to trigger a DAQmx function when this device starts transmitting a CAN frame. I can generate a trigger when a CAN frame is written into the rx buffer, but that is too slow.

Can I implement this without the need of building extra hardware?

Thanks, Jos
0 Kudos
Message 1 of 5
(4,779 Views)
Hi Jos,

yes, that is possible. You can program the Series 2 CAN cards to generate a pulse on the RTSI/trigger port whenever a CAN frame is sucessfully received (and passed the Series 2 filters).
Before starting your task (Channel API) or Network Interface Object (Frame API), use the nctConnectTerminals function to route the 'Interface Receive Event' (source) to RTSIx (destination). The width of the pulse is one CAN bit time.

If you want to generate a trigger when a CAN frame with a particular arbitration ID is received, you have to use the Frame API. Set up a CAN Object for that ID and configure the RTSI Mode to 'RTSI Output on Receiving CAN Frame' (LabVIEW) or NC_RTSI_OUT_ON_RX (C languages).

For the latter case, there is already LabVIEW example code as part of the NI-CAN driver software: 'CAN Object controls RTSI on Unsolicited Receive.vi'

-B2k
0 Kudos
Message 2 of 5
(4,762 Views)
Thanks for your answer!

I understand that in both cases the trigger is generated when the CAN frame passed the filters and is written into the receive buffer. I performed some tests (CAN message length = approx 140 bits @ 250kBs). It takes approximately 600 us from the reception of the first bit of the CAN frame until the RTSI generates a trigger pulse. This is too slow for my application. I need to generat a trigger on the RTSI when the a the first bit (or change) on the CAN-bus is detected.

Jos
0 Kudos
Message 3 of 5
(4,757 Views)
Hi Jos,

Your observation is correct. The trigger is generated when the frame is successfully received. Whether the CAN frame is valid or not (correct baud rate, not bit errors, etc.) is only known when the end of the frame (EOF) is reached. At your frame length (~140 bit @ 250kBs), the EOF is at about 560 us after the StartOfFrame (SOF).

Both NI CAN card types (Series 1 & 2) get the information about an incoming frame only, when the CAN controller determined that the transmission was good. Triggering on the SOF could be problematic as the transmission might stop before the complete frame was on the bus and is retransmit (e.g. because of an error frame during the transmission).

I don’t know your application, but one could run the DAQmx measuring task continuously and filter out later everything that is older than 600 us before the trigger pulse from the CAN card occurred.

If there is no way around triggering on the SOF, you probably need the help of a data acquisition card (analog input in differential mode) to detect the change of state from idle to SOF.

-B2k
0 Kudos
Message 4 of 5
(4,748 Views)
Thanks for your help! My intention is to synchronize a number of measurements with a CAN message, whether it is good or not. I build a listener device (SJA1050) and a use the digital rx signal as a trigger (on a DAQmx card). I'm still playing with the LabView to translate the CAN message in a proper trigger pulse, but I that is only a matter of time!

Thanks again!

Jos
0 Kudos
Message 5 of 5
(4,745 Views)