LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scheduling threads in cRIO with LabVIEW real-time

Hello all,

 

I'm a bit confused regarding threads and scheduling in labview RT for the cRIO. I have three timed-loop structures that each write to a CAN bus, running at the following setup:


Thread 1: prio 3 (high), period 1 000 000 μs

Thread 2: prio 2 (med), period 20 000 μs

Thread 3: prio 1 (low), period 10 000 μs

 

What I'm trying to achieve is that thread 1 always executes first each 1000ms multiple, followed by the other threads in priority order. However, when monitoring the actual start and finish iterations of the timed-loop structures I have the following running scheme (as percieved by the actual start and finish times from the structure):

 

 Around time 0:

Time: 2, Thread 1 Start

Time: 294, Thread 1 Finishes

Time: 10040, Thread 3 Starts

Time: 13513, Thread 3 Finishes

Time: 20023, Thread 2 Starts

Time: 21990, Thread 2 Finishes 

 

Around time 1 000 000:

Time: 1000022, Thread 2 starts.

Time: 1000029, Thread 1 starts. (most likely interupts thread 2)

Time: 1000230, Thread 1 finishes.

Time: 1000262, Thread 3 starts.

Time: 1001974, Thread 2 finishes. (most likely interupts thread 3)

Time: 1008045, Thread 3 finishes.

 

My questions are:

* Why aren't thread 2 and 3 ready to execute at time 0 together with thread 1? This causes thread 3 to run before thread 2 and is not desirable in my case.

* Why do thread 2 and 3 get to execute after time 1 000 000, even though there is a higher priority thread in the ready queue and thus get interupted?

 

 

Thanks in advance

Mattias

0 Kudos
Message 1 of 7
(2,927 Views)

Can you share your code? It might be helpful to see how you have the Timed Loops configured. Are you discarding missed periods? Preserving the original phase? Is anything inside the loops configured to run at time-critical priority?

0 Kudos
Message 2 of 7
(2,881 Views)

Attached is the vi i run at the RT target of my cRIO.

 

I've been playing around with the different modes of the timed loops (discarding missed periods and preserving the original phase, without any success). Since the deadline is equal to the period, i find it weird that all the threads wouldn't execute between time 0 and 10 000. Additionally the missed period shouldn't be discarded? The timed loops basicly only run CAN Open vi's from the NI CAN Open library.

 

Regarding the code:

The flat sequence before the loops are just initializing objects. I added some sync timed structure start to see if it would help me (it did not).

 

Wbr

Mattias

0 Kudos
Message 3 of 7
(2,867 Views)

To avoid confusion, Mats = Me in this case Smiley LOL...

0 Kudos
Message 4 of 7
(2,861 Views)

Any chance you can save it back to LabVIEW 2015 or earlier? I haven't installed 2016 yet.

0 Kudos
Message 5 of 7
(2,838 Views)

Of course, I hope this will work:

 

 

0 Kudos
Message 6 of 7
(2,819 Views)

I don't think this is the right approach to what you want to do. It seems like it would be easier to put all three sections of code in the same timed loop, running at the desired rate for the fastest loop, then put case structures around the sections that you want to execute less frequently and only run them every N iterations of the main loop. That way you could dictate the order in which you want that code to execute, and there would be no possibility of one section interrupting another.

 

I don't have the CANOpen toolkit available so I don't know what's going on inside those VIs. Maybe there's something inside one of them that allows the thread to sleep, causing the higher priority thread to get interrupted by the lower one?

 

If you must use your current approach of separate loops, I think you will have more success adding a small time offset to the loops that are supposed to run later, rather than attempting to schedule them all to run at the same time.

0 Kudos
Message 7 of 7
(2,803 Views)