LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Outputting data from the sub vi at the same rate

I am using the attached sub vi to return max, min, and average values received from a plc on our factory floor. The data in the sub vi is analysed every time the value in the plc changes rather than analysed after a set time delay. I have programmed the sub vi to output the data to the main vi after 20 values have been collected, however as soon as the sub vi starts outputting, the rate of the sub vi accelerates to the speed of the main vi rather than outputting every time a new value is received from the plc. This means my averages are calculated and outputted incorrectly.

Is there any way to control while loop in the main vi so that it only executes when fresh data is available from the sub vi? I have tried the LV help files on loops and structures but haven’t found anything relevant yet.

Regards,

Stuart Wilson

0 Kudos
Message 1 of 11
(3,304 Views)

Hi Stuart

Is the previously attached vi in the main-loop of your main vi? Could you post both of them (please as LV7.0)?

It's quiet hard to solve your problem without the possibility to have a look at your main vi.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 11
(3,292 Views)
Hi Becktho, thanks for the swift reply and interest. I have attached my main vi as requested. Excuse the mess. As you can fathom from the front panel, I am measuring "handling times" for a 5-step production sequence. Once I get the model right for one step, I can repeat for other 4. Basically, all i am trying to do is initially collect 20 values from the plc and continuously measure the max, min and average of this array everytime a new value is recieved from the plc. Any input on best practice, example code etc is greatly appreciated. Many thanks, Stuart
0 Kudos
Message 3 of 11
(3,289 Views)

Hi Stuart

Obviously you must have missed that I just use LV7.0. Could you attach it again for this version (Menu File >> Save with options >> Save for previous version)?

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 4 of 11
(3,287 Views)
Apologies... too eager to get this problem solved. This should be in the correct format. Thanks, Stuart
0 Kudos
Message 5 of 11
(3,284 Views)

Hi Stuart,

In addition to what bektho has said...

      It's not clear whether the sub-vi "Read Tag.vi" is to blame.  Also, the second time _this_ VI is called, the shifted-array will still be there, so if "elements subtracted" hasn't changed, then loop-abort condition will be true on first iteration.  Just a note on logic, an un-initialized shift-register saves data between runs - even if you stop the VI.  You may want to put some condition inside the loop that allows the data-array to be emptied.  (see attached example.)  The comment on the FP of your example implies that you would like to see intermediate indicator values on the FP of the caller.  You can do this with control referenc(s).  Your connector outputs only return the final values when the subroutine terminates. I added a reference to a DBL to the attached.  On your top-level VI, create a DBL, then right-click and create reference.  Wire this to the reference input I added.

You can use references to dynamically change values used in the subVI (change Property-node to Read.)

Hope it helps!

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 6 of 11
(3,279 Views)

First of all - I'm not used to the DSC-module.

But - if the tag was read event-based, the loop should wait until data is available. So as you describe the problem, I assume that your subvi reads the values each time it is executed. I don't know if Read Tag.vi waits until a value change occurs, but I'd suggest you to check, if it realy reacts just on a value change event.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 7 of 11
(3,278 Views)
Thomas/Dynamik, thanks for both your help. The Read Tag.vi timeout is set to -1 which means it won't read the value until that value has changed. This means I get a nice build up of array values while the sub vi is collecting 20 values. After these 20 values, as you quite rightly said, the sub vi terminates and starts to output the values to the top level vi. However it doesn't do this at its previously nice rate, it starts outputting constantly and does not wait for the new value from the Read Tag.vi. I will take the Read Tag.vi out of the while loop and use it to initialise the loop and see if that helps. If I use the new values from the Read Tag.vi to initialise the loop, does this mean the loop will not execute, and therefore not output, until it has this new value??? Dynamik, I can't use initialise array function because i need the values of previous runs in order to calculate the 'rolling' averages. Many thanks for your time and input. Stuart
0 Kudos
Message 8 of 11
(3,271 Views)
Another idea - place the sub-vi parallel to your main-loop and use another technology to update the frontpanel (references, events, ...).
In the sub-vi, use the average pt-by-pt. This does the job of averaging perfectly and you can define the number of elements to average.
 
Using this configuration, you would have both loops running independently from each other.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 9 of 11
(3,264 Views)


@Stuart Wilson wrote:

I am using the attached sub vi to return max, min, and average values received from a plc on our factory floor. The data in the sub vi is analysed every time the value in the plc changes rather than analysed after a set time delay.
... I am measuring "handling times" for a 5-step production sequence.



Stuart,
Are the total handling times for each step for each production sequence being logged to Citadel/DSC's database?

If yes:
Rather than using your rolling average subVI, you could write code that makes use of DSC's "Read Trace.vi".

With the appropriate start/end time selections, you'll get an array that you can cut down (if necessary) to the last 20 values to get your 'Last 20" average.

If you read the trace for the whole day/shift, you can easily get the max/min/average for the day with the ArrayMaxMin function you're currently using and Mean.vi (Functions > Math > Prob&Statistics).

Message Edited by Donald on 09-29-2005 11:33 AM

=====================================================
Fading out. " ... J. Arthur Rank on gong."
0 Kudos
Message 10 of 11
(3,174 Views)