LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Log down the accumulated on/off time and number of cycles

Solved!
Go to solution

Hi,

 

I'm using LabVIEW to build a test program for monitoring the status of 9 switches for a long period of time, and I need to log down the following data:

 

How many times is the switch turned on?

How long has the switch been turned on?

How long has the switch been turned off?

I've built a VI but it looks really huge... So how can I simplify it?

 

Also is there any method to reduce the consumption of CPU resource? Such as using 'wait' function?

 

The data stored in the array is in this format:


 

 

    Cycle counter

   On-time

   Off-time

   Buffer

Switch 1

 

 

 

 

Switch 2

 

 

 

 

...

 

 

 

 

Switch 9

 

 

 

 

 


 

Thanks,

 

David

Download All
0 Kudos
Message 1 of 11
(3,992 Views)

One problem is that you are constantly polling the switches instead of just waiting for one to change state (event structure).  You can also use the boolean array to figure out which switch was changed by using a feedback node and comparing it with the new state of the boolean array.  Within all your case structures you are doing the exact same thing, you are just doing it to a different row of the 2D array.  Instead, just pass the 2D array through a shift register and index it in the shown case structure based off of the switch that was toggled.  Take a look at my attached VI and let me know if you have any questions.

0 Kudos
Message 2 of 11
(3,977 Views)

Hi JGar,

 

Thanks a lot for the help, the event structure really simplifies my program a lot. But for the switches I need to distinguish whether the switch is switched from on to off or off to on. So is it a good idea that I use implies function and nested case structure to achieve that?

0 Kudos
Message 3 of 11
(3,956 Views)
Solution
Accepted by topic author Dkaka

Your method would necessitate repeating the log F->T and T->F routines in every case structure for ever value, which can be a pain if you need to make a change to that routine.  Take a look at the code I've attached.  The one case structure that I have will contain just one instance of each routine and the row of the 2D array that it applies it to is dynamic and determined by which switch was toggled.  Also, you can just index the boolean array at the switch point and read it's value.  If True then it was a F->T transition, and if False it was a T->F transition.  One other thing, you had wired the stop button to the stop terminal of the while loop.  When you have an event structure it just sits there waiting for one it's events to trigger it into action.  Since there was no Stop event the Stop button never actually stopped the VI.  So I added back a Stop value change event so it would work.  Let me know if this makes sense.

Message 4 of 11
(3,948 Views)

Thanks a lot, just one more question: what if two switches togged at the same time?

0 Kudos
Message 5 of 11
(3,937 Views)

What you can do is check the state of each switch (my attached vi).  In the for loop if it sees there was a change, then it will execute the True False case within its True case (the False case will just pass it through).  The inner True False case will contain your routines.  Now when the switch array changes value it will check each switch to see if it needs to do any recording.

0 Kudos
Message 6 of 11
(3,928 Views)

Thanks a lot, that's exactly what I want.

0 Kudos
Message 7 of 11
(3,919 Views)

Hi JGar,

 

I tried to use a DAQ assistant to replace the control so that I can monitor real switches, but it does not work. Do you have any solutions for that? I found relevant topics about it but had no clue of implementation. http://www.ni.com/tutorial/5384/en/

 

Thanks a lot.

 

0 Kudos
Message 8 of 11
(3,877 Views)

If you are using real time data for the switches then you will have to get rid of the event structure since that is registered to only trigger when there is a change in the switch array control on the front panel.  Once you have removed that event structure post your vi so I can see how you have everything set up and I'll see if I have any suggestions.

0 Kudos
Message 9 of 11
(3,847 Views)

I used a NI USB 6501 DAQ digital inputs to acquire status of the switches, and a corresponding DAQ assistant is used in the VI.   BTW is it a better way for real time data system to use producer-consumer structure?

 

Many thanks.

0 Kudos
Message 10 of 11
(3,825 Views)