Here are some examples of programs for the Hyperdrive stepper motor controller. Additional examples and a discussion of getting started along with a description of the SPL language are provided in the Hyperdrive User Manual, and the reader should refer to this for the finer points. However, extensive use of comments in these examples should help in understanding what is happening.
Because program editing is often performed within a text editor such as Notepad++ and then the program subsequently downloaded to the Hyperdrive for testing/use, each example begins with the PG command to switch the Hyperdrive from Command mode to Programming mode. The concluding EN command switches back to Command mode so that when the download concludes it can be immediately tested.
This simple example has two loops (remember loops cannot be nested). The code within the first loop rotates the motor clockwise through one revolution five times, with a half second pause between each rotation. The second loop rotates the motor anticlockwise through ten quarter turns, now with one second pauses. The program then terminates, automaticaly switching the Hyperdrive back to Command mode.
110 ; Multiple loops. 130 dr cw ; clockwise 140 ad 500 ; 500 Rpm/Sec^2 accel time 150 sm 3 ; step mode 3 160 ms 250 ; 250 rpm 170 lp 5 ; loop 5 times 180 st 1600 ; 1 revolution 190 wt ; wait until stopped 200 dl 500 ; 500 mSec delay 210 el ; redo loop 220 230 dr ccw ; counterclockwise 240 sm 4 ; step mode 4 250 lp 10 ; loop 10 times 260 st 800 ; 1 quarter turn 270 wt ; wait until stopped 280 dl 1000 ; 1 Sec delay 290 el ; redo loop 300 en
If we assume the motor has a 1.8° basic step, then the step mode instruction sm 3 on line 5 will move the motor 1.8 / 8 = 0.225° for each step. The st 1600 instruction in the first loop will therefore rotate the motor through 0.225 * 1600 = 360° or one revolution. The wt wait instruction will pause the program until the previous step instruction has completed, and the dl 500 delay instruction will pause the program for 500 mSecs.
Prior to the second loop, the sm 4 switches the motor stepping mode back to the default divide by 16 mode, where our 1.8° motor will move 0.1125° for each step. Thus the st 800 step instruction will move the motor 0.1125 * 800 = 90° during each pass through the loop for a total of 900° or two and a half revolutions.
The motor has rotated 5 revolutions clockwise and 2.5 revolutions anticlockwise, making a total of 2.5 revolutions clockwise when the program ends.
The Hyperdrive has three input lines and one output line for external control. A comprehensive set of instructions are available for motor control with these lines. This next example shows how the state of the IO-1 line can be used to select alternate paths through a program.
; Using the IJ instruction to alter program flow. 100 lp ; loop forever 110 ij 1,h,140 ; jump if IO-1 is high (5V) 120 ms 100 ; set speed 100 RPM 130 gt 150 140 ms 20 ; set speed to 20 RPM 150 st 2000 ; do the steps 160 wt 170 dl 5000 ; wait 5 secs 180 el 190 en
If the IO-1 line is in the high state (connected to +5V) then the motor will perform the 2000 steps at 20 RPM. If in the low state (connected to SGND) they are performed at 100 RPM. Note that the IO-1 through IO-3 terminals can be controlled from DC voltages higher than the internally provided +5V. External resistors can be used to set the necessary input conditions and this is discussed in detail in the User Manual.
Many applications are not concerned that a specific number of steps are required for the motor, only that the motor accelerate to and maintain a specific speed as it drives the machine between two positions that are defined externally by various types of position sensors. In the simplest case these could be two limit switches. This next example shows a motor being started by a sensor on IO-2 pulsing low as it detects an item. It accelerates to 300 RPM at a 1000 Rpm/Sec^2 rate and continues at this speed until a sensor on IO-1 also pulses low. It then decelerates to a stop at the same rate and pauses for 40 milliseconds before returning to the loop start and once again waiting for the IO-2 sensor.
; A sensor on IO-2 starts the motor by going low. ; A sensor on IO-1 stops the motor by going low. ; A LED on IO-4 indicates motor running 100 md speed ; use speed mode 110 pw 3 ; power mode 3 120 dm 3 ; decay mode 3 130 sm 2 ; step mode 2 140 io 4, H ; turn off LED 150 ad 1000 ; 1000 Rpm/Sec^2 160 lp ; forever 170 ic 2, L ; wait for IO2 low (start) 180 ia 1, L, 240 ; arm a jump on IO1 going low (stop) 190 io 4, L ; turn on LED 200 ms 300 ; start running at 300 rpm ; The motor is now running. 210 dl 1000 ; only run for this time 220 gt 280 ; should never get here 240 dc ; decel 250 io 4, H ; turn off LED 260 dl 40 ; 40 mSec wait 270 el ; loop 280 dc ; emergency stop 290 en
When encountered, the ic instruction at line 170 means the program will not continue until IO line 2 is at the specified level. The start switch changing state allows the program to continue. The ia 1, L, 240 instruction at line 180 arms the Hyperdrive to continuously monitor IO line 1 for a low going signal and jump to line 240 if that should occur. An LED is connected to the IO-4 output line and the io 4,L instruction at line 190 will turn it on, indicating the motor is running.
The ms 300 instruction accelerates the motor to 300 RPM and the program then pauses for 1 second at line 210. In this application the usual cycle time is typically about 600 milliseconds, so the sensor on IO-1 will normally go low long before the delay times out. However, should the sensor fail, the next instruction jumps out of the loop to line 280 which stops the motor and the program exists. So the motor stopped and the LED on means the sensor failed.
When IO-1 does goes low the program immediately jumps to line 240, stopping the motor. The LED is turned off at line 250 and after a short delay the program returns to waiting on IO-2 at line 170.
The last example shows the program for a specific machine. The comments at the start describe the machine function and how the IO terminals are used. The program is initially saved to the Hyperdrive non-volatile storage with the SV instruction, and the controller is configured to automatically load and run that program when power is applied with the AR instruction.
Note how the machine can be reset from an unknown position (ie after a power failure) by detecting that the emergency stop switch is held down while power is applied. This starts a sub program that carefully seeks out the EXTENDED limit switch and, once that position is known, proceeds to the now known start position. Note also how this Hyperdrive can start and stop the "cross motor" at a known position of the plunger via its output line IO-4.
; PLUNGER MOTOR PROGRAM ; This program manages a screw-jack driven plunger. There is ; a START button, an EMERGENCY STOP button, and an EXTENDED ; limit switch. ; ; The 3 push-buttons are SPDT and connected to IO-1, IO-2 and IO-3. ; In each case the normally closed contacts connect the IO ; terminal to the 5V+ terminal, and when the button is pressed ; they are connected to the SGND terminal. ; ; The switch connected to IO-1 is the START button. ; The switch connected to IO-2 is the EMERGENCY_STOP button. ; The switch connected to IO-3 is the EXTENDED limit switch. This ; changes state at and beyond the extended position. ; ; When the plunger reaches the extended position it waits for ; 5 seconds and then retracts. ; ; Pressing the EMERGENCY STOP button will immediately retract ; the plunger. ; ; The output IO-4 is connected to another Hyperdrive which ; activates another motor (here called the "cross motor") ; once this plunger motor has moved a specified number ; number of steps from retracted. ; ; The machine configuration is such that the retracted ; position is a specified number of steps from the extended ; position, and this is the only position which is a known ; (via the EXTENDED limit switch). ; ; Should power be lost the Hyperdrive will not know where ; the retracted position is. However it can find the extended ; position and from there the retracted position is known. ; Holding the START button down and applying power starts a ; subprogram that locates the extended position and from ; there the initial retracted position. ; 100 sm 2 ; stepping mode 2 110 ad 500 ; set the accel/decel rate 120 io 4,h ; ensure cross motor stopped 130 ij 1,h,330 ; jump over the re-positioning code if ; the start button high (not pressed) ;---------------------------------------------------------- ; Reset sequence - first find the extended switch... ; 140 ms 100 ; nice and slow 150 ij 3,l,210 ; jump if plunger is past extend limit 160 dr ccw ; extend 170 im 3,l,260 ; jump when limit goes low 180 st 50000 190 wt 200 gt 250 ; limit did not occur 210 dr cw ; retract 220 im 3,h,260 ; jump when limit goes high 230 st 50000 240 wt 250 gt 250 ; something wrong - loop forever ; We have reached the extended limit switch position ; coming from either direction. The retracted position ; is exactly 42000 steps from here. ; 260 hl ; immediate halt 270 dl 100 280 dr cw ; retract 290 ms 200 300 st 42000 ; travel to retract position 310 wt 320 gt 330 ;---------------------------------------------------------- ; Start 330 pw 4 ; plunger power setting 340 ms 750 ; set the RPM 350 ic 3,h ; limit switch must be closed 360 lp ; loop forever 370 io 4,h ; ensure cross motor stopped 380 ic 1,l ; wait for start button 390 ic 2,h ; must be no emergency button 400 dl 100 410 dr ccw ; extending 420 im 2,l,540 ; arm emergency retract 430 im 3,l,470 ; arm up limit switch 440 io 4,l,24000 ; start the cross motor after this many steps 450 st 50000 ; start up 460 wt ; limit switch gets us here 470 ic 3,l ; clear the jump to here 480 dc ; start the decel 490 wt ; wait till it completes 500 dl 5000 ; time to remain at the top 510 ic 2,h ; ensure emergency switch still high 520 io 4,h,15000 ; stop the cross motor after this many steps 530 gt 590 ; Shutdown 540 hl ; immediate stop 550 wt 560 dl 100 570 ic 2,l ; clear the jump to here 580 io 4,h ; ensure cross motor is stopped 590 bt 100 ; go back to retract 600 wt 610 dl 1000 ; delay before a re-start 620 el 630 en
For information or help with any aspects of these example programs or those bundled on the distribution CD, please email firstname.lastname@example.org.