LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error in timed loop

Greetings,

I am a graduate student working on a project and I have got a bug in my code and I do not know how to fix it. I have attached my code. The purpose of this code is to run a loop of 4.5 seconds in length 45000 times. In the first 2.5 seconds it is supposed to output 0V to a DAQ channel and in the last 2 seconds it is supposed to output a voltage of 1V to the same channel. If within the first second of the new cycle a voltage change from a switch at another channel is not detected the code is supposed to stop and indicate a failure. If no failure is detected then the code must record the iteration and time of the voltage reading.

For testing purposes I eliminated the external links and input a simple numerical indicator for the output and a case structure for the input so that when the iteration is 500 ms old the 'switch' is activated. However, my code never gets going, my iteration duration never gets above zero and I think it gets hung up on the array building section.

Any help would be appreciated. Thanks,

Taylor
Message 1 of 5
(3,231 Views)

Taylor,

I did not dig too far into your problem however I have a few LabVIEW tips that may lead you to the solution:

1- Refrain from using local variables: If you want to reference a value the best way is to wire the terminal to the value desired. Refer to the attached file where I modified your code to implement this style in a few example cases. Wires should always be used because it ensures that the data flows correctly through your program (whereas if local variables do not ensure this because based on dependences values may arrive at different times). I'm guessing this is why you are having problems running your program.

2- Event structures: If you use an event structure it is good programming practice to place the the control which triggers the event inside the structure (as I did with the start control in the attached modified file). Even though the program will response the latching action of the control will not be implemented. So for instance with your start button it will not return to the off state when the program ends.

3- Search the NI Knowledge Base/Discussion Forums for answers to your questions. A lot of times there has already been an extensive discussion about your specific topic.

Let me know if these tips help or if you have any other questions/concerns.

Cheers,

Jonah Paul
Applications Engineer
National Instruments

Jonah Paul
Marketing Manager, NI Software
0 Kudos
Message 2 of 5
(3,217 Views)
I think you should sit down and do some tutorial first before diving in to a project like this. You seem to have many misconceptions about dataflow. I won't have time to look at it in details at the moment, but here are a few pointers.
  1. Get rid of the outer event structure. An event structure that is not inside a loop is quite odd. Simply run the VI and execute the code. No need for the extra step.
  2. Get rid of the inner small event structure. It has no place inside a timed loop!
  3. Your "save to file" portion is meaningless. SInce there is no data dependency, it will write to a spreadsheet file exactly once way before the local variables have received any useful data.
  4. Your tiny case structure can be deleted because it just repeats the input boolean. Just replace it with a plain wire.
  5. Your "equal FALSE" below is just an "invert".
  6. A FOR loop with one iteration can be deleted sice the shift registers are initialized.
  7. Why all these local variables?
  8. The comparison of [i] with "number of cycles" belongs inside the timed loop. In your implementation it win't get data until the loop finishes.
  9. ...
  10. ........

Maybe run your code with execution highlighting to see what's really happening. Good luck! 🙂

0 Kudos
Message 3 of 5
(3,214 Views)
Thanks to all who replied. I am still learning. Regarding the use of local variables, that was a suggestion of one of the technicians in my department.

There is a lot to think about but I do have a question. I was rereading the timed loop help and realized that iteration duration is not what I thought. Is there a place where I can get the iteration time?

Thanks,

Taylor

PS - I have only LabVIEW 8.0.
0 Kudos
Message 4 of 5
(3,208 Views)
 

Taylor,

Altenbach is right on, you should sit down and get a good LabVIEW fundamentals foundation before you continue. You can do this through numerous methods. I recommend going through the "New to LabVIEW" content in the Getting Started dialog box when LabVIEW initial boots up to get basic documetation. In addition there are hundreds of ready made examples that you can look at which also can be found in the Getting Started dialog box at the bottom right-hand side. Finally, National Instruments also offers Training classes that are an excellent way to get acclimated to the power of LabVIEW.

Once you have completed some training and have a little better handle I recommend that instead of using a timed loop to coordinate your program flow (I'm assuming that you will be running this in a Windows environment) you should use while loops with a "Elapsed Time" VI inside which will delay each state for as long as you want (in your case 2 or 2.5 sec). However you have to be careful about reseting the Elapsed Time VI as well delaying the while loop when using this design.

Please take some time to get a good base then go from there.

Cheers,

Jonah Paul
Applications Engineer
National Instruments

Jonah Paul
Marketing Manager, NI Software
0 Kudos
Message 5 of 5
(3,185 Views)