08-31-2009 01:17 PM
I am making a power demand meter that will warn when too much kW is being used. It counts pulses per minute and I am have problems with my arrays. Every minute I would like to record the current pulse count into an array to get 15 entries (minutes). Then remove the first entry (first minute)and places the new one at the bottom of the list. Then it takes the first and last counts, subtracts therefore getting pulses per 15mintes on a rolling scale. I have included my image and just dont know the problem because it doesnt do anything.
Solved! Go to Solution.
08-31-2009 01:37 PM
08-31-2009 01:41 PM
08-31-2009 01:54 PM
I indicated the tunnel below. The value added to the array will always be the value of this tunnel when the loop started its execution.
08-31-2009 01:54 PM
Having the code is more efficient that a screenshot, but a few things to hopefully kick-start you in the right direction.
1. A 60 sec delay is almost always a very bad idea, if you click the stop button, it will take up to a minute to react.
2. I assume the hidden loop on the left supplies the data. As written, a single value is passed to the while loop and never updated. Irregardless of other errors, this will be a problem.
3. The flat sequence is completely unneccesary. Except for timing operations, this is almost always true. LV dataflow will almost always take care of this for you.
4. As currently wired (unless there is a hidden bend in the wire), the Array Subset function is chopping off the first 15 elements of the array, you would rather have the last fifteen elements. A simple method is to reverse the array, take the first 15 elements and reverse again. Seems complicated but the reversals cost you very little and it even works if the array is smaller than 15 elements.
5. The shift register is good for this application, but you should either embed this while loop into your data taking loop with a false constant wired to the stop terminal so it loops once, or just add a shift register to the data taking loop to hold the data. And with an uninitialized SR you are in for some unpredictable behavior.
This all assumes you want to fix the existing code. My suggestion is to look into a state machine, in this way you don't slow down user interactions (like the stop button) waiting for the slow acquisition.
08-31-2009 01:55 PM
08-31-2009 02:13 PM
08-31-2009 02:49 PM
It may still be useful to you to explore a state machine architecture. A search on 'state machine' will provide lots of examples and discussion. For your current VI, the first iteration will give you an odd result, since the shift register is no initialized. I would connect the output of your query directly to the input of the loop. See below.
08-31-2009 02:56 PM
You can forgo the shift register in the outtermost loop and just connect the output of the flat sequence to the input of the inner loop. Also, you can use the error cluster to control execution order and remove the flat squence.
08-31-2009 03:15 PM
Jack,
That inner loop will run forever (False wired to stop terminal) and will always use the same data point (tunnel going into that while loop).
Perhaps you want to eliminate the inner while loop and move the shift register to the outer??????