LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to run for loop only once when condition is true?

Highlighted

Hello LabVIEW Community,

 

I have a code that is plotting datapoints from a delimited file as attached below.

Whenever the data is less than "-5", I have a keyboard simulation event, inside the for loop, that presses down the keys 'j' and 'k' continuously. (ASCII Code of 'j' and 'k' are 74 and 75)

 

However, I only want to press down both 'j' and 'k' once whenever the value is less than "-5".

 

For example, in the image below, I would like to press down 'j' and 'k' four times which should result in "jkjkjkjk".

I'm not really sure how to do this and would appreciate any suggestions. Thank you in advance!

 

jackhsu66_0-1602567308590.png

 

0 Kudos
Message 1 of 7
(283 Views)
Highlighted

Hi Jack,

 


@jackhsu66 wrote:

However, I only want to press down both 'j' and 'k' once whenever the value is less than "-5".


So you want to output some data whenever a "value" currently is less than -5 AND was greater/equal -5 before?

 

What about using a shift register to access the "before value"?

What about using a boolean function (like AND) to combine several boolean values?

What about using a ready-to-use function to detect such "falling/rising edge" occurances in your "value"? Ever heard of Pt-By-Pt_BooleanCrossing?

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 2 of 7
(261 Views)
Highlighted

Hi GerdW,

 

Thank you for your suggestion! Really appreciate your time.

 

I used the "shift register" and "AND" command and was able to count places where the value is currently less than -5 and was greater than -5 before. However, I have these noises in my signal as shown below where I only want to count once. (The image shown counted 4 times).

 

Any suggestions on how to eliminate these noises, or just count this signal as one? Thanks!

 

Capture.JPG

 

Capture.JPG

 

 

 

 
 
 
 

 

0 Kudos
Message 3 of 7
(223 Views)
Highlighted

@jackhsu66 wrote:

Any suggestions on how to eliminate these noises, or just count this signal as one? Thanks!

 


A PtByPt filter should help. Probably a low pass filter, but there are many filters that would help.

 

Alternatively, add a shift register and only set the 'up' state if the data is up for more then n samples. That is, if x>-5, increase counter (keep counter in a shift register). If counter>10, it's considered up.

 

You can probably do with one shift register, by making smart use of the counter.

Message 4 of 7
(215 Views)
Highlighted

I think you should physically clean up that signal before it ever gets to the detector.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 7
(181 Views)
Highlighted

@billko wrote:

I think you should physically clean up that signal before it ever gets to the detector.


All positive values seem to go to the exact same value, and so are the negative values.

 

It looks like a digital problem to be. Parsing maybe, or an unhandled time out or bytes that get lost during acquisition?

 

But I agree, fixing it is better then a bandage.

 

You'd probably still want some kind of mechanism to prevent triggers on noise around -5. Either a counter or a asymmetric trigger (if down, go up if >-3, if up, go down if <-5). 

0 Kudos
Message 6 of 7
(175 Views)

@jackhsu66 wrote:

Hi GerdW,

 

Thank you for your suggestion! Really appreciate your time.

 

I used the "shift register" and "AND" command and was able to count places where the value is currently less than -5 and was greater than -5 before. However, I have these noises in my signal as shown below where I only want to count once. (The image shown counted 4 times).

 

Any suggestions on how to eliminate these noises, or just count this signal as one? Thanks!

 

Capture.JPG

 

Capture.JPG

 

 

 

 
 
 
 

 


Let's learn a little bit about the HARDWARE.  (oh, yes the magic 8-Ball is rolling) then we can chat about shock vibration and bouncing relays.   Proper electrical engineering can really help you with these pesky software problems 😉

"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 7
(158 Views)