Example Programs

Showing results for 
Search instead for 
Did you mean: 

Controlling a Stepper Motor Drive for Constant Velocity with a DAQ Device


This example was written to control a stepper motor drive using the digital output lines of a general purpose DAQ device. The example can be used to control any stepper motor drive which uses step/direction control signals with a DAQ card that can output at least three compatible digital signals, including a hardware-timed pulse train.


This example sets up three digital output tasks using the DAQmx API. One digital line is used to enable the stepper motor drive, while the other two select the direction and generate the required step pulse.



  • LabVIEW 2011 or compatible
  • NI-DAQmx 9.3.5 or compatible


  • Compatible DAQ Device (minimum three suitable digital outputs)
  • Compatible Stepper Motor Drive (using Step/Dir inputs)

Note: Please consult your hardware's specifications or manufacturer to be sure that your DAQ device's digital output lines operate within the voltage and current range specified by your motor drive. It is possible to damage your equipment if used incorrectly.

Steps to Implement or Execute Code

First, select which digital output lines you will be using to generate the required control signals. You must select the line you are using for each signal in the appropriate front panel control. You must also verify the steps/revolution setting of your stepper motor drive and confirm that the 'Step Pulse Train Frequency' control is set accordingly to achieve your desired velocity. This VI will control a stepper drive for constant velocity. For example, if your stepper motor drive is set to use 200 steps/revolution, a setting of 200 in the 'Step Pulse Train Frequency' will correspond to 1 revolution/second or 60 RPM.

After selecting which digital lines are being used for which signals and confirming the desired steps/revolution setting, verify all connections to the stepper drive and run the VI. Clicking the 'Enable Drive' Boolean will enable the stepper motor axis, and toggling the 'Clockwise/Counterclockwise' Boolean will select the direction of motion.

This example does not include support for feedback or velocity profile smoothing. These more advanced features will require additional programming or the use of a dedicated motion controller.

Again, please be careful and consult your device manufacturer if necessary before attempting to use this code.

**This document has been updated to meet the current required format for the NI Code Exchange.**

Member mohk

i am new and using smiulated daqmx.

which driver r u using??

Member example_scrub

NI DAQmx is the correct driver to use.  Simulated devices don't actually write data to anything, and input data is purely simulated.

Member Adi_adarsh

Which driver we should use when we are controlling stepper motor with a DAQ?

Member Sammid

I was using this code to run my stepper motor. I could control the direction of the motor few days ago. But now it is running only in anticlockwise direction. Can anyone please let me know the reason?

Member curious_frog

I realize this is a very old post but I was hoping someone could explain the top channel of the code section by section.


I want to modify the code so that I can alternate between movement and rest. It seems like I should be able to do this by adding a for loop around some segment of the code that allows for finite rather than continuous steps at the stop but I can't seem to get this to work.


Eventually I am trying to take a series of measurements at set intervals within a 3d space but am trying to start with the simplest version of the problem I can think off. I am using the NI USB-6343 with a TB6600 driver and am able to get the given code to work.


I am new so I have very little existing knowledge but I am trying to learn, thanks!