Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

CAN taking Near 100% of CPU

Are RT-Fifo Queues better to use than the Normal Queues (Enqueue and Dequeue) on the RT Controller ? I'm still getting data loss and when I put the normal Queues size too big, there's a Lag that appears between the RT-Controller data and the data received on the Host PC. The array of data (from CAN) that I send into the Queue is around 1408 (this number should normally be around 352 when counting it as it represents 16 frames) elements of U32 every 2.5ms. I've set my Shared Variables at 2 arrays of 2048 Elements. The loop of the SV is every 10ms. When a new data is received on the RT Controller from the CAN, it takes around 9-10 seconds before I see the change on the Host PC...

 

So I tried quickly replacing all the Normal Queues for RT-FIFO and no data even gets transfered through the SV (the data is still sent to the SV on the RT-controller) and the RT Controller is topped at 100%. When I look at RT-FIFO examples, they seem to be implemented exaclty like the Normal Queues.

0 Kudos
Message 11 of 18
(4,938 Views)

Hello foreshadow,

 

Real-Time FIFO Functions Dim hasPlayer, playerversion hasPlayer = false playerversion = 10 Do While playerversion > 0 On Error Resume Next hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & playerversion))) If hasPlayer = true Then Exit Do playerversion = playerversion - 1 Loop is_FlashVersion = playerversion is_Flash = hasPlayer

The Real-Time FIFO functions are used to send and receive data deterministically between VIs. RT FIFO functions provide a deterministic data transfer method that does not add jitter to a time-critical VI. An RT FIFO is a lossy form of communication that overwrites the oldest data element when the FIFO is full.

 

Would it be possible to post your code?  Thanks.

 

 

O. Proulx
National Instruments
www.ni.com/support
0 Kudos
Message 12 of 18
(4,928 Views)

Since you said that RT-FIFO is data that can be lost, I went back with the normal Queues. Here is the code.

0 Kudos
Message 13 of 18
(4,924 Views)
I added some while loops inside the 10ms loops that includes the DeQueue and SV. Now there's data loss every 16 data received. These loops run about 5 times each time the 10ms loop runs. I've also changed the TickCount and Lenght(variable in the cReadMult) to be U8 like the cReadMult data instead of sending it all as U32.
0 Kudos
Message 14 of 18
(4,898 Views)

Here is an update of the code. I'm still getting data loss as explained in the previous post.

The second picture is part of the vi on the Host PC. There is 2 timed loops identical. I've only put the SV and the basics of the diagram. The rest is non important and doesn't affect the program's timing. 

Download All
0 Kudos
Message 15 of 18
(4,890 Views)

Hello foreshadow,

 

What is the size of your queue?

O. Proulx
National Instruments
www.ni.com/support
0 Kudos
Message 16 of 18
(4,878 Views)

4096 elements for each CAN channel. 

I count it as every 2.5ms I get 16 frames wich each contains an array of 22 U8  elements. +4Lenght + 4TickCount. So 16*22 + 4 +4 = 360. Each write to Pc is 10 times (25/2.5) so 4096 to make it a round number.


RT SV config: 2arrays of 4096 elements for each SV.
0 Kudos
Message 17 of 18
(4,876 Views)

When I put the Loop on the Host PC at 1ms, I seem to get almost everything, but data get jumped around when I verify the binary written file.

 

I think i'll add Queues on the Host PC side. I don't have time to test this at this moment, but monday I'll try to use 2 normal loops in parallel inside of 1 large loop. 1 to read and buffer and another to empty the Queue, both in 1 large loop.

0 Kudos
Message 18 of 18
(4,873 Views)