2

I am having issues with interfacing my stepper motor, connected to a control board being this one

Due to some reason I am not able to move it, unless I remove the enable signal. I can change the direction either unless I manually change by either plug it or unplug it. If codewise change the state of the dir_pin,would the motor keep spinning in the same direction.

The control board need has a timing diagram, specifying when the en, and dir signal should be enabled.

Timing diagram of the controlboard

the code I am using to interface it is as below:

stepper_motor.cpp:

#include "stepper_motor.h"

stepper_motor::stepper_motor()
{
  pinMode(BUILTIN_LED,OUTPUT);
  pinMode(step_pin,OUTPUT);
  pinMode(dir_pin,OUTPUT);
  pinMode(en_pin,OUTPUT);

  alive_bool = true;
  position_bool = false;
  step_count = 0;
}


void stepper_motor::alive()
{
  if(alive_bool == true)
  {
    digitalWrite(BUILTIN_LED,HIGH); 
    alive_bool = false;
    delay(2000);
  }
  else if(alive_bool == false)
  {
    digitalWrite(BUILTIN_LED,LOW);
    alive_bool = true;
    delay(2000);
  }    
}

void stepper_motor::step_pwm()
{

    digitalWrite(en_pin,HIGH);

    delay(0.005);

    digitalWrite(dir_pin,LOW);

    delay(0.005);

    while(1)
    {
      digitalWrite(step_pin,LOW);
      delay(1);
      digitalWrite(step_pin,HIGH);
      delay(1);
    }

}

stepper_motor.h

/* Class: stepper_motor
 * Info: contains the setup, and primary interface to control
 * the stepper motor
 *  
 * stepper_motor(): constructor -  setup the connection to the control board
 * void step_pwm():  Moves the tilt - uses the bool to determine the direction. 
 * bool alive_bool: Is either high (1) or low (0), used for the alive void. 
 */

#ifndef stepper_motor_h
#define stepper_motor_h

#include "Arduino.h"
#include "pins_arduino.h"

#define step_pin  D1
#define dir_pin   D2
#define en_pin    D3
#define max_step  200

 class stepper_motor
{
  public:
    stepper_motor();
    void alive();
    void step_pwm();
  private:
    bool alive_bool;
    bool position_bool;
    int step_count;
};

#endif

main:

#include "stepper_motor.h"

stepper_motor motor;
int state = 0;
void setup() {
  // put your setup code here, to run once:
}

void loop() {

      motor.step_pwm(); 
}

The motor moves, so the step signal seem to be correct. But enable and dir seem to incorrect, or are pretty sure that they are.

So what is wrong with those signal? do they not follow the required timing?

3
  • 1
    Check this statement "delay(0.005);" Commented Sep 25, 2016 at 11:38
  • See forum.arduino.cc/index.php?topic=317628.0 Commented Sep 25, 2016 at 11:40
  • delay() works but not delayMicroseconds().. delay works due to the code overhead is around 12 ms Commented Sep 25, 2016 at 12:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.