Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Writing my own code for driving a stepper motor. Understanding some syntax

werto165
 Share

I want to be able to drive a bipolar stepper with a l2393d 

image.thumb.png.a64bd23a3d2193f0874e02d7cfe3a916.png

I also want to use the stepper library build into the arduino IDE(I think) 

 

However I don't want the function to be blocking so I want to be able to interface with the arduino whilst steps are occuring. I was just looking into the stepper.cpp files and I am a little confused with the follow syntax: 

 

void Stepper::setSpeed(long whatSpeed)
{
  this->step_delay = 60L * 1000L * 1000L / this->number_of_steps / whatSpeed;
}

 

to drive the stepper motor there needs to be a certain stepper delay (as far as I know) so I was just wondering if someone could explain the this-> syntax to me as I am not familiar with it. 

 

  if (this->pin_count == 4) {
    switch (thisStep) {
      case 0:  // 1010
        digitalWrite(motor_pin_1, HIGH);
        digitalWrite(motor_pin_2, LOW);
        digitalWrite(motor_pin_3, HIGH);
        digitalWrite(motor_pin_4, LOW);
      break;
      case 1:  // 0110
        digitalWrite(motor_pin_1, LOW);
        digitalWrite(motor_pin_2, HIGH);
        digitalWrite(motor_pin_3, HIGH);
        digitalWrite(motor_pin_4, LOW);
      break;
      case 2:  //0101
        digitalWrite(motor_pin_1, LOW);
        digitalWrite(motor_pin_2, HIGH);
        digitalWrite(motor_pin_3, LOW);
        digitalWrite(motor_pin_4, HIGH);
      break;
      case 3:  //1001
        digitalWrite(motor_pin_1, HIGH);
        digitalWrite(motor_pin_2, LOW);
        digitalWrite(motor_pin_3, LOW);
        digitalWrite(motor_pin_4, HIGH);
      break;
    }
  }

 

this is the sequence to make the stepper motor "step" 

 

so I what also I'd like to know if you do a delay say every 20ms would that produce a similar control?

 

in the header file it references this too: 

 

 unsigned long step_delay; // delay between steps, in ms, based on speed

 

Thanks 

 

 

CPU: Intel 3570 GPUs: Nvidia GTX 660Ti Case: Fractal design Define R4  Storage: 1TB WD Caviar Black & 240GB Hyper X 3k SSD Sound: Custom One Pros Keyboard: Ducky Shine 4 Mouse: Logitech G500

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, werto165 said:

I was just wondering if someone could explain the this-> syntax

C++ supports object oriented programming (OOP). In OOP one can define custom datatypes, called classes. A class groups data (member variables) and functions that perform operations on said data (member functions / methods) together. "this" is a pointer that points to the class instance for which the function was called. 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

I am not 100% what you are going for, but I have a "Tone" library someone wrote and open sourced for generating frequencies and is non-blocking. I had to make some corrections to the library and added support for the mega 2560, but that portion of the library is now proprietary with my company and I cannot share the corrections I made, however I think I might be able to dig up the library files from the net, or I can look on my work computer, come Monday morning. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×