#include "stepper_motor.h"
int max_step = 200;
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::step_pwm()
{
if(position_bool==true)
{
//Dir pin low
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,LOW);
delay(0.005);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,HIGH);
delay(0.005);
int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,HIGH);
delay(1);
digitalWrite(step_pin,LOW);
delay(1);
}
//digitalWrite(en_pin,LOW);
//position_bool = false;
}
else
{
//Dir pin high
delay(1000);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,LOW);
delay(0.005);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,HIGH);
delay(0.005);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,HIGH);
int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,HIGH);
delay(1);
digitalWrite(step_pin,LOW);
delay(1);
}
//digitalWrite(en_pin,LOW);
//position_bool = true;
}
}
if(position_bool==true)
{
//Dir pin low
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,LOW);
delay(0.005);
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,HIGH);
delay(0.005);
int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,LOW);
delay(0.0025);
digitalWrite(step_pin,HIGH);
delay(0.0025);
}
Well.. yeah i read through the datasheet. Step signal should be H--> Wait --> L --> Wait --> H..
int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,HIGH);
delay(1);
digitalWrite(step_pin,LOW);
delay(1);
}
//Dir pin low
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,LOW);
delay(0.005);
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,HIGH);
void stepper_motor::step_pwm()
{
//Start - En Low , DIR HIGH, STEP high
//init configuration!
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,HIGH); // Previous LOW
delay(0.005);
//T1- En HIGH , DIR HIGH, STEP HIGH
//Enable high
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,LOW);
delay(0.005);
//T2- En HIGH , DIR low, STEP HIGH
//Direction choosen
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,LOW);
delay(0.005);
//T2- En HIGH , DIR low, STEP HIGH
//STEP step between low and high with 2.5µs between
while(1)
{
digitalWrite(step_pin,LOW);
delay(2.5);
digitalWrite(step_pin,HIGH);
delay(2.5);
}
}
Something is very wrong with the enable pin..
I can move the system without the information from the enable pin.
void stepper_motor::step_pwm()
{
//Start - En Low , DIR HIGH, STEP high
//init configuration!
digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,LOW); // Previous LOW
delay(0.005);
//T1- En HIGH , DIR HIGH, STEP HIGH
//Enable high
//digitalWrite(step_pin, HIGH);
//digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,HIGH);
delay(0.005);
//T2- En HIGH , DIR low, STEP HIGH
//Direction choosen
//digitalWrite(step_pin, HIGH);
digitalWrite(dir_pin,LOW);
//digitalWrite(en_pin,HIGH);
delay(0.005);
//T2- En HIGH , DIR low, STEP HIGH
//STEP step between low and high with 2.5µs between
while(1)
{
digitalWrite(step_pin,LOW);
delay(2.5);
digitalWrite(step_pin,HIGH);
delay(2.5);
}
}
First set EN, than you have to wait at least 5us, then set DIR, then wait at least 5us, then clear STEP wait 2.5us, then set STEP wait 2.5us.
Where did I say this?I don't understand why the while loop doesn't follow the specification given in the code..
Yes it´s in your code...(I greyed it out now)The datasheet begins with: EN = 0, DIR = 1, STEP = 1.
Where is this in your code?
The datasheet says: pulling the EN to LOW (GND) will stop the motor current.The enable pin doesn't affect the motor.
Then most probably the controller dirves the pin LOW. (A voltmeter should show the voltage)And the direction can only be changed by pulling out the direction signal. The direction doesn't change, when i change its state in the code.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?