LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sychronising the start of two timed loops

Hi Forum,

 

I am developing a real time project to acquire voltage signals (20 channels) and temperature signals (20 channels) at a different sampling rate. I am using two timed loop but I am unable to synchronise the start of the two timed loops in cRIO.vi (VI on the target).

 

The time delay between the two timed loops loops is not as obvious when the loop rate is similar (say 30Hz to 1Hz), however one of the loop will run at 50Hz while the other will run at 1sample per min (60000ms period) most of the time. The time delay becomes very obvious (up to 60s), it seems that the low priority time loop starts one iteration too slow. Is there any way to fix this? Because ideally we want the elapsed time to be accurate (at least within 5 sec) for data analysis purpose. Thanks!

 

Attached is the whole project I am working on. It would be great if someoen can spend some time looking at it. Any help is greatly appreciated! 

0 Kudos
Message 1 of 6
(2,290 Views)

You have a race condition in each of your timed while loops in the cRIO.vi.

 

You are writing to a shared variable, then reading from a shared variable.  You have no control over which happens first.  In all likelihood, the read of the shared variable occurs in the current loop iteration before the new data is written to the shared variable in that same loop iteration.  So you have stale data.  You should should not read from that shared variable, but use a wire from where you write to the shared variable.

 

You just happen to notice it more easily in the slower timed loop because the data is a minute stale rather than perhaps 20 msec stale (50 Hz.)

Message 2 of 6
(2,284 Views)

Do you mind show me exactly the changes I need to make? Do you mean the use of variable1 and variable2 are redundant?

 

That step of writing "variable1" into "Buffered" in the VI is an advice given by an NI engineer which I blindly follow. I was told that it has something to do with buffering which prevents the loss of data but I don't quite understand the concept behind it.

 

Can you also briefly explain the purpose of assigning a numeric constant to the timeout on variable1 and what the number would affect my data acqusition process? I previously had it set on 9000ms but I changed to a much lower number because it would delay the start of the timed loop.

 

Once again, thanks a lot for your help!

0 Kudos
Message 3 of 6
(2,280 Views)

Attached is what I was talking about, now you know the data going into the "buffered" SV as the latest data from that iteration.  I was going to just erase the Variable1 Read, but I see that its timeout output is what is controlling the case structure.

 

But now that you talk about what the NI engineer was telling you, I have no clue as to what he is trying to do.  It seems to me like Variable1 and Buffered should have essentially the same data unless the Variable1 SV times out.  In which case Variable 1 contains data that Buffered does not have.  So I don't know how that  prevents a loss of data.  If anything it seems like it contributes to a loss of data.  Maybe that person can look at what you are doing and see if it is what they have in mind and can explain it better.

 

If I were you, I'd just use the one set of shared variables to pass data back to the host VI, then worry about exotic schemes to handle data loss in the event you find out it is actually happening.  It looks like your shared variable library is hosted on the cRIO, so I can envision a scenario where the VI running on the cRIO fails to communicate with the shared variables.

 

Message 4 of 6
(2,274 Views)

Thanks Ravens Fan! I have followed your suggestion and only used one shared variable each for transferring the two arrays of data. I have turned on the buffering option in the shared variable settings and so far I havent not witnessed any loss of data.

 

A quick question out of this topic tho, is it common practise to make sure the two VI's start at the same time? Right now I always run computer.vi first then cRIO.vi to avoid loss of data, however this always result in an extra line or two of redundant data at the start which seem to be values left over at the shared variables from the previous run.

0 Kudos
Message 5 of 6
(2,246 Views)

I don't know of anyway to easily get both to start at the same time.

 

I would consider adding some code at the front end of each VI that checks whether the other is operating and doesn't move on to the real section of code until it does.  With some creative use of some additional shared variables (not buffered), you could create a hand shaking scheme that each one doesn't start until it knows the other one is ready.

0 Kudos
Message 6 of 6
(2,241 Views)