LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

register time when switch closed briefly OR remains closed

Hi!

 

I have attached the current VI I am working on and I am having a little trouble working out the logic for my particular interest.

 

The basic application of this VI is to time an interval registered by a start switch and then ended by a separate stop switch. The difference is then found between those two times.

 

On the stop switches (which is the lower half of the block diagram) I am trying to register the stop time. Right now, the time registers when the switch closes and remains closed until the program stops. Currently, inorder to register the time, the switch must remain closed throughout the entire program.

 

I would like the stop time to register if the switch remains closed OR if the switch is closed and then opens again (due to the weight bouncing off/rolling off) I would like it to work in either situation of the weight keeping the switch closed OR the weight initially closing the switch and then rolling off.

 

In either case, I would like the first moment the switch closes to be the time used in the time interval calculation. I think it should be a pretty easy fix...I apologize if it's really basic...

 

Thanks so much!

0 Kudos
Message 1 of 22
(3,762 Views)

Blizabeth,

 

I would consider adding a shift register to the inner  For Loops that carries an array of booleans initialized to false.  Then, set the element of the array to true the first time the switch closes.  You can use this with an AND to make sure that the event only registers one time.

 

Cheers, Matt 

0 Kudos
Message 2 of 22
(3,756 Views)

Could I see this on the block diagram? I'm a visual learner and sometimes get mumbled up in the logic of the sentences.

 

thanks so much!

0 Kudos
Message 3 of 22
(3,753 Views)
actually, how do I add a shift register to the inner for loop? I was able to make sense of everything else...
0 Kudos
Message 4 of 22
(3,751 Views)
Simply right click on the input node for the array, and select shift register.  You will need to wire both the inner cases correctly....
0 Kudos
Message 5 of 22
(3,744 Views)

So I was able to try your suggestion and have attached my attempt...I'm still confused how to connect the shift register of the inner for loop?

 

I really appreciate your help!

0 Kudos
Message 6 of 22
(3,741 Views)

Blizabeth,

 

I realize you are a visual learner, but you should probably think about this a little bit (the problem is fairly straightforward and a good learning exercise).  Looking at the VI I realized I led you a little off-track.  

 

  1. You need some way to say that we have already registered the first event where the boolean changes.  I have suggested an array of booleans initialized to false (i.e. the boolean has not changed from F->T).  We will go with this.
  2. You need away to keep track of this array - shift registers are a simple way to do this as they occupy an allocated slot of memory.  
  3. The array needs to be initialized one time for the entire operation of the VI (this is where I think I got you off track) and the state of each value needs to be tracked through each execution; in your VI, they are being reinitialized every time the while loop executes (so the shift registers in yours will not do what you need).  If you don't understand shift registers and how to use them (they are pretty fundamental to LV), here are two papers on them and some examples of how to use them: http://zone.ni.com/devzone/cda/tut/p/id/7592 and http://decibel.ni.com/content/docs/DOC-2158.
  4. Use the boolean for the proper index to say something like "if switch == TRUE AND first_time_pressed == TRUE then set_time() else do_nothing()".
If you can get all of this down, this should solve your problem.  Also, as someone suggested in your previous post, consider not using property nodes to change values of indicators or controls - these are poorer performers than local variables; consider using local variables to properly initialize your times and then update them via the actual indicators.  Regardless of the application, this is just good programming practice.
 
I hope all of this helps and good luck with your app.  I know it's tough learning this stuff; the curve is steep but it will pay off in spades.
 
Peace, Matt 

 

Message 7 of 22
(3,722 Views)

Matt will probably get pissed off at me, but I think this is a bit above the beginners level, so I added some code to record the time the stop switch reopens after it has been closed. 

 

I changed your lower shift register because the old way made no sense to me.  Now that shift register is used to hold a flag which states if the switch has been closed once or never closed.  The case structure determines if the switch has been closed and is now open, and if so then it records the reopen time.  After the loop, the new For Loop calculates the time from the switch closure to the reopen.  But if th switch never reopens, then this loop is meaningless.  You can modify it to produce something meaningful, or disregard it completely.

 

The attached vi is in LV2009.

 

- tbob

Inventor of the WORM Global
Message 8 of 22
(3,717 Views)

Haha...never, Tbob!  I was just trying to motivate a little thought given the fact that we have attempted to guide the user through a similar problem over here.

 

Matt

0 Kudos
Message 9 of 22
(3,701 Views)

mtat76 wrote:

Haha...never, Tbob!  I was just trying to motivate a little thought given the fact that we have attempted to guide the user through a similar problem over here.

 

Matt


 

I didn't notice that this was a second post for the same vi.  Glad you caught that Matt. 

Blizabeth37, you should stick to one post for the same vi, even though your problem may be different.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 22
(3,693 Views)