Stepper dengan driver TB6600 Microstep Driver
Dependents: StepperTB_Example Lowlevel_function
Diff: StepperTB.cpp
- Revision:
- 2:787cee5a8dad
- Parent:
- 1:6cbbb5795b9c
--- a/StepperTB.cpp Thu Nov 01 15:00:05 2018 +0000 +++ b/StepperTB.cpp Fri Nov 09 17:30:00 2018 +0000 @@ -17,29 +17,48 @@ } //Method + +void StepperTB::MoveOneStep(bool Direction, int Interval){ + int Msteps = getMstep(); + + //Gerak sebanyak Mstep Microstep = 1 Step + if(Direction == 0){ + //Arah 0 (Belum dicoba CW/CCW) + for(int i=0; i<Msteps; i++){ + DIR_=0; + ENA_=1; + PUL_=1; + wait_us(Interval); + PUL_=0; + wait_us(Interval); + } + } + else { + //Arah 1 + for(int i=0; i>Msteps; i--){ + DIR_=1; + ENA_=1; + PUL_=1; + wait_us(Interval); + PUL_=0; + wait_us(Interval); + } + } + } + void StepperTB::MoveStep(int StepAmt, int Interval){ - //Konversi StepAmt ke microstep - int MstepAmt = getMstep()*StepAmt; //Gerak sebanyak MstepAmt microstep if(StepAmt>=0){ - for(int i=0; i<MstepAmt; i++){ - DIR_=0; - ENA_=1; - PUL_=1; - wait_us(Interval); - PUL_=0; - wait_us(Interval); + //Arah 0 (Belum dicoba CW/CCW) + for(int i=0; i<StepAmt; i++){ + MoveOneStep(0, Interval); } } else { - for(int i=0; i>MstepAmt; i--){ - DIR_=1; - ENA_=1; - PUL_=1; - wait_us(Interval); - PUL_=0; - wait_us(Interval); + //Arah 1 + for(int i=0; i>StepAmt; i--){ + MoveOneStep(1, Interval); } } }