I have attached my VI for reference.
I am receiving signals from a load cell and pressure transducer. If both the load cell signal and pressure transducer values are lower than the user input and constant, respectively, then I am generating a 5V signal to close a relay coil (True Case). Alternatively, if the load cell or Pressure transducer receives a signal greater than the user input or constant, respectively, then I want to stop generating the 5V signal and end the program (False Case with 0,Default Case stopping the program).
Currently the user input and constant are random values used to test my program. The program is not stopping if the case structure is false. It appears that it is stopping the 5V signal, but I have not actually tested this with a relay. I hope to have the program functioning prior to testing the hardware to minimize possibility of damage to hardware. Any help would be greatly appreciated.
Solved! Go to Solution.
Your while loops are nested, not running in parallel. The outer while loop will not possibly stop until all code inside of it (including the inner while loop) has finished executing.
Why are you continually writing the same value (either 0 or 5) to the analog output? Just writing it one time will be enough, you do not need an inner while loop. Do not write the 0 to it when you are done.
You can initialize your DAQ task once on the left side of your loop, and close it once, on the right side of the loop.
Do not create almost identical copies of your code in the case structures. The identical part should be taken outside the case structure.
Wow, what a mess. You are only reading the load cell exactly once when the program starts, the you are going into a true or false case which basically look identical (why is there so much duplicate code?!). The boolean at the loop input tunnel of the inner while loop will always have the same stale value and the inner loop will run until the respective stop button has been pressed. At which time the outer loop will terminate. (it would only continue if the orange wires would have a value of 1, but it can only be 0 or 5, both conditions will stop the outer loop.
So, the load cell is only read once per run of the program. Seems useless. What is the purpose of the "Start" button? Also try to eliminate most of the dynamic data.
I would recommend to learn about dataflow and start with a few basic tutorials.
I have (to the best of my understanding/knowledge) edited the code to reflect what you have said. My questions are:
1) How would I make the load cell and pressure transducer continually read values and only perform the case structure when the AND function changes its boolean value?
2) How can I stop the entire routine when the value written by the DAQmx is a 0.
It still makes absolutely no sense to have a case structure with two identical cases. All you need is the "select" wired to the boolean. You need to initialize the DAQ output task only once before the loop and not with every iteration of the loop.
What determines the loop rate? (the word "continually" is too vague!)
You really need to start with some basic LabVIEW tutorials.
Maybe I can ask this in a different way. I have removed all code from the loops. Now the code runs just once and produces an output of either 5V or 0V based on the signals received prior to the AND function.
I only want to write a new voltage value if the and condition changes. For example...The initial signals produce a true value for the AND and the DAQmx initially writes 5V. I would like the code prior to the AND to keep retrieving signals until the AND becomes false. At this point I want to write a new value with the DAQmx. This value would be 0V. Additionally at this point I would like to end the program. How would I do this?
Altenbach, I have watched many LabVIEW tutorials via YouTube, and I have read LabVIEW documentation. I simply do not know which direction to go. I don't know if I need a while loop, case structures, both, etc. I'm feel I could use any of these to produce the same functionality. I am coming to the forums to ask for help and guidance from someone who is more experienced. It makes more sense to ask for guidance from someone who is experienced rather than sift through hours of information that could be potentially irrelevant to my functionality. I don't want the questions to appear as if I am lazy and simply just asking for the code to be done for me. I just want some guidance as to what exactly I should read more about.
Your second paragraph basically describes just what you should do. The part you want to do repeatedly, "keep retrieving signals until the AND becomes false", goes in a while loop so it happens repeatedly, with the output of the AND wired to the conditional "run" terminal of the loop. When it becomes false the loop will stop and execution will continue on to whatever's next in the dataflow, in this case "write a new value" and "end the program".
So I understand that I can "continue if true" which allows me to keep retrieving signals until I receive a false from the AND.
Would this mean that I need to make the DAQmx generate 5V upon starting the program and then only write the 0V when the while loop stopped?
That's right.You'd want to write to the output at the start if you want it to be something other than the default value while you're in the loop. Also, be aware that if there's no dataflow connection between the loop and the DAQmx stuff to the right of it, then they'll both execute in parallel when your program starts; if you want the DAQmx stuff to wait until the loop is done, you need some connection that exits the loop and goes to an input on whatever should run next. Usually the error in would be used for this.
I want my initial DAQmx to be 0V. Only once I have determined the AND to be true do I want the DAQmx to generate 5V. Upon determining that the AND is false I would want to return to 0V.
I feel I need to add a case structure because I want to write a value based on whether the while loop is true or false. Is it possible to execute the case structure only once the AND value has changed. I do not want to constantly rewrite a value, as this would waste memory and damage hardware.
If there was any way to trigger an event structure on the AND function, then I feel like my solution would be using an event structure.