Stepper Motor Controller and Light Detection
This project was given to my team in our Engineering Experimentation class. The project, in a nutshell, was to control a stepper motor which had a “light detection circuit” mounted to it and as the stepper rotated through its sweep the program had to pickup on the angle that the light detection circuit found the light source (an LED).
Here is a screen shot of the program:
This was our entire program.
I’m working on posting our .vi file for download…
If you’d like to read our entire report, I have posted it below.
The objective of this project was to control a stepper motor by utilizing National Instruments’ LabVIEW development environment which we would use to program software to be able to detect a LED using a prebuilt light detection circuit, and return the angle that the light was detected (relative to our starting position).
Stepper motors can be used in a wide array of applications, from moving paper from the paper tray to the printing head on a printer, or in an intravenous pump to induce medicine into a patient’s body. LabVIEW is a graphical programming platform which allows the user to create simple or complex programs using a large block diagram. LabVIEW is used in many major engineering companies (such as the Federal Aviation Administration) and is an important tool to know how to use in order to be successful in the engineering field.
The equipment that was available for our use was the LabVIEW 8.6 program, a National Instruments’ ELVIS hardware development platform, and a prebuilt stepper motor driver and light detection circuit. We were given the information of what digital outputs we needed to control via LabVIEW in order to get the stepper motor to properly function.
The overall design of our Lab View circuit begins with the actual circuit located inside a for-loop which is located inside a while-loop. The while-loop has one main purpose, to allow the circuit to continually run through it’s 101 iterations (the number of iterations defined for the program to run inside the for-loop), as well as ultimately shut down the program with the user initializing the emergency stop button located on the front panel labeled Gremlin Ambush Emergency Stop. As mentioned above, the for-loop controls the circuit by cycling through 101 iterations which, when multiplied by 1.8, allows the stepper motor controlled by the circuit to rotate to an angle of 180 degrees as required by the project outline initially provided in the project objectives. The for-loop contains the entire circuit and not only controls the stepper motor, but also enables the light to turn on, and detects the angle at which the light is detected. In the paragraphs to come the control of the stepper motor, the light enablement, and the angle of detection will be discussed in further detail.
The first challenging task in this project tackled by the group is controlling the stepper motor. Although this task is not perceived as necessarily difficult, making the stepper motor turn 180 degrees in one direction and automatically return to the original position proved to be a more tedial and time consuming task. All was achieved with the implementation of three QUOTIENT-REMAINDER gates, two ADDITION gates, two SELECTOR gates, a NEGATE gate, an INCREMENT gate, a SUBTRACT gate, two FEEDBACK-NODES, and finally an S-R FLIP-FLOP that is made from two NOR gates and one of the previous mentioned FEEDBACK-NODES. To implement a value for the index in the first case structure (to be mentioned later) a constant of 4 is tied to two QUOTIENT-REMAINDER gates, both also attached to the loop count feature available with the for-loop, one result is attached to the true side of a SELECTOR and the other attatched to an INCREMENT feature, then subtracted from the constant 4, mentioned above, using a SUBTRACT gate. This value is attached to the false side of the SELECTOR. This circuit allows the index to be 0,1,2,3 for a true case and 3,2,1,0 for the false case providing the index that is needed for the first case structure. Case structure one is what ultimately turns the stepper motor. Inside case structure one, exists a DIGITAL WRITER, two INDEX ARRAYS, a NUMBER TO BOOLEAN converter, and several constants and LED’s (Light Emitting Diodes). This case structure will effectively turn the motor. By wiring the first INDEX ARRAY to constants 1, 2, 4, and 8 the program is able to send each element to a NUMBER TO BOOLEAN converter turning the base 10 numbers into binary. The equivalent binary numbers of 1, 2, 4, and 8 are 0001, 0010, 0100, 1000. The binary numbers are then put into another INDEX ARRAY. This second INDEX ARRAY outputs each of the binary numbers one at a time but outputs them by breaking them into their four components. For example, 0001 is output from the second INDEX ARRAY on four separate lines. The first line carries the first 0, the second line carries the second 0, the third line carries the third 0, and the fourth carries the 1. These individual outputs are sent to the DIGITAL WRITER in a sequential and continuous order so that the stepper motor can turn. One other minor element in this case structure is a BOOLEAN TRUE/FALSE and it turns on a series of LED’S on the front panel to show that the sequence being sent to the DIGITAL WRITER is working properly. This function was initially created as a troubleshooting apparatus, however, with it’s useful function in illustrating what is being sent to the stepper motor, and it’s attractive presence in the front panel, it was decided to allow the series of LED’s to remain as part of the final project. The True/False for this case structure is attached to the BOOLEAN TRUE/FALSE (Initialize) as well as the BOOLEAN TRUE/FALSE (Gremlin Ambush Emergency Stop) utilizing an OR gate. When this case structure is false the array of 0000 is sent to the DIGITAL WRITER clearing the stepper motor and allowing it to run again at a later time without errors from an improper shutdown. To make this process effective, a TIME DELAY feature had to be inserted into the program between the BOOLEAN TRUE/FALSE (Initialize) and the actual stop. Another important observation to note is that when the Initialize button is pressed to False, the shutdown will occur when the for-loop has completed it’s 101 iterations returning the stepper motor back to it’s original position, whereas the Emergency Stop button will immediately shutdown the program due to it’s positioning outside of the for-loop, inside of the while-loop.
Although the indexes derived from the process mentioned above with the SELECTOR turn the motor clockwise/counterclockwise, it was found that the circuit needed limits as well as an input to the SELECTOR to switch it from True to False or False to True. The logical patchwork used to fix the problem is outlined by using the constant 1.8 multiplied by 1 and placed into an ADD gate, then into a SELECTOR on the True side. This result was sent to the third QUOTIENT-REMAINDER gate with a dividing constant of 360. Sent to a FEEDBACK NODE the new result is then sent back to have the value of 1.8 added and sent through again providing a number sequence of (0,1.8,3.6…etc). This value from the FEEDBACK NODE is also sent to a Gauge located on the front panel to display the position of the stepper motor in degrees as well as sent to two COMPARATORS (one greater than or equal to the constant 4, the other less than or equal to the constant 180). If either of these conditions are read as false the signal will be sent to the S-R FLIP FLOP and the index sequence described above will switch and the logical patchwork on the False side of the SELECTOR will be effective, which consists of the constant 1.8 sent to a NEGATE feature, multiplied by 1 and sent to an ADD gate with the value from the FEEDBACK NODE. A WAVEFORM CHART was placed in the program for troubleshooting purposes to visually observe that the logic would work in a satisfactory manner.
The next component in the program was to utilize the Radar On/Off button to activate the light circuit board attached to the stepper motor. This was accomplished by attaching a BOOLEAN TRUE/FALSE switch (labeled Radar On/Off on the front panel) to the D04 slot on the DIGITAL WRITER located inside the first case structure. This set-up is connected using an AND gate to the DAQ ASSISTANT. However, it is important to note that the DAQ ASSISTANT is not directly connected to this AND gate, it is actually first connected to a GREATER THAN OR EQUAL TO gate that is also connected to a constant of two. By doing this when the DO4 BOOLEAN TRUE/FALSE (Radar On/Off) switch is on and the DAQ ASSISTANT output is greater than two, the AND gate will send a true to the BOOLEAN LED (labeled as Froto Found on the front panel) and the LED will initialize, turning the light on.
The third and final component to be discussed in the design of this project will be a combination of the Speed Delay of the stepper motor and the calculation to find the angle of detection. Changing the speed of the stepper motor is achieved by using a constant of 1000 and dividing it by a NUMERICAL CONTROL (Speed) and sending that value to a WAIT feature. The first element in this portion of the circuit is an INITIALIZE ARRAY feature located on the outside of the while loop, this INITIALIZE ARRAY is assigned values of 0 with an index of 3 making an array of 000. This array passes through a shift register located on the for loop and proceeds into case structure two. Until the second case structure reads true, the array mentioned above will simply run through the shift registers ultimately making a big loop. When the second case structure reads true, however, a second element enters the case structure from the GAUGE display mentioned earlier that actually shows the value of the angle the stepper motor has turned through on the front panel. These elements are connected using an ADD ARRAY feature with the output falling into an INDEX ARRAY located inside the case structure. It should be noted here, as mentioned above, that in order for the case structure to record values it has to be in its TRUE case which only happens when the light is found. The INDEX ARRAY that the two previous mentioned elements are connected to will now have an array that consists of the first angle reading that the GAUGE element picks up. This is then sent outside of case structure 2 and into the SHIFT REGISTER located on the other side of the for-loop and ultimately looped back. This process will continue until three values are in the INDEX ARRAY. These values are sent to a COMPOUND ADDER which sums the input vaules, and after being passed out, placed into a divider which divides the value by 4 (this takes the average of angles in which the light was detected). The result is sent to an NUMERICAL INDICATOR (Angle of Gremlin).
The LabVIEW program that the group wrote does fulfill the tasks and objectives as stated above. The program does control the movement of the stepper motor and can enable/disable the “radar” detection circuit. When the radar circuit is enabled the program will return the average angle of light detection to the user via the LabVIEW front panel GUI. Once the program is started it can continue without user interaction until the shut down sequence is initiated (which it will return back to its initial starting position). Our program also will release the stepper motor once the shut down sequence has been completed, keeping heat build up in the stepper motor to a minimum and conserving electricity.
Although our program does fulfill the objectives, while programming several issues arose that the group had to work around. One such issue was the ability to average the angle of light detection, as opposed to simply taking the first angle that the light was detected. Doing so would cause different angles to be sent back to the user for interpretation depending on the stepper motor rotation.
Setting the boundary conditions to control when the stepper motor stops and switches direction also caused quite a headache. The upper boundary for the condition circuit will work fine when set at 180o. The main concern was that when the lower boundary was set at 0O, the stepper motor would keep moving counter clockwise and not stop and switch direction. After a graph was inserted into the signal chain we discovered that the issue was the S-R Flip-flop circuit was not fast enough to switch the rotation direction before the stepper would rotate counterclockwise past 0o (which because of the way the gauge circuit works, would cause it to jump to 360o) causing the GREATER THAN OR EQUAL TO 180o condition to be met (which is why it would just keep rotating counter clockwise). To solve this problem, the lower boundary was set at 4o, which allowed the motor to make that condition true, and the S-R Flipflop to change and take effect before the stepper motor could go below 0o and reset to 360o.
The last major issue we ran into was when the shutdown sequence was activated the program was exiting before the software had time to write a code of 0000 out to the ELVIS (again a timing issue). To solve this problem we inserted a DELAY SIGNAL block which allowed just enough time for the boolean line running to the case structure to change state which would send out the 0000 to become active and take effect before the program would exit.