LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array help for demand meter

Solved!
Go to solution

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.

 

 

demand.JPG

0 Kudos
Message 1 of 12
(3,788 Views)
The way you bring the data into the loop means that it will always write the same value to the array for every iteration.  Is that the problem?
0 Kudos
Message 2 of 12
(3,776 Views)
It could be, but I am not sure what you mean. The value coming from the outside of the while loop is an integer that changes because it is the current count. Do you mean how I am using the shift register?
0 Kudos
Message 3 of 12
(3,771 Views)

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.

 

 

original.PNG

0 Kudos
Message 4 of 12
(3,755 Views)

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.

 

 

0 Kudos
Message 5 of 12
(3,754 Views)
You seem to have a problem understanding data flow. Nothing will come from the first loop until that first loop stops. Once the first loop stops and the second begins, nothing new gets passed into the second until it stops and you restart everything. So, the integer is never changing inside that second loop.
0 Kudos
Message 6 of 12
(3,753 Views)
I see what you guys mean now about the first value always being the same. I made a few changes as recommended and have attached the vi.
0 Kudos
Message 7 of 12
(3,737 Views)

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.

 

demand meter.png

0 Kudos
Message 8 of 12
(3,724 Views)

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.

 

demand meter.png

0 Kudos
Message 9 of 12
(3,717 Views)

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??????Smiley Wink

Message 10 of 12
(3,705 Views)