I am currently designing a test rig that has two stepper motors in sync. I need them to have watchdog switches so if one stepper motor is stopped and doesn't complete the full revolution the system stops.
I have tried Switch/Case, if statements and if/else statements with no luck.
I had tried to write the code so when one switch was hit the steppers would step halfway through a revolution and then when the next witch was triggered it would step through the second half of the revolution.
After each full revolution I would like the LCD to also Display what iteration ( what revolution) it was on.
On top of all of this I would like to have the system running at 120 rpm with possibility of cranking it up to 600-800 rpm.
I am using a Arduino Uno and controlling the steppers with a ST-M5045 MircoStep Controller.
I would appreciate any insight. I would post code but do to trying multiple ways I have like 6 different files and none of them come close to working.
Would making an array 1x250 with alternating 1's and 0's and calling the column with a for loop to decide which if statement to run be faster than the modulo?
for (int x = 0; x <= 200; x++) {
if (upDown == 0) {
digitalWrite(9, HIGH);
delayMicroseconds(sensorValue);
upDown = 1;
}
else {
digitalWrite(9, LOW);
delayMicroseconds(sensorValue);
upDown = 0;
}
}
Also, why have you duplicate code. This should work just as well
byte upDown = 0;
for (int x = 0; x <= 200; x++) {
digitalWrite(9, upDown);
delayMicroseconds(sensorValue);
upDown = ! upDown;
}
It may also be wise to abandon delayMicroseconds() in favour of the using micros() or millis() as in the second example in this [simple stepper code](http://forum.arduino.cc/index.php?topic=277692.0).
You probably should also abandon the use of FOR as that also blocks until it is complete.
That will make your code much more responsive
...R
Thank you modifying your code solved my issue and now it runs like a charm!!!!
for (int x = 0; x <= 100; x++)
{
digitalWrite(9, HIGH);
delayMicroseconds(sensorValue);
digitalWrite(9, LOW);
delayMicroseconds(sensorValue);
}
But note the modulo wasn't the problem in the first place, the limiting
factor is that digitalWrite is very slow because its general enough to work
with any pin.
Direct port manipulation is often employed when speed really matters.
What actual step rates are you wanting to achieve?
You will need to deal with ramping up the speed to get to high stepping speeds,
a motor cannot accelerate infinitely fast.