Pages: [1]   Go Down
Author Topic: speed up stepper motor  (Read 163 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello I am struggling to make my two stepper motor speed up.
it has to run 3600 RPM.
here is my code two run two stepper motor with two push button.
it seems only run up to .setSpeed(200);
any advise would be really helpful




Code:
#include <Stepper.h>

#define motorSteps 200     // change this depending on the number of steps
// per revolution of your motor
#define motorPin1 6
#define motorPin2 5
#define motorPin3 8
#define motorPin4 9

int switchPin = 2;              // switch is connected to pin 2
int switchPin2 = 3;


int led1Pin = 13;
int lightMode = 0;

int currentSwitch1State;
int beforeSwitch1State;


int stepper_curState = 0;
int stepper_bfState = 0;
int stepper_idx = 0;


bool isArrive = false;
enum
{
STEPPER_STATE_STOP = 0,
STEPPER_STATE_RUN,
STEPPER_STATE_BACK,
};


Stepper myStepper(motorSteps, motorPin1,motorPin2);
Stepper myStepper2(motorSteps, motorPin3,motorPin4);



void setup()
{
myStepper.setSpeed(200);
myStepper2.setSpeed(200);
pinMode(switchPin, INPUT);    // Set the switch pin as input

pinMode(led1Pin, OUTPUT);

Serial.begin(9600);                // Set up serial communication at 9600bps

stepper_idx = 0;
stepper_bfState = STEPPER_STATE_STOP;
stepper_curState = STEPPER_STATE_STOP;
}

void switchPinHigh()
{
if(currentSwitch1State == HIGH)
return;
beforeSwitch1State = currentSwitch1State;
currentSwitch1State = HIGH;
}
void switchPinLow()
{
if(currentSwitch1State == LOW)
return;
beforeSwitch1State = currentSwitch1State;
currentSwitch1State = LOW;

if( beforeSwitch1State != currentSwitch1State )
{
if( stepper_idx == 0)
{
stepper_bfState = stepper_curState;
stepper_curState = STEPPER_STATE_RUN;
}
else if ( stepper_idx > 0 && ( (stepper_curState == STEPPER_STATE_RUN) || (stepper_curState == STEPPER_STATE_BACK) ))
{
stepper_bfState = stepper_curState;
stepper_curState = STEPPER_STATE_STOP;
}
else if( stepper_idx > 0 &&  stepper_curState == STEPPER_STATE_STOP)
{
if(isArrive == true && (stepper_bfState == STEPPER_STATE_BACK || stepper_bfState == STEPPER_STATE_RUN))
{
stepper_bfState = stepper_curState;
stepper_curState = STEPPER_STATE_RUN;
}
else
{
stepper_bfState = stepper_curState;
stepper_curState = STEPPER_STATE_BACK;
}
}
}
}

void loop(){

if(digitalRead(switchPin) == HIGH || digitalRead(switchPin2) == HIGH)
{
switchPinHigh();
}
else if(digitalRead(switchPin) == LOW || digitalRead(switchPin2) == LOW)
{
switchPinLow();
}


if(stepper_curState == STEPPER_STATE_RUN && stepper_idx < 10000)
{
stepper_idx ++;
myStepper.step(1);
myStepper2.step(1);
}
else if(stepper_curState == STEPPER_STATE_BACK && stepper_idx > 0 )
{
stepper_idx --;
myStepper.step(-1);
myStepper2.step(-1);
}
else if(stepper_curState == STEPPER_STATE_STOP || stepper_idx == 10000 || stepper_idx == 0 )
{

if(stepper_idx == 10000)
isArrive = true;
else if(stepper_idx == 0)
isArrive = false;
stepper_curState = STEPPER_STATE_STOP;
}
}
Logged

Pages: [1]   Go Up
Jump to: