Hi
With this library the user can drive up to 5 stepper motors (not simultaneously)
The main method is
MotorRotate( MotorNumber as Byte , RotationsPerMinute as Word, NumberOfSteps , Optional MotorDirection as Byte = GCBClockwise , Optional MotorStepMode as Byte = GCBWaveDrive , Optional MotorType as Byte = GCBBipolarMotor )
Τhe possible directions of rotation are two
GCBClockwise or GCBRotateRight and
GCBAnticlockwise or GCBRotateLeft
The possible step modes are three
GCBWaveDrive Or FullStep One Phase
GCBFullStep Or FullStep Two Phases and
GCBHalfStep
The possible types of motors are two
GCBUnipolarMotor Drive with Transistor Array
GCBBipolarMotor Drive with L298 Motor Driver
The user should declare in main program the ports to use any motor (4 each). Even should indicate the steps per revolution having the motor.
Ιn addition the user can define up to 5 limit switches to terminate the movement of each motor when the corresponding switch get the value <1>.
' Stepper Motor routines for the GCBASIC compiler'Copyright(C)2016KatsaounisDimitris' This library is free software; you can redistribute it and/or'modifyitunderthetermsoftheGNULesserGeneralPublic' License as published by the Free Software Foundation; either'version2.1oftheLicense,or(atyouroption)anylaterversion.' This library is distributed in the hope that it will be useful,'butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU'LesserGeneralPublicLicenseformoredetails.' You should have received a copy of the GNU Lesser General Public'Licensealongwiththislibrary;ifnot,writetotheFreeSoftware' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA'''Thislibrarycanhandleupto5steppermotors.Theusershoulddeclareinmainprogram' the ports you use any motor (4 each). Even should indicate the steps per revolution having the motor'andthenumberofsteps.'''Startup routine#startup InitMotor'Definepinsfor5Motors#defineGCBStepper1Pin1Stepper1Pin1#defineGCBStepper1Pin2Stepper1Pin2#defineGCBStepper1Pin3Stepper1Pin3#defineGCBStepper1Pin4Stepper1Pin4#defineGCBStepper2Pin1Stepper2Pin1#defineGCBStepper2Pin2Stepper2Pin2#defineGCBStepper2Pin3Stepper2Pin3#defineGCBStepper2Pin4Stepper2Pin4#defineGCBStepper3Pin1Stepper3Pin1#defineGCBStepper3Pin2Stepper3Pin2#defineGCBStepper3Pin3Stepper3Pin3#defineGCBStepper3Pin4Stepper3Pin4#defineGCBStepper4Pin1Stepper4Pin1#defineGCBStepper4Pin2Stepper4Pin2#defineGCBStepper4Pin3Stepper4Pin3#defineGCBStepper4Pin4Stepper4Pin4#defineGCBStepper5Pin1Stepper5Pin1#defineGCBStepper5Pin2Stepper5Pin2#defineGCBStepper5Pin3Stepper5Pin3#defineGCBStepper5Pin4Stepper5Pin4'Define types of motors#define GCBUnipolarMotor 1 'DrivewithTransistorArray#defineGCBBipolarMotor2'Drive with L298 Motor Driver#define GCBDCMotor 3 'DrivewithL298MotorDriver'Define Directions#define GCBClockwise 1#define GCBAnticlockwise 2#define GCBRotateRight 1#define GCBRotateLeft 2'Definestepmodes#defineGCBWaveDrive1'Or FullStep One Phase#define GCBFullStep 2 'OrFullStepTwoPhases#defineGCBHalfStep3'Other Defines#define GCBMotorInfinity 1#define GCBSwitch1 Switch1Pin#define GCBSwitch2 Switch2Pin#define GCBSwitch3 Switch3Pin#define GCBSwitch4 Switch4Pin#define GCBSwitch5 Switch5Pin#define GCBStopSwitch StopSwitchPin'DimGlobalVariablesDimRotationsPerMinute,RotationsPerSecond,StepsPerSecondasWordDimStepsPerRevolutionasByteDimStepsCount,NumberOfStepsasLongSubInitMotorDirGCBStepper1Pin1OutDirGCBStepper1Pin2OutDirGCBStepper1Pin3OutDirGCBStepper1Pin4OutSetGCBStepper1Pin1offSetGCBStepper1Pin2offSetGCBStepper1Pin3offSetGCBStepper1Pin4off#ifdefStepper2Pin1DirGCBStepper2Pin1OutDirGCBStepper2Pin2OutDirGCBStepper2Pin3OutDirGCBStepper2Pin4OutSetGCBStepper2Pin1offSetGCBStepper2Pin2offSetGCBStepper2Pin3offSetGCBStepper2Pin4off#endif#ifdefStepper3Pin1DirGCBStepper3Pin1OutDirGCBStepper3Pin2OutDirGCBStepper3Pin3OutDirGCBStepper3Pin4OutSetGCBStepper3Pin1offSetGCBStepper3Pin2offSetGCBStepper3Pin3offSetGCBStepper3Pin4off#endif#ifdefStepper4Pin1DirGCBStepper4Pin1OutDirGCBStepper4Pin2OutDirGCBStepper4Pin3OutDirGCBStepper4Pin4OutSetGCBStepper4Pin1offSetGCBStepper4Pin2offSetGCBStepper4Pin3offSetGCBStepper4Pin4off#endif#ifdefStepper5Pin1DirGCBStepper5Pin1OutDirGCBStepper5Pin2OutDirGCBStepper5Pin3OutDirGCBStepper5Pin4OutSetGCBStepper5Pin1offSetGCBStepper5Pin2offSetGCBStepper5Pin3offSetGCBStepper5Pin4off#endif#ifdefSwitch1PinDirGCBSwitch1In#endif#ifdefSwitch2PinDirGCBSwitch2In#endif#ifdefSwitch3PinDirGCBSwitch3In#endif#ifdefSwitch4PinDirGCBSwitch4In#endif#ifdefSwitch5PinDirGCBSwitch5In#endif#ifdefStopSwitchPinDirGCBStopSwitchIn#endifEndSubSubMotorRotate(MotorNumberasByte,RotationsPerMinuteasWord,NumberOfSteps,OptionalMotorDirectionasByte=GCBClockwise,OptionalMotorStepModeasByte=GCBWaveDrive,OptionalMotorTypeasByte=GCBBipolarMotor)'Dim StepsCount as Long Dim StepsDirection as Integer MotorTimeDelay=MotorSetSpeed (RotationsPerMinute) If MotorType=GCBBipolarMotor Then if MotorStepMode=GCBFullStep Then If MotorDirection=GCBClockwise Then SetMotorPin MotorNumber , 1 , 4, 1 , 1 Goto PinRelease else SetMotorPin MotorNumber , 4 , 1, -1 , 4 Goto PinRelease End if End if if MotorStepMode=GCBWaveDrive Then If MotorDirection=GCBClockwise Then SetMotorPin MotorNumber , 5 , 8 , 1 , 5 Goto PinRelease else SetMotorPin MotorNumber , 8 , 5 , -1 , 8 Goto PinRelease End if End if if MotorStepMode=GCBHalfStep Then MotorTimeDelay=MotorTimeDelay/2 If MotorDirection=GCBClockwise Then SetMotorPin MotorNumber , 9 , 16 , 1 , 9 Goto PinRelease else SetMotorPin MotorNumber , 16 , 9 ,-1 , 16 Goto PinRelease End if End if End if If MotorType=GCBUnipolarMotor Then NumberOfSteps +=1 if MotorStepMode=GCBFullStep Then If MotorDirection=GCBClockwise Then SetMotorPin MotorNumber , 17 , 20 , 1 , 17 Goto PinRelease else SetMotorPin MotorNumber , 20 , 17 , -1 , 20 Goto PinRelease End if End if if MotorStepMode=GCBWaveDrive Then If MotorDirection=GCBClockwise Then SetMotorPin MotorNumber , 21 , 24 , 1 , 21 Goto PinRelease else SetMotorPin MotorNumber , 24 , 21 , -1 , 24 Goto PinRelease End if End if if MotorStepMode=GCBHalfStep Then MotorTimeDelay=MotorTimeDelay/2 If MotorDirection=GCBClockwise Then SetMotorPin MotorNumber , 25 , 32 , 1 , 25 Goto PinRelease Else SetMotorPin MotorNumber , 32 , 25 , -1 , 32 End if End if End ifPinRelease: Select Case MotorNumber Case 1 GCBStepper1Pin1 = 0 GCBStepper1Pin2 = 0 GCBStepper1Pin3 = 0 GCBStepper1Pin4 = 0 Case 2 #ifdef Stepper2Pin1 GCBStepper2Pin1 = 0 GCBStepper2Pin2 = 0 GCBStepper2Pin3 = 0 GCBStepper2Pin4 = 0 #endif Case 3 #ifdef Stepper3Pin1 GCBStepper3Pin1 = 0 GCBStepper3Pin2 = 0 GCBStepper3Pin3 = 0 GCBStepper3Pin4 = 0 #endif Case 4 #ifdef Stepper4Pin1 GCBStepper4Pin1 = 0 GCBStepper4Pin2 = 0 GCBStepper4Pin3 = 0 GCBStepper4Pin4 = 0 #endif Case 5 #ifdef Stepper5Pin1 GCBStepper5Pin1 = 0 GCBStepper5Pin2 = 0 GCBStepper5Pin3 = 0 GCBStepper5Pin4 = 0 #endif End SelectEnd SubSub SetMotorPin (MotorNumber as Byte , TableBegin as Byte , TableEnd as Byte , StepsDirection as Integer , TablePosition as Byte) StepsCount=0 Do until StepsCount = NumberOfSteps ReadTable PinSet , TablePosition , MotorPinValue Select Case MotorNumber Case 1 GCBStepper1Pin1 = MotorPinValue.0 GCBStepper1Pin2 = MotorPinValue.1 GCBStepper1Pin3 = MotorPinValue.2 GCBStepper1Pin4 = MotorPinValue.3 Case 2 #ifdef Stepper2Pin1 GCBStepper2Pin1 = MotorPinValue.0 GCBStepper2Pin2 = MotorPinValue.1 GCBStepper2Pin3 = MotorPinValue.2 GCBStepper2Pin4 = MotorPinValue.3 #endif Case 3 #ifdef Stepper3Pin1 GCBStepper3Pin1 = MotorPinValue.0 GCBStepper3Pin2 = MotorPinValue.1 GCBStepper3Pin3 = MotorPinValue.2 GCBStepper3Pin4 = MotorPinValue.3 #endif Case 4 #ifdef Stepper4Pin1 GCBStepper4Pin1 = MotorPinValue.0 GCBStepper4Pin2 = MotorPinValue.1 GCBStepper4Pin3 = MotorPinValue.2 GCBStepper4Pin4 = MotorPinValue.3 #endif Case 5 #ifdef Stepper5Pin1 GCBStepper5Pin1 = MotorPinValue.0 GCBStepper5Pin2 = MotorPinValue.1 GCBStepper5Pin3 = MotorPinValue.2 GCBStepper5Pin4 = MotorPinValue.3 #endif End Select Wait MotorTimeDelay ms TablePosition=TablePosition + StepsDirection if StepsDirection>0 then if TablePosition=TableEnd + 1 then TablePosition=TableBegin end if Else if TablePosition=TableEnd - 1 then TablePosition=TableBegin end if End if 'SwichestoEndRotation#ifdefGCBSwitch1IfGCBSwitch1=1thenExitSub#endif#ifdefGCBSwitch2IfGCBSwitch2=1thenExitSub#endif#ifdefGCBSwitch3IfGCBSwitch3=1thenExitSub#endif#ifdefGCBSwitch4IfGCBSwitch4=1thenExitSub#endif#ifdefGCBSwitch5IfGCBSwitch5=1thenExitSub#endif#ifdefGCBStopSwitchIfGCBStopSwitch=1thenExitSub#endifStepsCount+=1Loop'NextEnd SubFunction MotorSetSpeed (RotationsPerMinute) as Word 'InmillisecondsRotationsPerSecond=[Word]RotationsPerMinute/60ifSysCalcTempX>=5thenRotationsPerSecond++StepsPerSecond=[Word]RotationsPerSecond*StepsPerRevolutionMotorSetSpeed=[Word]1000/StepsPerSecondEndFunctionTablePinSet5'0b00000101 '1BipolarFullStep6'0b00000110 10 '0b000010109'0b00001001 '41'0b00000001 '5BipolarWaveDrive4'0b00000100 2 '0b000000108'0b00001000 '81'0b00000001 '9BipolarHalfStep5'0b00000101 4 '0b000001006'0b00000110 2 '0b0000001010'0b00001010 8 '0b000010009'0b00001001 '163'0b00000011 '17UnipolarFullStep6'0b00000110 12 '0b000011009'0b00001001 '201'0b00000001 '21UnipolarWaveDrive2'0b00000010 4 '0b000001008'0b00001000 '241'0b00000001 '25UnipolarHalfStep3'0b00000011 2 '0b000000106'0b00000110 4 '0b0000010012'0b00001100 8 '0b000010009'0b00001001 '32EndTable
Odd. try tomorrow.
I will also ping Dimi to see if he can repost. This has to be the only time when I did not absorb into the release as I always feared this - loss of code and good insights. :-(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sent directly by Dimitris Katsaounis today - hot off the press. http://gcbasic.sourceforge.net/newfiles/Stepper.zip I will leave here for a day or two then I will move into the main build. Too risky leaving them in the forum.
Say thanks to Dimitris.
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
With this library the user can drive up to 5 stepper motors (not simultaneously)
The main method is
MotorRotate( MotorNumber as Byte , RotationsPerMinute as Word, NumberOfSteps , Optional MotorDirection as Byte = GCBClockwise , Optional MotorStepMode as Byte = GCBWaveDrive , Optional MotorType as Byte = GCBBipolarMotor )
Τhe possible directions of rotation are two
GCBClockwise or GCBRotateRight and
GCBAnticlockwise or GCBRotateLeft
The possible step modes are three
GCBWaveDrive Or FullStep One Phase
GCBFullStep Or FullStep Two Phases and
GCBHalfStep
The possible types of motors are two
GCBUnipolarMotor Drive with Transistor Array
GCBBipolarMotor Drive with L298 Motor Driver
The user should declare in main program the ports to use any motor (4 each). Even should indicate the steps per revolution having the motor.
Ιn addition the user can define up to 5 limit switches to terminate the movement of each motor when the corresponding switch get the value <1>.
The test program i use
My 27 Euros CNC works with Stepper.h library
https://www.youtube.com/watch?v=ww4p01LJBG0
The Library
The test program
Last edit: Dimitris Katsaounis 2016-07-22
The cnc program
Last edit: Dimitris Katsaounis 2016-07-22
Excelent.
Very good. Really good work.
Wow !!!
Can not download the two .gcb files.
ERROR 404
Last edit: jackjames 2017-02-12
Odd. try tomorrow.
I will also ping Dimi to see if he can repost. This has to be the only time when I did not absorb into the release as I always feared this - loss of code and good insights. :-(
OK. Thanks.
Sent directly by Dimitris Katsaounis today - hot off the press. http://gcbasic.sourceforge.net/newfiles/Stepper.zip I will leave here for a day or two then I will move into the main build. Too risky leaving them in the forum.
Say thanks to Dimitris.
:-)