Go Down

Topic: Stepper motor coding problem (Read 71 times) previous topic - next topic

KarrNut

I'm trying to control an idle-air-control valve using "MsTimer.h" and having a serious problem. When I run the stepper sequence I can move the stepper in and out a specified number of steps and it works great. However, when I want to control the pace of the closing steps using the timer, the stepper does move nearly far enough to close the valve.

Code: [Select]
/*setup for using an arduino motor controller
 * this program works as advertised
 */
int inA1 = 12; // ch a
int inA2 = 13; // ch b
int inB1 = 9; // dis a
int inB2 = 8; // dis b
int dTime = 10;
int nSteps;
int startSteps = 15;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(inA1, OUTPUT);     
  pinMode(inA2, OUTPUT);     
  pinMode(inB1, OUTPUT);     
  pinMode(inB2, OUTPUT);
   
  nSteps = 0; //counter for number of steps
  //opens an IAC valve
  Serial.println("Moving in");
  while(nSteps < startSteps) {  //moves plunger in
    StepOne();
    StepFour();
    StepThree();
    StepTwo();
    nSteps ++;
  }
  StepStop();
  Serial.println(nSteps);
  nSteps = 0;
   delay(1000);
  //closes IAC valve using same number of steps
  Serial.println("Moving out");
  while(nSteps < startSteps) {  //moves plunger out
    StepOne();
    StepTwo();
    StepThree();
    StepFour();
    nSteps ++;
  }
  StepStop();
  Serial.println(nSteps);
}


void loop() {
  // put your main code here, to run repeatedly:
}

void StepOne() {
//arduino motor shield stepper code!!!!!

Robin2

You need to post the program that illustrates the problem - and the complete program.

There is no reference to any timer in the code in your Original Post.

These links may help
Stepper Motor Basics
Simple Stepper Code

also look up the AccelStepper library

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

PaulS

Code: [Select]
* this program works as advertised
But that isn't the code you are asking questions about. So, why would you post that code?
The art of getting good answers lies in asking good questions.

Go Up