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.
Stepp.cpp
00001 #include "Stepp.h" 00002 00003 Stepp::Stepp(PinName clk, PinName dir, PinName en) : _clk(clk), _dir(dir), _en(en) { 00004 _clk = 0, _dir = 0, _en = 0; 00005 00006 debug = new Debug(); 00007 this->speed = 50; 00008 this->acell = true; 00009 //PinName pinOrigin; 00010 } 00011 00012 int Stepp::step(int n_steps, bool direction) { 00013 00014 int accelspeed; 00015 if(this->acell) accelspeed = START_STOP_SPEED; 00016 else accelspeed = this->speed; 00017 00018 _en = 0; // habilita move 00019 _dir = direction; 00020 00021 for(int i=0; (i< n_steps && EixoMonitoring::stopAll == false); i++){ 00022 00023 if(this->acell){//linear acceleration 00024 if(i < START_STOP_SPEED) if (--accelspeed == this->speed) accelspeed ++; 00025 if(i > (n_steps-START_STOP_SPEED)) if(++accelspeed == START_STOP_SPEED) accelspeed--; 00026 } 00027 00028 _clk = 1; 00029 wait_us(1); 00030 _clk = 0; 00031 wait_us(1); 00032 wait_us(accelspeed); 00033 } 00034 _en = 1; 00035 00036 return 1; 00037 } 00038 00039 bool Stepp::findLimits(int n_steps, bool direction, DigitalIn sensor) { 00040 00041 int accelspeed = 0; 00042 if(this->acell) accelspeed = START_STOP_SPEED; 00043 else accelspeed = this->speed; 00044 00045 int i = 0; 00046 _en = 0; // habilita move 00047 _dir = direction; 00048 00049 while(sensor.read() == 0 && EixoMonitoring::stopAll == false){ // n chegou na origem 00050 00051 if(this->acell){ //linear acceleration 00052 if(i < START_STOP_SPEED) if (--accelspeed == this->speed) accelspeed ++; 00053 if(i > (n_steps-START_STOP_SPEED)) if(++accelspeed == START_STOP_SPEED) accelspeed--; 00054 } 00055 00056 _clk = 1; 00057 wait_us(1); 00058 _clk = 0; 00059 wait_us(1); 00060 wait_us(accelspeed); 00061 00062 i++; 00063 } 00064 _en = 1; 00065 00066 00067 if(sensor.read() == 0){ 00068 return 0; 00069 } 00070 else{ 00071 return 1; 00072 } 00073 } 00074 00075 00076 float Stepp::version(void) { // version() returns the version number of the library 00077 return VERSION; 00078 }
Generated on Sun Jul 24 2022 20:01:40 by
1.7.2