LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does Labview VI pause intermittently during motor control while loop?

I'm performing some biomechanical testing using Labview to control stepper motor actuators. I have a PCI-7334 controller card and a MID-7604 driver. The testing is run in load control using a while loop that sends a number of steps to the stepper motor that is proportional to the difference between the actual and desired load. The VI intermittently pauses though and sits in active for several seconds (~5 sec to 20 sec). What could cause this problem?

 

Thank you in advance for your assistance.

0 Kudos
Message 1 of 5
(3,145 Views)

I don't think you provide enough information to troubleshoot. Does the VI actual pause or is it only failing to redraw the front panel often enough?

 

Can you show us some of the code?

0 Kudos
Message 2 of 5
(3,124 Views)

Thank you for your quick reply altenbach!

 

I apologize for not providing enough information. Let me clarify.

 

The VI does not actually pause, but the while loop in the code (see attached VI that I labeled the while loop: "THIS IS THE LOOP THAT PAUSES") should continually read in data from the load cell via PCI-6023E DAQ card and based on the difference between the current load and the desired load should send the stepper motor a command about how many steps to take. What happens sometimes is that the VI still says that it's running, but isn't doing anything. This doesn't appear to happen after a certain number of iterations, but rather randomly during the execution. After a few seconds the motor begins to move again and everything functions normally.

 

Thank you for your help. Please let me know if there's more information you'd like.

0 Kudos
Message 3 of 5
(3,108 Views)

Without the subVIs it is hard to see what is going on.

 

Some general comments:

1. Block diagrams should be limited to the size of one screen.  Yours is over 4 times as wide as my 27" screen.

2. Sequence structures should be avoided.  LabVIEW is a datflow language and only rarely are sequence structures required. There is almost certainly a way to write your program without them.

3. The use of local variables should be avoided.  Again, they have a place but most likely they are not needed in your program. They are prone to race conditions, make extra data copies, and force execution in the UI thread.

4. Floating point data types are not recommended as case selectors. They will be rounded and coerced to integers.

5. Learn about the Producer/Consumer Design Pattern and state machines.  

 

One possible cause of your slowdown is having the Write to Spreadsheet File.vi inside the while loop. This VI is convenient to use but it opens, writes, and closes the file each time it is called.  I have no way to tell how much data you write on each iteration but as the file grows the OS may need to re-allocate space for the file or fragment the file. These operations can be slow.

 

Do you really want to Abort the program in the False case?  This will leave any outputs in the last state they had been set. This could have your motor(s) running, clutch engaged, ...  In programs which control physical hardware an orderly shutdown procedure is usually better: set all outputs to a safe condition, close files, close DAQ tasks, and indicate the status to the user.  Calling Stop allows none of this to happen.

 

Lynn

Message 4 of 5
(3,099 Views)

Thank you for your comments Lynn. I know that this program can be written cleaner, and your comments certainly are helping me move forward.

0 Kudos
Message 5 of 5
(3,050 Views)