Notifications
Clear all

Stepperonline motor

1 Posts
1 Users
0 Likes
1,084 Views
 Jimw
(@jimw)
Member
Joined: 4 years ago
Posts: 1
Topic starter  

Hello All. I got this nema 34 stepper motor. It works pretty nice, But I'm having two issues I can't figure out. When I enable it, there is a delay of about a second before it actually starts. I know it's not the enable signal because I piggybacked some LED's onto the inputs and it is immediate. The 2nd issue is that when I start and or stop it, the limits change by about an 1/8 of a revolution. I originally had it controlled by a VB pgm from a laptop, but have since changed to one of those Nextion HMI's. I've included my sketch and a link to a video of it in operation. I've also ordered to programming cable for tuning the drive, but coming from china who knows when it'll arrive. On a final note. My main buck converter burned up and when it did it sent 60 VDC to the Arduino and the 2nd buck converter, but the 2nd one burned closed, not open so it looks like my Nextion is still good. SO, I have new Buck converters ordered and should be here next week. If anyone has an Idea about the delay or the set points changing, I would be happy to try them. Thanks.

 

www.bolca.net/misc/

#include<Serial.h>

//Declare pin functions on Redboard
#define stp 2
#define dir 3
#define EN 6

 

//Declare variables for functions
char input;
//bool zero=false;
bool onetime=false;
//int target=3000;
int ontime =16099;// range NEMA34, 16099 to 1.6
int offtime =2.5;
int posSP =200;
int negSP =-200;
int current =0;
bool rotation= true;
bool enabled=false;
bool oscillate=false;

void setup() {
// put your setup code here, to run once:
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
pinMode(EN, OUTPUT);

// resetEDPins(); //Set step, direction, microstep and enable pins to default states
Serial.begin(9600); //Open Serial connection for debugging

digitalWrite(dir, HIGH); //Pull direction pin "High, Positive,CW"
digitalWrite(EN, HIGH); //Enable
}

// Main Loop*************************************************************************************************************************************************************************************************************************************************************

void loop()
{
static unsigned long lasttime = 0;
const long interval = 10;
unsigned long now = millis();
//if ((now - lasttime > interval)&&(enabled==true)) }

while(Serial.available()){

if(onetime==false)
{
(onetime=true);}

input = Serial.read(); //Read user input and trigger appropriate function

// characters used ......................0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D ,L ,U , Z

if (input =='0')
{digitalWrite(EN,HIGH);//high = disabled
(enabled =(false));
}

if(input =='1')
{digitalWrite(EN,LOW);//low = enabled
(enabled =(true));
}
if (input =='2')
{digitalWrite(dir,HIGH);// positive
(rotation=(true));
}

if(input =='3')
{digitalWrite(dir,LOW);// negative
(rotation=(false));
}

// Fast speed decrease
if((input =='4')&&(ontime<15777))//NEMA= 15777
{ontime= int(ontime+(ontime*.25));

}

// Fast speed increase
if((input =='5')&&(ontime > 10))
{ontime= int(ontime -(ontime/5));

}
//Maintained speed decrease
if((input =='8')&&(ontime<15777))//NEMA= 15777
{ontime= int(ontime+(ontime*.25));

}

//Maintained speed increase

if((input =='9')&&(ontime > 10))
{ontime= int(ontime -(ontime/5));
}

if(input =='A')//VB jog button mouse down
{digitalWrite(EN,LOW);//}//low = enabled
(enabled=true);
}

if (input =='B')// VB jog button mouse up
{digitalWrite(EN,HIGH);//}//high = disabled
(enabled=false);
}

if (input =='C')// over ride positive set point limit
{posSP=(100000000);
}

if (input =='D')// over ride negative set point limit
{negSP=(-100000000);
}

if (input =='Z')// set zero at current position
{(current=(0));
}

if (input =='U')// set upper limit at current position
{posSP=(current);
}

if (input =='L')// set lower limit at current position
{negSP=(current);
}

if (input =='O')//Oscillate
if (oscillate==false)
{(oscillate=true);
}
else if (oscillate==true)
{(oscillate=false);
(enabled=false);
}
//PLUS 100
if((input =='6')&&(ontime<16998))//NEMA= 16998
{ontime= (ontime +100);
}

//MINUS 100
if((input =='7')&(ontime > 199))
{ontime= (ontime -100);
}

}// FINAL BRACE

 

//run motor**************************************************************************************************************************************************************************************************************************************************
if ((oscillate==true)&&(negSP==current))
{ rotation=(true);
digitalWrite(dir,HIGH);}
else if ((oscillate==true)&&(posSP==current))
{rotation=(false);
digitalWrite(dir,LOW);}

{digitalWrite(stp,HIGH); //Trigger one step forward
delayMicroseconds(ontime);

}

if ((current==posSP)&&(rotation==true))
{digitalWrite(EN,HIGH);//}//high = disabled
(enabled =(false));}
else if ((enabled==true)&&(rotation==true))
current=(current+1);

 

else if ((current==negSP)&&(rotation==false))
{digitalWrite(EN,HIGH);//}//high = disabled
(enabled =(false));}
if ((enabled==true)&&(rotation==false))
current=(current-1);

digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again

delayMicroseconds(offtime);

 

}

//*************************************************************************************************************************************************************************************************************************************************************


   
Quote