Example Code

Creating a Stepper Motor Driver Simulation Using a 7-Segment LED

Code and Documents

Attachment

The Challenge: The directional control of a stepper motor can sometimes be difficult to visualize. How does one know whether the motor is rotating clockwise or counterclockwise by just looking at the motor itself?

The Solution: Using LabView software and Mathscript to write logical statements to control the directions of illumination of the 7-segment LED to mimic a stepper motor that rotates in equal steps under the influence of electromagnets to complete one revolution.

We are controlling each of the six segments on the LED that has been used as a numerical display to light up in a particular direction and speed. The individual cathodes were connected to the digital output pins of National Instruments’ USB-6009, which also provides digital outputs generated from LabView logical statements. This sequential pattern of LED illumination resembles the stepper motor whose rotation is controlled by a series of electromagnets that are positioned in a circular path, and thus helps visualize the direction of rotation of a stepper motor before a real implementation.

No Buffer Circuit Needed

NI’s USB-6009 DAQ provided a digital voltage output of 5V to the Vcc pin of the 7-segment LED (M72/K312B) that was connected a 3.3 KΩ resistor to limit the input current within a compatible range. We tried connecting a TTL buffer circuit to the Vcc pin but found that the output voltage was too low to emit the light from the LED. After switching to a 3.3 KΩ resistor, the input voltage for the LED was measured to be 1.7 V, and the measured current was 1.53 mA.

Software

The Mathscript was used to write the logical statements through a shift register. Determination of the direction of LED had been accomplished by judging whether the previous segment was on. If yes, the current segment would be turned on before the previous one was turned off. The scripts for the clockwise and counter-clockwise directions were simply a reverse of each other. The speed of rotation was controlled by ‘wait until next millisecond multiple’.

Conclusion

We agreed that the Mathscript function in LabView made this simulation very user-friendly and thought-engaging for novices to learn how to implement logical statements for controlling an external object that consisted of multiple parts working together. Moreover, the Mathscript also offered a resilient way to make changes in the logical statements to allow the VI to be used with other types of stepper motors that may have a different number of electromagnets and configurations. However, we also noticed that a command rt_wait(ms) was not compatible in this environment.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors