08-10-2017 02:46 PM
I am programming a stepper motor and would like to accelerate it from a frequency of 200 Hz up to 1000 Hz using about 6 steps, hold it at 1000 Hz for a desired input amount of steps, then decelerate it back to 200 Hz in using 6 steps, similarly to the acceleration. My VI works when connected to the myDAQ and stepper motor, however the frequency outputted to the motor during the first few steps (acceleration) and last few steps (deceleration) seems lower than it should be qualitatively. I believe that the way I have coded this VI is inefficient and thus causing the software to take longer to run my code, resulting in a delay in the output to the hardware, specifically in my for loops that control the acceleration and deceleration. Any insight on how to clean up or rewrite this portion of my code to avoid this delay would be much appreciated. My VI is attached below. Thanks in advance!
Solved! Go to Solution.
08-10-2017 03:04 PM
I don't have LV2017 installed so I can't have a look at your vi but what you're observing is most probably a physical phenomena than a software issue. A stepper can't change speed instantly, how fast it can accelerate/decelerate is related to the inductance and resistance of the windings, the ability of your power source to deliver energy rapidly to the motor and other factors (load inertia, resonance, ...)
Did you used a scope to measure these variations?
Ben64
08-10-2017 03:31 PM
You are correct. That code is inefficient.
Create your task once. Write to your Task in a loop. Stop your task once. Clear your task.
Ramp Pattern.vi is a friend you need to make.
08-11-2017 08:01 AM
Just a forewarning: your myDAQ device is very likely inadequate for the task of outputting a variably frequency with a very specific # of pulses. The newish X-series boards were the first to support buffered pulse train output, a feature you'd need to provide both variable frequency and precise control over total # steps. The myDAQ doesn't support this.
Before X-series were around, I used hardware-timed DO as a tedious method to accomplish the same thing, but the myDAQ doesn't support that either. You'll probably need a different DAQ board or, better yet, a dedicated stepper controller.
-Kevin P
08-14-2017 01:19 PM
Hi, thanks for your help. The reason I have my task starting and clearing so many times was because I was having errors about the output counter channel being "reserved." Is there a way to avoid this and use only one task while changing the command I'm giving that one channel?
08-15-2017 12:57 PM
Dear kbauman,
I'm not entirely certain that this is what you are looking for, but it may help to take a look at these examples and documents.
Change Counter Output Frequency on the Fly
Generate a Continuous Digital Pulse Train With On The Fly Frequency Control
Counter Output PWM with Dynamic Duty Cycle Updates in DAQmx
Pulse Width Modulation (PWM) Using NI-DAQmx and LabVIEW
Hope this helps!
Alyssa H.
National Instruments