Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: StepperTB_Example Lowlevel_function
StepperTB.cpp
00001 #include "mbed.h" 00002 #include "StepperTB.h" 00003 00004 //Parameterized CTOR 00005 StepperTB::StepperTB(PinName ENA, PinName DIR, PinName PUL, int Microstep, int StepPerRev): 00006 ENA_(ENA), DIR_(DIR), PUL_(PUL), Microstep_(Microstep), StepPerRev_(StepPerRev) { 00007 //Inisiasi saja 00008 } 00009 00010 //GETTER 00011 int StepperTB::getSPR(){ 00012 return StepPerRev_; 00013 } 00014 00015 int StepperTB::getMstep(){ 00016 return Microstep_; 00017 } 00018 00019 //Method 00020 00021 void StepperTB::MoveOneStep(bool Direction, int Interval){ 00022 int Msteps = getMstep(); 00023 00024 //Gerak sebanyak Mstep Microstep = 1 Step 00025 if(Direction == 0){ 00026 //Arah 0 (Belum dicoba CW/CCW) 00027 for(int i=0; i<Msteps; i++){ 00028 DIR_=0; 00029 ENA_=1; 00030 PUL_=1; 00031 wait_us(Interval); 00032 PUL_=0; 00033 wait_us(Interval); 00034 } 00035 } 00036 else { 00037 //Arah 1 00038 for(int i=0; i>Msteps; i--){ 00039 DIR_=1; 00040 ENA_=1; 00041 PUL_=1; 00042 wait_us(Interval); 00043 PUL_=0; 00044 wait_us(Interval); 00045 } 00046 } 00047 } 00048 00049 void StepperTB::MoveStep(int StepAmt, int Interval){ 00050 00051 //Gerak sebanyak MstepAmt microstep 00052 if(StepAmt>=0){ 00053 //Arah 0 (Belum dicoba CW/CCW) 00054 for(int i=0; i<StepAmt; i++){ 00055 MoveOneStep(0, Interval); 00056 } 00057 } 00058 else { 00059 //Arah 1 00060 for(int i=0; i>StepAmt; i--){ 00061 MoveOneStep(1, Interval); 00062 } 00063 } 00064 } 00065 00066 00067 void StepperTB::MoveRev(int RevAmt, int Interval){ 00068 //Konversi RevAmt ke step 00069 int StepAmt = RevAmt*getSPR(); 00070 00071 //Gerak sebanyak MstepAmt microstep 00072 MoveStep(StepAmt, Interval); 00073 }
Generated on Sun Jul 17 2022 10:47:56 by
