LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Program keeps adding data after limit of program is reached

I created a program in labview that controls a stepper motor using a parallel port. The program works fine with respect to the rotation of the system in both directions but the motor can only rotate no more than 360 degrees. I programmed the fuction so that when the user inputs a value this value is recorded. The next time the user inputs a value, the previous value is read and added to the new one and, again, saved on the spread sheet. When the total value reaches 360 degrees, the program gives the user an error displaying to rotate the program in the opposite direction. Until this point the program works fine. The problem is that if I add 0 degrees after the error is given, the program adds the previous number that was read and adds it to the spread sheet and is disrupting the calculations that are supposed to be on the spread sheet. Is there any way that I could modify the program so after 360 degrees (hence less than 0 degrees) the program stops adding or substracting numbers automatically? 

 

 

Download All
0 Kudos
Message 1 of 4
(2,361 Views)

First tip,  wire up the error wires across all of your VISA functions.

 

Second,  how is your program supposed to run? Is this a subVI to another VI?  Your program only runs once.  So I don't know how you ever "stop" the program.

 

Perhaps you want to use the In Range and coerce function?  Perhaps you need to add another case structure that handles the special error you are getting before it becomes a problem?

 

Without understanding how the program is supposed to work (exactly what are you doing when you "add 0 degrees after the error is given"?) it is difficult to give you more specific advice.

Message Edited by Ravens Fan on 09-14-2009 10:56 AM
0 Kudos
Message 2 of 4
(2,355 Views)

Thank you, I wired the errors across my VISA functions.

 

When running the program, the user inputs a certain amount of degrees (0<x<360), after the number of degrees is reached the program stops. When I say that i add 0 degrees after it reaches 360 degrees (or 0 degrees) is that when the program gives me the error when it reaches 360 degrees and i keep adding numbers in the same direction the program will keep adding this numebrs to the spread sheet. For example, one of the times i was testing the program, the motor reached 360 degrees, the "degrees of rotation in" read 15 degrees (because it was the amount the i rotated it) "degrees of rotation out" also read 15 and the "total degree count" read 360; there the program would tell me to chage the direction of the motor. Instead of rotating the motor in the other direction, as requested,  I decided to test the error to see what would happen and i literaly added 0 degrees in the program. As expected the motor did not move, "degrees of rotation in" read 0 degrees, but for some reason "degrees of rotation out" read 15 degrees and "total degree coun" read 375 degrees. If i kept running the program (adding the same 0 value) in the same direction it would keep adding 15 (last value before reaching 360 degrees) to the spread sheet.

 

This program will be posted public so people can control the motor online, I need to fix this problem so the count of degrees is accurate. What did you mean by using the In Range and coerse function? Why would I use those functions?

 

Thank you very much for your help. If there is any further information that i can provide you with please let me know.  

 

0 Kudos
Message 3 of 4
(2,341 Views)

You still haven't explained how you are running your program.

 

Is this a subVI that is part of a larger program?

 

As you have it programmed, you hit the run button and it executes exactly one time.  So how do you "keep running the program"?  (I'm really afraid you are going to say that you are using the Run Continuously button.)

 

What is the purpose of the "spreadsheet"?  Actually, it is not a spreadsheet, but a text file.  Are you trying to log data or are you just using it as a storage mechanism for data between runs of your program?

 

I understand your explanation about the degrees of rotation In vs. Out.  Have you turned on Highlight Execution to trace the flow of data through your application?  Perhaps that will show you why you aren't gettting the data you expect.  Your overall architecture is getting complicated.  You have have 3 layers of Case structures.  That is exponentially growing the various branches of your code execution.  Most of the cases are identical to others, or are just handling different comparisons.  If you are losing track of your current value between iterations, then you aren't using shift registers correctly.  Actually, I know that because the only case you have a shift register (your For Loops), you aren't event using the value coming in from the left hand node.  So you essentially just have a tunnel going out.

 

You should really look at a state machine architecture.  With that, you have each state in a different case of the case structure.  You make decisions on each iteration of the while loop as to what the next state to execute would be.

 

As for In Range and Coerce, I don't know if you need it or not.  It is useful if you have a situation where where a number would exceed a range such as 0-360 and you want to force it back to the limits of the range.

Message 4 of 4
(2,332 Views)