09-26-2021 07:40 PM - edited 09-26-2021 07:44 PM
Hello,
I have a larger design (not my own) that I'm attempting to modify. I am VERY new to Labview. I needed something that would toggle back and forth on a false to positive edge.
I used some edge detection logic that I've seen suggested in some other posts to try and do that inside a case statement that used what I think is a local variable.
Logically, it seems simple enough, but it also seems that at times either it does NOT toggle, or perhaps it toggles 2x (the result being the same). The input is from "inside" the larger project, so in a hardware sense, it would not seem to be asynchronous (to everything else in the project, so to speak) at least to me.
However, I will admit to NOT understanding race conditions in Labview, and maybe that is the issue here.
I've given up trying to use this approach, but I am still trying to use the edge detector for another purpose (being driven by the same signal) and am worried that since I don't understand why this occasionally had a problem, that my use of the edge detector is also doomed to fail on occasion.
Any explanation why this case statement toggle approach seems to fail, especially as it involves edge detection would be GREATLY appreciated.
BTW, I'm doing this (for free - at least right now) for a company that can't afford to update from the 2009 version (maybe they're getting what they're paying for....)
Thanks (just for reading this far).
09-27-2021 02:00 AM - edited 09-27-2021 02:14 AM
Simple solution:
09-27-2021 02:09 AM - edited 09-27-2021 02:31 AM
@LV_Neophyte wrote:
I needed something that would toggle back and forth on a false to positive edge.
09-27-2021 11:53 AM
To the OP: this is purely a preferred style thing. One of the very few things I'm inclined to disagree with altenbach about is the use of "Greater than" for boolean comparisons. While he finds it very intuitive, I definitely don't.
So if your brain's wired more like mine than his, here's the same code using the style of boolean logic I prefer to use. It's the node named "Compound Arithmetic" which has nice properties of expanding for multiple inputs and the ability to individually invert any of the terminals. The little circle on the upper input terminal in the pic below means that input is being inverted.
The logic for seeing a F->T transition then reads literally as: "prev value NOT True AND present value True", or more casually as "was False before and is True now". That feels more intuitive to me. YMMV.
-Kevin P
09-27-2021 12:11 PM
Thank you for your reply. I'll attempt to address each of the items in your reply in the same order.
1. I've attached the VI as requested. Please remember I'm stuck on version 2009.
2. Yes, I want to detect the night to day transition (but NOT the day to night transition).
3. & 4. I was attempting to use this (in effect D_PP - "Day Ping Pong") to select every other day, or even and odd days, if you like. It then when on to select the case in another case state.
5. Not sure that I understand "reasonable loop rate". As you may have surmised, this transition only occurs once every 24 hours, and that's when I want to flip the state of D_PP. (Sorry if that doesn't address your concern.)
6. So the case structure would have a NAND gate for the "True" case and an AND gate for the "False" case, with the feedback and inversion outside - OK I understand that, but I'm not sure how to accomplish the same thing without a case structure - sorry I guess I'm just not experienced enough....
7. Do you mean that I should skip (what I think is) the local variable and wire an output of the case statement back around to the input?
8. I think this suggestion would give me BOTH edges, and I only want ONE.
09-27-2021 12:17 PM
@Kevin_Price wrote:
To the OP: this is purely a preferred style thing. One of the very few things I'm inclined to disagree with altenbach about is the use of "Greater than" for boolean comparisons. While he finds it very intuitive, I definitely don't.
Once we agree that T > F, my version is, at least for me, easier to read than boolean gymnastics (I even use "not equal" instead of XOR, for example!). Using plain comparisons on booleans (=, !=, >, <) is simpler than fancy, partially inverted compound functions, or even "implies". 🙂 I am sure the compiler reduces it to the same machine code anyway.
True, LabVIEW has some holes where it forgets that T>F. While we can sort boolean arrays just fine, we cannot use array Min&Max on them to get the desired index (1D, 2D, etc.) even though we can guess what the result should be 😞 )
Of course we also have the boolean crossing tool. No extra code needed. 🙂
09-27-2021 12:30 PM - edited 09-27-2021 12:41 PM
@LV_Neophyte wrote:
1. I've attached the VI as requested. Please remember I'm stuck on version 2009.
2. Yes, I want to detect the night to day transition (but NOT the day to night transition).
3. & 4. I was attempting to use this (in effect D_PP - "Day Ping Pong") to select every other day, or even and odd days, if you like. It then when on to select the case in another case state.
5. Not sure that I understand "reasonable loop rate". As you may have surmised, this transition only occurs once every 24 hours, and that's when I want to flip the state of D_PP. (Sorry if that doesn't address your concern.)
6. So the case structure would have a NAND gate for the "True" case and an AND gate for the "False" case, with the feedback and inversion outside - OK I understand that, but I'm not sure how to accomplish the same thing without a case structure - sorry I guess I'm just not experienced enough....
7. Do you mean that I should skip (what I think is) the local variable and wire an output of the case statement back around to the input?
8. I think this suggestion would give me BOTH edges, and I only want ONE.
Can you explain in detail what your desired states are?
09-27-2021 01:49 PM
Good call on the use of the built-in Boolean Crossing function. Both more clear and more versatile than our raw code. Same startup behavior too -- edge detection output always False on first call.
-Kevin P
P.S. ....although FWIW, its internal logic IS a version of my boolean "gymnastics" rather than > or <. 😋
09-28-2021 10:19 AM
Sorry for the delay, NI put me in a 24 hr timeout for being a new user!
In answer to altenbach's questions:
Can you explain in detail what your desired states are?
1. Program start D/N - could be either, I can't control this; D_PP - I don't care, could be T or F
2. D/N = T, D_PP = D_PP
3. D/N T->F, D_PP = D_PP
4. D/N F->T, D_PP becomes NOT D_PP (it toggles).
5. D/N F, D_PP = D_PP
FWIW, I changed the scheme based on my (in retrospect) incorrect interpretation of altenbach's point #7 in the first response.
I went from this (which fails to switch properly at times):
To this (which seems to be more robust):
Note that LV added the feedback node when I wired the output back to the input.
This leads me to believe that my original attempt caused a race condition whereby both the T and F cases were evaluated in the same loop iteration meaning that D_PP switched twice when it should have only switched once.
With the added feedback (delay), that's impossible, I think.
Thanks to everyone for their time and effort - I feel good about solving the problem.
09-28-2021 10:42 AM - edited 09-28-2021 10:43 AM