LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I set one loop's frequency as a slave of another loop ?

I have 2 loops in parallel. The first runs at 500Hz. The AIread controls the frequency. How can I set the second one at 100Hz ? It is very easy to set it with local variable, but really not clean. The second loop must not use the CPU while waiting the next 100Hz tick. Is it possible ? I am trying to use occurrence, but the second loop will always (I think) use CPU while waiting next tick !
Is it possible to set one loop in one thread and the other one in another thread ? Then set each thread to a CPU (I use a bi-xeon PC)
Thanks
0 Kudos
Message 1 of 6
(2,682 Views)
Using a local for this is not too bad, here it does not involve much data and I would assume race conditions are not a concern here. If the second loop is just waiting (using a wait function) it won't use any CPU time.

Linking the timing of the loops together by using a producer/consumer model is an option similar to using occurences, but will also enable data transfer between the loops if that's necessary.

The easiest way to get the two loops to run in separate threads would probably be to put them in separate VIs and set the VIs to run in different execution systems.
0 Kudos
Message 2 of 6
(2,682 Views)
Thanks for your answer.
I wanted to not use the wait function because it is not precise (I think). If I put a 'case structure' in the second loop that waits for an occurrence, it will be more precise, but the test of the 'case structure' will use CPU time. Is there a better way to use the occurrence ? Or am I wrong, to wait an occurence does not use CPU ?
0 Kudos
Message 3 of 6
(2,682 Views)
The occurence halts all execution until it is set, no CPU load.
0 Kudos
Message 4 of 6
(2,682 Views)
cariboo wrote in news:5065000000080000001EBE0000-
1075935269000@exchange.ni.com:

> I have 2 loops in parallel. The first runs at 500Hz. The AIread
> controls the frequency. How can I set the second one at 100Hz ? It is
> very easy to set it with local variable, but really not clean. The
> second loop must not use the CPU while waiting the next 100Hz tick. Is
> it possible ? I am trying to use occurrence, but the second loop will
> always (I think) use CPU while waiting next tick !
> Is it possible to set one loop in one thread and the other one in
> another thread ? Then set each thread to a CPU (I use a bi-xeon PC)
> Thanks

One solution is to place a case inside the loop which run at 500 Hz. Put
your 100Hz code inside the True case. Use the "Quot
ient & Remainder"
funtion and the iteration counter to execute the true case every fift
execution of the 500Hz loop.
This may not work if the 100Hz code use to much time, it will then delay
the 500Hz loop.


I would go for the occurences solution. The wait will use some CPU
resources while waiting but i don't think that should be any problem (when
done correctly).

--
Rolf
0 Kudos
Message 5 of 6
(2,682 Views)
instead of a case struture. How do you think about the event structure ? Would it be a better idea ?
0 Kudos
Message 6 of 6
(2,682 Views)