LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

time synchronization in producer/consumer loop

Solved!
Go to solution

I wanted to save data from producer loop once in 4 secs. But this is not possible due to the wait function in the producer loop. It saves data once in 5 secsonce in 4-5 loops. When I cancel the wait function, the loop uses CPU extremely high. How can I avoid this timing problem?

Egemen
0 Kudos
Message 1 of 7
(4,533 Views)

As I understood the requirement is:

You want to produce the data with rate of 1Hz (delay in Producer loop is 1000ms) but want to save one sample at 0.2Hz (after every 5000ms).

Now if thats the requirement, I'll suggest you to make a small change in your code.

-> Instead of using "Wait (ms)" you should use "Wait Until Next ms Multiple"...!!

 


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


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

moderator1983, your suggestion is not useful. It has the same problem. Check while vi running that, it saves data once in 4 secs for a few loop and after saves one in 5 secs it keeps to save data in the same manner. It cannot catch the data once in 4 secs for every time.

Egemen
0 Kudos
Message 3 of 7
(4,516 Views)

Ohhh...!!

 

I'm sorry about my reply...

check now...


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 4 of 7
(4,510 Views)

I thought that I could not explain what I wanted to do. Just run the vi that I sent or your prepared no matter which one runs, while counting the generated data, check the value indicater. I want it to save the 4. generated element always but it saves 5. generated element in some loops. Please check, you will see the problem.

Egemen
0 Kudos
Message 5 of 7
(4,505 Views)
Solution
Accepted by topic author newbieeng

Yeah, actually I ran your code and got the issue...

You're using two timing functions (Wait ms and Elapsed Time) in the same loop runing on a non-real time system (that is Windows)... And as its not deterministic, this behaviour is expected...!!

 

However if you want to generate and log (the latest sample) at different rates.. you need to do it in different loops...
You may say that, you're alreayd doing this in different loops.. but in your implementation.. the execution of lower loop is still controlled by the Producer Loop.

 

I've made certain changes...

-> Replaced Queue with Notofier.

-> Now Elapsed Time is part of lower loop (Consumer Loop).


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 6 of 7
(4,493 Views)

Thank you moderator 1983. Instead of producer consumer design pattern I need to use master/slave. I got it.

 

Edit: I controlled your last suggestion, and the same situation that I observed before as a problem occurred again but not as frequently as in the previous producer/consumer loop. It does not catch all 4th generated values, sometimes, it cathes the 5th ones. To eleminate thedata loss do I have to use timed-loop?

Egemen
0 Kudos
Message 7 of 7
(4,475 Views)