Discussion:
Acquiring data while using Analog Outputs
(too old to reply)
AAvedro
2008-06-23 12:40:08 UTC
Permalink
I'm trying to control a stepper motor by: 1) using Analog inputs switching between 5 (ON) and then 0 (OFF) Volts to move it and then 2) acquiring Voltage inputs right afterwards through my IOtech PersonalDaq3001. I've included a copy of the VI I am working on. I've spoken to an IOtech representative and he said that I have to use their READ SCAN sub-vi in a While loop that encases my entire program. The READ SCAN sub-vi should effectively acquire data all the time while the program is running. From there, I should have a For loop to toggle the motor 'X' number of times and pick off data points from the READ SCAN array in order to get the current Voltage value after each toggle.

Also, I'm trying to sample 100 points each time so I can get an average Voltage value instead of a single value and then storing that into an array which I want access to after the completion of the For loop.

 

When I run the VI now, the For loop actually runs X number of times before it re-enters the While loops. So for the 1st iteration, it runs once (gets data once and moves motor once). For the 2nd iteration, it runs twice (get data once, moves motor once, grabs the SAME data again, and moves the motor

again) before re-entering the While loop. I'm not sure why it grabs the same data and why it grabs it X number of times.

 

So in summary, I'm trying to have my program to toggle my motor (switching between 5 and 0 V), acquire an average voltage reading, and then store that value into an array. I want to toggle the motor X number of times and have a voltage value read after each toggle with each voltage value coming from the Read SCAN sub-vi. I've tried programming this but have been unsuccessful.
Wallace_F
2008-06-24 22:10:10 UTC
Permalink
Hi AAvedro,
There are probably several ways to program your application to do what you want it to do.  However, from your description, it is still somewhat unclear how you are trying to control the stepper motor and acquire the voltage inputs.  Perhaps, if you attach your VI to your next post it would make it easier to help you out.
Best wishes,
Wallace F.
AAvedro
2008-06-25 13:10:09 UTC
Permalink
Hi Wallace,
Thank you for your help. Please find my attached my VI to this reply. I have changed it since I posted my message. Right now, I have a While loop that is acquiring data repetitively. it is acquiring 100 samples at each iteration, getting the mean value, and then storing that into the 'Mean' array. My motor control loop is in a parallel For loop which executes 25 times by toggling the motor On/Off and then attempts to pick off the most current value from the 'Mean' array at that moment in time, and storing it in the 'Mean For Loop' array. Unfortunately, the values in the 'Mean For Loop' array do not seem to be updating correctly, ie values from indices 1-24 are all the same. I've started to look at the queue postings on the Forum so hopefully that will help me. In the mean time, could you offer some suggestions on how to get acquire data while also performing other functions at the same time? Thank you for your time!


Automated_Motor_Control_v3 _trial4.vi:
http://forums.ni.com/attachments/ni/250/41104/1/Automated_Motor_Control_v3 _trial4.vi
Wallace_F
2008-06-26 22:40:09 UTC
Permalink
Hello AAvedro,
I was able to look at your code, and I think I can explain why the values in the Mean for loop array don't update in a manner that is consistent with what you are anticipating.  The reason is because, since the for loop is outside of a while loop, it will run for only n iterations, and then it is finished.  Whatever values are in the mean array, as seen from the for loop will stop updating after the specified number of iterations. For this reason, I'm recommending that you take a look at the producer/consumer architecture as a possible solution to your problem.  There is a NI Developer Zone article that discusses the producer/consumer architecture.  This article is linked below.
<a href="http://zone.ni.com/devzone/cda/tut/p/id/3023" target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/3023</a>
Best wishes,
Wallace F.

Loading...