Welcome! Log In Create A New Profile

Advanced

setup electronik

Posted by Anonymous User 
Anonymous User
setup electronik
August 23, 2009 06:47PM


1

[Note: User was banned for mean-spirited and inconsiderate behavior: Rudness, Foul Language.]

Edited 3 time(s). Last edit at 10/26/2009 12:24AM by SebastienBailard.
Re: Need help for control two stepper motors!
August 23, 2009 08:25PM
What is this a class project?

It should be possible, this type of control more and likely should be implemented off of timer interrupt.

But as a exercise you could do it this way.

1. Save the desired number of steps for each axis
2. Calculate the number of steps per second requried for each axis.
3. Calculate the time delay between steps dividing steps per second into 1000
4. Take the current time from the millis(); function and add in the time delay and save as a next time to step value.
5. in the loop function check if there are steps remaining if so grab the current time.
6. compare it against the next time to step value for the desired axis.
6a. If greater or equal then issued the required step pulse.
6b. Decrement the step count.
6c. add time delay between steps to the next time to step value.
Anonymous User
Re: Need help for control two stepper motors!
August 24, 2009 07:11AM
freds Wrote:
-------------------------------------------------------



Thanks for the answer!

Edited 2 time(s). Last edit at 08/26/2009 11:00AM by perpuna.
Anonymous User
Re: Need help for control two stepper motors!
August 24, 2009 12:10PM
Thanks for the answer!

Edited 1 time(s). Last edit at 08/26/2009 11:00AM by perpuna.
Anonymous User
Re: Need help for control two stepper motors!
August 25, 2009 06:58PM
#define s1_stepPin 53
#define s1_dirPin 51
#define s1_enablePin 49


#define s2_stepPin 47
#define s2_dirPin 45
#define s2_enablePin 43


void setup()
{
Serial.begin(9600);


pinMode(s1_stepPin, OUTPUT);
pinMode(s1_dirPin, OUTPUT);
pinMode(s1_enablePin, OUTPUT);
pinMode(s2_stepPin, OUTPUT);
pinMode(s2_dirPin, OUTPUT);
pinMode(s2_enablePin, OUTPUT);

digitalWrite(s1_dirPin, HIGH);
// digitalWrite(s1_stepPin, LOW);
digitalWrite(s1_enablePin, LOW);
digitalWrite(s2_dirPin, HIGH);
//digitalWrite(s2_stepPin, LOW);
digitalWrite(s2_enablePin, LOW);

}

void loop()
{

long t_end=1000000L;
int s1_steps=10000;
int s2_steps=20000;

int t1 = t_end/s1_steps; //Delay between steps of the first motor
int t2 = t_end/s2_steps; //Delay between steps of the second motor

int c1 = 0; //The counter of idle time of the first motor
int c2 = 0; //The counter of idle time of the second motor
long t_total = 0; //Time from the operation beginning

while (t_total++ < t_end) {
if (++c1 == t1) {
digitalWrite(s1_stepPin, HIGH);
c1 = 0;
}
if (++c2 == t2) {
digitalWrite(s2_stepPin, HIGH);
c2 = 0;
}
delayMicroseconds(1);
digitalWrite(s1_stepPin, LOW);
digitalWrite(s2_stepPin, LOW);
delayMicroseconds(100);
}
digitalWrite(s1_enablePin, HIGH);
digitalWrite(s2_enablePin, HIGH);
}

Edited 4 time(s). Last edit at 08/26/2009 10:24AM by perpuna.
Re: Need help for control two stepper motors!
August 26, 2009 05:40AM
It doesn't work because your loop only has delays when a motors steps.

This should work because it always delays 2us round the loop. It might be a bit inaccurate depending how long digitalWrite() takes. Making the second delay bigger would make it more regular but have less speed resolution.

void loop() 
{ 

	int t_end=1000000; 
	int s1_steps=10000; 
	int s2_steps=20000; 

	int t1 = t_end/s1_steps; //Delay between steps of the first motor 
	int t2 = t_end/s2_steps; //Delay between steps of the second motor 

	int c1 = 0; //The counter of idle time of the first motor 
	int c2 = 0; //The counter of idle time of the first motor 
	long t_total = 0; //Time from the operation beginning 

	while (t_total++ < t_end) { 
		if (++c1 == t1) { 
			digitalWrite(s1_stepPin, HIGH); 
			c1 = 0;
		}
		if (++c2 == t2) {
			digitalWrite(s2_stepPin, HIGH);
			c2 = 0;
		} 
		delayMicroseconds(1); 
		digitalWrite(s1_stepPin, LOW); 
		digitalWrite(s2_stepPin, LOW); 
		delayMicroseconds(1); 
	} 
}


[www.hydraraptor.blogspot.com]
Anonymous User
Re: Need help for control two stepper motors!
August 26, 2009 10:24AM
#define s1_stepPin 53
#define s1_dirPin 51
#define s1_enablePin 49


#define s2_stepPin 47
#define s2_dirPin 45
#define s2_enablePin 43


void setup()
{
Serial.begin(9600);


pinMode(s1_stepPin, OUTPUT);
pinMode(s1_dirPin, OUTPUT);
pinMode(s1_enablePin, OUTPUT);
pinMode(s2_stepPin, OUTPUT);
pinMode(s2_dirPin, OUTPUT);
pinMode(s2_enablePin, OUTPUT);

digitalWrite(s1_dirPin, HIGH);
// digitalWrite(s1_stepPin, LOW);
digitalWrite(s1_enablePin, LOW);
digitalWrite(s2_dirPin, HIGH);
//digitalWrite(s2_stepPin, LOW);
digitalWrite(s2_enablePin, LOW);

}

void loop()
{

long t_end=1000000L;
int s1_steps=10000;
int s2_steps=20000;

int t1 = t_end/s1_steps;
int t2 = t_end/s2_steps;

int c1 = 0;
int c2 = 0; r
long t_total = 0;

while (t_total++ < t_end) {
if (++c1 == t1) {
digitalWrite(s1_stepPin, HIGH);
c1 = 0;
}
if (++c2 == t2) {
digitalWrite(s2_stepPin, HIGH);
c2 = 0;
}
delayMicroseconds(1);
digitalWrite(s1_stepPin, LOW);
digitalWrite(s2_stepPin, LOW);
delayMicroseconds(100);
}
digitalWrite(s1_enablePin, HIGH);
digitalWrite(s2_enablePin, HIGH);
}

Edited 1 time(s). Last edit at 08/26/2009 11:01AM by perpuna.
Sorry, only registered users may post in this forum.

Click here to login