LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Hourly Average

I am monitoring the performance of our manufacturing plant on a daily basis. One of the things I would like to indicate on my front panel is how the plant is performing hour-to-hour throughout the production shift. I would like to measure the average between two times (e.g. average production rate for 07:00 – 08:00, 08:00 – 09:00… 14:00 – 15:00 etc) and report this on a numerical indicator. I have attached a jpeg of my block diagram to best show you what I am aiming to do.

Basically, I have tried to initialise the loop at 10:00 hours; gather data from a memory tag in an array (values are read out upon change); close the loop at 11:00 hours; upon closure of the loop average all the values collected in that hour. This doesn’t seem to be working.

If you can spot any problems with my code, I would really appreciate an alternative way of doing this. Your help is greatly appreciated.

Best regards,

Stuart Wilson

0 Kudos
Message 1 of 11
(4,184 Views)
Main problems I can see are the following:
1) the Get date and time etc. function also returns the current date (as stated by the name), so you need to set the current day in constants used for the comparison
2) the code on the left of the while loop doesn't wait as you need: it only throws a boolean (false at any time except exactly at 10:00:00) to a tunnel on the loop structure border
Other suggestions:
3) you may need to initialize the data shift register if you reuse your vi later
4) the array size function is better used outside the loop, once the data are fully collected.

Paolo
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 11
(4,173 Views)

Hi Stuart,

As pincpanter said...

The code on the left doesn't do much and you should initialize the shift register otherwise you will get surprises.

What you could do is create an array of start times (ie. 7:00 to 15:00).   Within the while loop do a compare (System time vs time in the array) and use the boolean to trigger a Case Statement that takes the timestamp and your data to update your display.  In order to avoid multiple triggering of the Case Statement, you could update the index to the time array within the Case Statement and the system time would have to reach the next hour before the Case Statement is triggered again...

Ray

Message 3 of 11
(4,164 Views)

Many thanks for the reply Paolo.  A few questions though:

Re: 1) is there a Get time only function?  I do not want to have to ask the user of this program to manually enter todays date in the constant every time we run the vi

Re: 2) If the boolean won't initialise the while loop then can you offer any alternative to start the while loop at the specified time and stop it after 1 hour?  I am pretty inexperienced and have run out of ideas

Re: 3) I want the loop to execute once in a day between two specific times.  Does this mean i can ignore the initialising of the shift register?  I also don't want a zero in my array as this will throw out the averages.

Re: 4) Why is the array size better used outside loop?

A very big thanks for all your answers.  I look forward to hearing from you again if you get the time.

stuart

0 Kudos
Message 4 of 11
(4,162 Views)

Ray, a couple of quick questions if get a chance to revisit this...

If i initialise the shift register with zero, I will have forced a zero into my array and this will throw out my averages will it not? i.e. how do I initialise it without spoiling my analysis?

I understand perfectly what you are suggesting as an alternative, however I am a little lost on how to achieve it. Firstly, how do i create an array of start times? If it's only start times, how does the vi know to finish at 15:00 (the end of production).  System time obtained using "Get date/time in seconds", then as Paolo explains above, I will need to put the date in manually every single time i run the vi - can this be avoided?  I also don't want to lose the 07:00 - 08:00 data once the 08:00 - 09:00 calculates.  Will these be possible using your suggestion below?  I have attached a screen shot of my front panel to show you the end result i am looking for.  If you could show me exactly what kind of approach you mean, this would help me greatly.

Many thanks for your help so far.

stuart

 

0 Kudos
Message 5 of 11
(4,151 Views)

Hi Stuart

I did something similar a while back. This is the approach I used.

Regards

0 Kudos
Message 6 of 11
(4,148 Views)
Stuart,
 
A question that might lead to an alternate method : Is the memory tag that you're building this array to get hourly averages logged to Citadel?
If yes, then when the time rolls over every hour during production, you could just use 'Read Trace.vi' and 'Get Trace Statistics.vi' to get your averages (rather than continually using 'Read Tag.vi'). Rough v6.1 demo attached, but it may be broken in v7 because of changes to the above VI's.
 
 

Message Edited by Donald on 10-26-2005 10:08 AM

=====================================================
Fading out. " ... J. Arthur Rank on gong."
0 Kudos
Message 7 of 11
(4,110 Views)
Hi Donald, that certainly seems like a simplified approach - thanks!! However, due to our LV version differences I'm afraid I can't see how the "Read Trace.vi" is connected with the timestamp. Could you (or any reader) please send me a screen shot of how this should be connected, or even a way of opening the file so that I can see the older code?? Thanks for your continuing support, Stuart
0 Kudos
Message 8 of 11
(4,083 Views)


@stuart wrote:
...  I'm afraid I can't see how the "Read Trace.vi" is connected with the timestamp. Could you (or any reader) please send me a screen shot of how this should be connected, or even a way of opening the file so that I can see the older code??

Sorry, Stuart. In LVDSCv6, there were seperate terminals for the Start and End times. In LVDSCv7, I think it was changed to a single terminal to which you have to feed a cluster consisting of the Start and End timestamps. Check the context help for 'Read Trace' to verify. If yes, then you just need to bundle the Start and End timestamps as per the attached mock up sceenshot, and check to make sure you get the bundle order correct.

Your icons for the VIs will probably be different since what are "traces" in v7 were "historical trends" in v6 (... and timestamp representation didn't exist either, time was either a U32 or DBL).

=====================================================
Fading out. " ... J. Arthur Rank on gong."
0 Kudos
Message 9 of 11
(4,038 Views)
Hi Donald, I hope you manage to revisit this thread. The code you attached is EXACTLY what i am looking for. I have made the necessary updates to include the "Read Trace" and "Get Trace Statistics" vi in version 7.1, however upon turn of the hour, the data is not outputting to the cluster of indicators as it should. I get the following message in the error string: NI-488: Error connecting to driver or device. --- VISA: (Hex 0x0) Operation completed successfully. I have attached a jpeg of my front panel just after the turn of the hour. I am reading the same data from the same PLC using other LV programs no problem, so i am a little unsure of what the problem is. Is there any reason why the code you sent me wouldn't show data on the indicator cluster? Thanks for your help with this one. Best regards, Stuart
0 Kudos
Message 10 of 11
(3,993 Views)