© KREMFORD PTY. LTD. Stepper Motors, Stepper Motor Controllers, Hyperdrive
Web Site by VP-IT
telephone
Telephone: 03 9017 0473
1st Floor, 175 Collins Street, Melbourne, Victoria 3000 Australia
telephone
Main Telephone
(03) 9017 0473
ABN 79 137 904 235

Kremford Products

Kremford Hyperdrive-3 Programmable

Stepper Motor Controller

Hyperdrive-3 Programming Examples

Below are some examples of programs for the Hyperdrive-3 stepper motor controller. Additional examples and a discussion of getting started along with a description of the SPL language are provided and described in the Hyperdrive-3 User Manual, and the reader should refer to this for help in understanding these examples. However, the extensive use of comments here should help in understanding what is happening. As 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 Program command to switch the Hyperdrive from Command mode to Programming mode. The concluding End command switches back to Command mode so that when the download concludes it can be immediately tested. A Loop Example This example has a single loop that is executed twice. It first sets the motor speed to 50 RPM with an acceleration time of 500 RPM/sec^2, and then starts the motor rotating clockwise for 3200 steps. Once this completes it pauses for half a second, changes the speed to 100 RPM, and starts the motor rotating anti- clockwise for 1600 steps. program ; switch to programming ; A program to demonstrate the program loop ; functionality and how to change direction. 090 StepMode 3 ; set 0.225 degree steps 100 Loop 2 ; execute the loop twice 110 SetRPM 50 ; set max speed at 50 rpm 120 Accel 500 ; set accel/decel time to 500 mSecs 130 Dir cw ; rotate clockwise 140 Step 3200 ; ..for 3200 steps 150 WaitFor ; wait until finished 160 Delay 500 ; pause for 500 mSecs 170 SetRPM 100 ; set max speed at 100 rpm ; Now change direction 180 Dir ccw ; rotate anticlockwise 190 Step 1600 ; ..for 1600 steps 200 WaitFor ; wait until finished 210 Delay 500 ; pause for 200 mSecs 220 ELoop ; end of loop 230 End If we assume the motor has a 1.8° basic step angle, then the step mode instruction StepMode 3 at line 90 will configure the motor to move 1.8 / 8 = 0.225° for each step. The first Step 3200 instruction will therefore rotate the motor through 0.225 * 3200 = 720° or two revolutions. The WaitFor instruction will pause the program until the two rotations have completed. When the motor stops, the Delay 500 delay instruction will pause the program for 500 mSecs before the next three instructions start the motor for 1600 steps in the opposite direction. Using Input Controls The Hyperdrive has four isolated input lines and two isolated output lines for interface to various external switches, sensors and controls. A comprehensive set of instructions are available for motor control with these lines. This next example shows how the state of the IN1 line can be used to select alternate paths through a program. Program ; Using the JumpIf instruction to alter program flow. 100 loop ; loop forever 110 JumpIf 1, on, 140 ; jump if IN1 is on 120 SetRPM 100 ; set speed 100 RPM 130 GoTo 150 140 SetRpm 20 ; set speed to 20 RPM 150 step 2000 ; do the steps 160 waitfor 170 delay 5000 ; wait 5 secs 180 eloop 190 end If the IN1 line is on, then the motor will perform the 2000 steps at 20 RPM. If off the move is performed at 100 RPM. Note that the IN1 through IN4 terminals are optically isolated and can be switched from DC voltages ranging from 5 to 24 volts. Note also that case does not matter in instructions. A Speed Example 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 IN2 switching on as it detects an item. It accelerates to 300 RPM at a 10,000 Rpm/Sec^2 rate and continues at this speed until a sensor on IN1 also switches on. 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 IN2 sensor. Program ; A sensor on IN2 switching on starts the motor. ; A sensor on IN1 switch on stops the motor. ; A LED on OUT1 indicates the motor is running 100 Mode speed ; use speed mode 110 Power 3 ; power mode 3 120 DcyMode 3 ; decay mode 3 130 StepMode 2 ; step mode 2 140 Out 1, off ; turn off LED 150 Accel 10000 ; 10,000 Rpm/Sec^2 160 Loop ; forever 170 ContWhen 2, on ; wait for IN2 on (start) 180 MonSkip 1, on, 240 ; arm a jump when IN1 on (stop) 190 Out 1, on ; turn on LED 200 SetRpm 300 ; start running at 300 rpm ; The motor is now running. 210 Delay 1000 ; only run for this time 220 GoTo 280 ; should never get here 240 DecelNow ; decel immediate 250 Out 1, off ; turn off LED 260 Delay 40 ; 40 mSec wait 270 ELoop ; loop 280 Halt ; emergency stop 290 End When encountered, the ContWhen instruction at line 170 means the program will not continue until the sensor connected to IN2 has turned on. This switch changing state allows the program to continue. The MonSkip 1, on, 240 instruction at line 180 arms the Hyperdrive to continuously monitor the IN1 line in the background for an ON signal and jump to line 240 if that should occur. An LED is connected to the IN1 output line and the Out 4, on instruction at line 190 will turn it on, indicating the motor is running. The SetRpm 300 instruction accelerates the motor to 300 RPM and the program then pauses for 1 second at line 210. For this machine the usual cycle time from limit switch to limit switch is typically about 600 milliseconds, so the sensor on IN1 will normally switch on long before the delay times out. However, should the sensor fail, the next GoTo instruction immediately jumps out of the loop to line 280 which stops the motor and the program concludes. So the motor stopped and the LED on means the sensor failed. In normal operation when IN1 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 IN2 at line 170. A Complete Example 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 Save command, and the controller is configured to automatically load and run that program when power is applied with the RunUp command. The machine is thus ready to run after being turned on. 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 OUT2. ;*************************************************************** ; MIXER TABLE PROGRAM ; ; This program manages a screw-jack driven table. For control ; there is a START button and up and down limit switches. ; ; The Start push-button is SPDT and connected to IN3. ; The Down limit switch is SPDT and connected to IN1. ; The Up limit switch is SPDT and connected to IN2. ; ; For detailed connections please refer to drawing KF083-1-22. ; ; After the START button is pressed the motor accelerates to ; 800 rpm and moves the table up for the set number of steps. ; At this point it decelerates to a stop and restarts at 200 rpm, ; at the same time starting the auger motor via IO4. When the ; table trips the up limit switch the motor stops for 15 secs ; before starting down at the same 200 rpm. ; ; After a set number of steps the auger motor is signalled to ; stop, the stepper comes to a halt, and then starts down again ; at 800 rpm until it activates the down limit switch. ; ; Should power be lost the Hyperdrive will not know if it is ; in the correct down position when power is re-applied. On ; power up it moves down a half turn of the screw. This assumes ; it is at the normal down position but ensures the switch is ; activated. If the low switch is not activated at this point ; it continues moving down until it is. At this point for both ; cases the table is below the low limit, so the motor starts ; up until the switch de-activates. To ensure the table position ; overtravel matches the normal, the motor runs up for a set ; time and then starts down at the nominal speed, coming to ; a stop at the normal position when the low limit activates. ; ; Notes: ; Clockwise is down. ; Ativated switches are low. ; ;*************************************************************** pg ; ; First must ensure we are at the down limit stop. 100 StepMode 2 ; step mode 2 (0.9 degree steps) 110 Power 2 ; power setting 2 120 Out 2, OFF ; wait until start button not pressed 130 SetRPM 400 ; set 400 rpm 140 Accel 3000 ; accel at 3000 rpm/sec2 150 Debounce 1, 10 ; 10 mSec debounce for all switches 160 Debounce 1, 10 170 Debounce 1, 10 ; ; Move down a small distance so if at down position, ; the switch is definitely activated. ; 180 Dir CW ; go down 190 Step 200 ; 200 steps (180 degs) 200 WaitFor ; run 210 Delay 500 ; half second delay ; ; Should now be below the low switch normal position. ; If not we continue moving down until it is. ; 220 JumpIf 1, OFF, 290 ; jump if low switch is activated 230 Monitor 1, L, 260 ; arm a jump for when switch activates 240 Step 250 WaitFor ; ; The low switch position has been reached. ; 260 DecelNow ; stop here 270 Waitfor 280 Delay 500 ; ; The low switch has been activated. Now move up until the ; switch de-activates. ; 290 Monitor 1, ON, 330 ; arm a jump for when switch de-activates 300 Dir CCW ; go up 310 Step ; start (should enter a max step here) 320 WaitFor ; run ; 330 DecelNow ; switch has de-activated 340 Delay 500 ; half second wait ; ; Next step is to move up far enough so that when the table ; is driven back down, its speed will match the machine ; normal down cycle. ; 350 Dir CCW ; go up 360 Step 2000 ; 2000 steps (5 turns) 370 WaitFor ; run 380 Delay 500 ; half second wait before continuing 390 SetRPM 800 ; set accel rate to match normal (3000 rpm/sec2) 400 Dir CW ; go down 410 Monitor 1, L, 440 ; arm a jump for when switch activates 420 Step ; start (should enter a max step here) 430 WaitFor ; run ; ; switch has activated (ie table in down position) ; 440 DecelNow ; decelerate to a stop 450 WaitFor ; wait until stopped 460 Delay 1000 ; one second delay 462 Power 4 463 DcyMode 4 ; ; The program now remains in the following loop forever. ; 470 Loop 480 Accel 1000 ; set accel rate to 1000 rpm/sec2 490 ContWhen 3, H ; wait until start button pressed ; 500 Dir CCW ; go up 510 StepMode 2 ; step mode 2 (0.9 degree steps) 520 SetRPM 800 ; set speed to 800 rpm 530 Step 12000 ; 30 rotations = max high speed travel 540 WaitFor ; run ; ; Table is now at the position from where we start the auger ; motor and resume the upward movement at a slower rate. ; 550 Out 2, ON ; start the auger motor 560 SetRPM 200 ; set speed at 200 rpm 570 Monitor 2, L, 600 ; arm a jump for when the up limit switch activates 572 Step 4000 574 WaitFor 576 Delay 100 578 SetRPM 60 580 Step ; start (should enter a max step here) 590 WaitFor ; run ; ; Up limit switch has activated. ; 600 DecelNow ; decelerate 610 WaitFor ; wait until done 620 Delay 15000 ; pause at top for 15 seconds ; 630 Dir CW ; go down 632 SetRPM 200 640 Step 2000 ; 2000 steps (5 rotations) 650 WaitFor ; run 660 Out 2, OFF ; turn off the auger motor 670 Accel 3000 ; set accel rate to 3000 rpm/sec2 680 StepMode 2 ; step mode 2 682 SetRPM 800 ; set speed to 800 rpm 690 Monitor 1, L, 720 ; arm a jump when the down limit switch activates 700 Step ; start (should enter a max step here) 710 WaitFor ; run ; ; Down limit switch has activated. ; 720 DecelNow ; decelerate 730 WaitFor ; wait until done 740 Delay 2000 ; 2 second wait before start switch is active 750 ELoop 760 End For information or help with any aspects of these example programs or those bundled on the distribution CD, please email
Kremford Pty Ltd - Custom Motor and Controller Application Design