LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structure executes twice (too many times!)

I have been developing a program for data acquisition and processing. The main block diagram has several case structures attached to a button set to "latch until released". Each case structure contains one subvi, sometimes more. My problem is that my case structures are executing twice, even though the button that is attached to them should be false as soon as the subvi has run once and thus they should only run once.

I can fix this problem by either instituting a time delay of 1 second in the main vi, or by merely "highlighting executing" on the main vi and then running the program.

So I think this is a timing issue. Is this odd? Is there a better fix? Is something else probably wrong with my program?

Thanks!
0 Kudos
Message 1 of 12
(4,601 Views)
Just a suggestion without seeing your code.If you just have a boolean controlling a case structure when it is false do nothing and if it true execute the subvi. or polling in other words. Why not use the eventstructure for this that way you can set it up to a value changed event of the button and when it is changed it will execute your subvi. You also said thatif you put in a wait function into the loop set to 1 Sec, this is way to long just for a button, are you sure you are not setting it to 1 mSec. Post some code and I can help you more.It seems as though the loop that runs your case structure us running way to fast and eating up all of the processor time. I would definetly try the event structure.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 2 of 12
(4,593 Views)
The problem lies in the mechanical action of your button. As it states, it will remain latched (true) until you release the button, meaning that your case structure will be exectuted for every time your main loop iterates and you still have the button pressed.
If you wish for your case structure to execute only once, set the mechanical action of your button to 'Latch when pressed'.
Hope this helps.
Message 3 of 12
(4,593 Views)
Didn't see the "Latch until released" part. Sometime it's the little things that bite you that make the worst wounds.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 4 of 12
(4,589 Views)
Okay, so a couple of things...

Yes, I do mean 1 second (1000 msec).

I meant switch until released (I doubled checked this, plus it wouldn't make sense that just adding a time delay would change the button position).

I am working on fixing an averaging routine that is very, very slow and shouldn't be, so that could be what is messing with the processor speed.

I have never worked with event structures before, but will play around with them if fixing the averaging routine doesn't help. Thanks for the input!
0 Kudos
Message 5 of 12
(4,583 Views)
My bad, the button fixes the problem...although my way should have worked also I think. But I still think that adding a time delay of 1 second shouldn't change button performance so something is acting up.
0 Kudos
Message 6 of 12
(4,582 Views)
I wouls say that adding the delay does not help with the button but does help with the processor. Post a version of your code or and image of your diagram and we will see if we can figure out your problem.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 7 of 12
(4,577 Views)
THe mechanical action "latch until released" will trigger the case at least twice, no matter how long the delay is.

Think about it this way:
A latch action (latch when pressed, latch when released) resets once the value is read.

If you have "latch until released", you actually have two successive events:
(1) when pressed, it turns on.
(2) when released, it waits until it is read before turning off.

No matter how fast you press the button, event (1) triggers your case. Even if you release the button 1ns later, it will now remain on and wait until it is read the second time before resetting to false.

Your wait will only help if you set it to "switch until released" AND you release it quickly.

Have a look at the graphics in the mechanical action menu. It illustrated the various actions quite nicely.

In your case only "latch when ..." action is appropriate.

Message Edited by altenbach on 06-22-2005 05:55 PM

Message 8 of 12
(4,572 Views)

It could also be due to the Type of Event. "Value Change" will execute the event twice; when button is pressed (0-1) and released (1-0).

Have a check on it.

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

Hi Jeswant,

 

congratulations for your first post in the forum!

But: you shouldn't have responded to an 11 years old thread…

 

(Lessons learned: check the dates of the posts! :D)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 12
(3,863 Views)