MATLAB Answers

Devon
0

How can I increase the speed of my stepper motor?

Asked by Devon
on 6 Jul 2016
Latest activity Answered by Devon
on 18 Jul 2016
I'm running Matlab 2015b (32-bit) on Windows 7 (32-bit) using Data Acquisition Toolbox. I have a National Instruments USB-6501 Digital I/O Device, and a unipolar stepper motor that receives 2 bits, one for creating the square waves and one for direction.
Currently, my motor moves too slowly and I do not know how to shorten the period of my square waves. Using an oscilloscope, the measured period of my square waves is 18ms. I need to lower this to ~2.5ms to move at the speed I require. My code looks like this: (Note that this is an indefinite while loop–in my finalized code I have already figured out how to exit the loop by reading inputs)
d = daq.getDevices;
s = daq.createSession('ni');
addDigitalChannel(s,'Dev1','port0/line0:1','OutputOnly');
signal1 = [1 0]; % First bit creates square wave, second controls direction
signal2 = [0 0]; % First bit creates square wave, second controls direction
door_switch = 0;
while door_switch == 0
outputSingleScan(s,signal1);
outputSingleScan(s,signal2);
end
There are no issues with the motor as I have tested it with an ePrime program and it generates the required square waves and motor speed (although with a PCI digital I/O device). I'm unsure if this is a problem with my code, a limitation of the NI USB-6501, or if there is a maximum "speed" that a while loop can execute at. If you have any suggestions or ideas, I would greatly appreciate it. Thanks in advance.

  0 Comments

Sign in to comment.

2 Answers

Answer by Devon
on 18 Jul 2016
 Accepted Answer

I received an answer from a Mathworks engineer, and I wanted to post it here for reference to others.
The NI-USB-6501 is software timed and only supports single scan operations, and outputSingleScan has too large of an execution time to send the signals at the rate I required. To bypass this, the engineer directed me to call the NI-DAQmx driver functions directly within MATLAB.

  0 Comments

Sign in to comment.


Answer by Vinod
on 12 Jul 2016

Rather than using outputSingleScan, can you queue up data and send the data using startForeground at a specific rate so the motor turns at the rate you need it to? See code snippet here .

  2 Comments

Hi Vinod,
When I try that I get an error that reads:
"queueOutputData is disabled because the session contains channels that do not support clocked operations."
I learned that the NI-USB-6501 is software timed and not hardware timed, so I have been unable to alter the rate as well. Inputting:
s.Rate = 10000 %(For Example)
returns the error: "Rate cannot exceed 0 in the current configuration."
Starting the session and adding my channels also generates the following:
"Warning: A channel that does not support clocked sampling was added to the session. Clocked operations using startForeground and startBackground will be disabled. Only on-demand operations using inputSingleScan and outputSingleScan can be done."
Thanks for responding!
Sounds like you are running into limitations of your DAQ hardware. You may need to try a board with clocked IO capability.

Sign in to comment.