Control stepper motor by specific signal

I' am trying to control Nema17 stepper motor : https://www.pololu.com/product/2267 by using specific signal like: h=(h0*sin-1(-S*sin(w*t)))/sin-1(-S) with h0 is a default angle and S between -1 and 0 i know how i can include this equation in arduino but the problem is how to control the stepper by this equation

Post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. And please use the code button </> when posting code
codeButton.png

What stepper motor driver are you using?

...R
Stepper Motor Basics
Simple Stepper Code

OK this is my code

const int stepPin = 2;
const int dirPin = 5;
const float K=0.1;
float c=1;
float w;
float U=5;
float O;//O Default angle 
float S;
unsigned long time;
float t;
const float Pi = 3.14159;
float f;//frequency
void setup() {
   Serial.begin(9600); 
  // Sets the two pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
 

}

void loop() {
t= millis();
 
  w=(K*U)/c;
  if(-1<=S<0){
  h=((O*asin(-S*sin(w*t)))/asin(-S));
  
  }
  if(S==0){
  h=O*sin(w*t);

  
  if(S>0){
  h=((O*tanh(-S*sin(w*t)))/tanh(-S));
  
  }
  
  
}
}

my actuel problem is how i can make my motor follow the result of h.
this not correct to do something like:

  digitalWrite(dirPin, HIGH); // Enables the motor to move in a particular direction
 
  for (int x = 0; x < h; x++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  
  
  }
  
  digitalWrite(dirPin, LOW); //Changes the rotations direction
    for (int x = 0; x < (h*2); x++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
   delayMicroseconds(500);
  }

I need to make my motor signal Rectangular function if -1<=S<0 and sinusoidal function if S=0
I mean that i have control my angle and my speed until be the same of h (O angle and w=2PIfrequency)

If you indent your code consistently it makes it much easier to see the inter-relationships

float c=1;
float w;
float U=5;
float O;//O Default angle 
float S;
unsigned long time;
float t;
const float Pi = 3.14159;
float f;//frequency

void setup() {
    Serial.begin(9600); 
    // Sets the two pins as Outputs
    pinMode(stepPin, OUTPUT);
    pinMode(dirPin, OUTPUT);
}

void loop() {
    t= millis();
 
    w=(K*U)/c;
    
    if(-1<=S<0){
        h=((O*asin(-S*sin(w*t)))/asin(-S));
    }
    
    if(S==0){
        h=O*sin(w*t);
        if(S>0){
            h=((O*tanh(-S*sin(w*t)))/tanh(-S));
        }
    }
}

You will see, for example, that if (S > 0) can never be true because you already tested for S == 0

And please DO NOT use single character variable names as they make debugging very difficult. Try finding all the instances of the variable S :slight_smile:

Use meaningful variable names.

There is no stepper code in that example so I can’t envisage what the problem is. And as the variable names mean nothing to me I can’t even guess. Sorry.

…R

np dude :confused: i know that i can’t explain to you my problem exactly by writing but thanks for ur reply :slight_smile: