Hi, I am successfully moving two Nema 23 steppers with two 2M542 controllers. However, one piece of code works, the other does not. See the third line from the bottom labelled "DEBUG". The Serial commented) makes the code work. The delay does not. Now any ideas why? the STEP_UP constant is about 500 milliseconds. Tried lower and higher. Makes no difference.
for (int i =1; i <= i_steps; i++) {
digitalWrite(DIRMINUS_LEFT,LOW); //change direction
digitalWrite(DIRMINUS_RIGHT,LOW);
digitalWrite(PULMINUS_LEFT,HIGH); //make a step L motor
digitalWrite(PULMINUS_RIGHT,HIGH); //make a step R motor
if (Serial.available()) {
char inChar = (char)Serial.read();
if (inChar = '5'); {
digitalWrite(PULMINUS_LEFT,LOW); //reset so you can make another step
digitalWrite(PULMINUS_RIGHT,LOW);
s_selection = '0';
Serial.println("STOPPED");
stringComplete = false;
break; //goto EscapeLine;
}
}
delayMicroseconds(STEP_UP); //Serial.println("Moving UP one step");//DEBUG
digitalWrite(PULMINUS_LEFT,LOW); //reset so you can make another step
digitalWrite(PULMINUS_RIGHT,LOW);
}
I would not put Serial.read() in the middle of the stepper code - it makes debugging far too complex, Put different parts of the program in different functions. Then you can test the different parts separately.
Do you really mean that you are using delayMicroseconds() to create a 500 millisecond delay?
In any case you would be much better using neither delay() nor delayMicroseconds(). have a look at the second example in this Simple Stepper Code
You are trying to start a NEMA23 at 2000 steps a second from cold? Not likely to work.
Go and get the AccelStepper library, look at the examples. Big heavy steppers must have their
step rates ramped up to allow for the high inertia of the rotor (and load).
You code loop is fundamentally broken as you have no delay between setting the pulse pins
low at the end of the loop and taking them high again at the head of the loop.
This is how to hand-drive a step+direction interface:
void make_step (boolean direction)
{
digitialWrite (dir_pin, direction) ;
delayMicroseconds (5) ; // direction must be setup before the step rising edge
digitalWrite (step_pin, HIGH) ;
delayMicroseconds (10) ; // allow enough time for slow opto-couplers.
digitalWrite (step_pin, LOW) ;
}
You can reduce the delay times if no opto-couplers are involved (talking straight to a DRV8825
for instance). Reverse the logic if the step/dir outputs are active low (common anode).
Hi Mark - RE: "You code loop is fundamentally broken as you have no delay between setting the pulse pins
low at the end of the loop and taking them high again at the head of the loop."
I was hoping the four lines of code (i,e, the serial write and the boolean changes ) would work as a delay?
MikeDutton:
Hi Mark - RE: "You code loop is fundamentally broken as you have no delay between setting the pulse pins
low at the end of the loop and taking them high again at the head of the loop."
I was hoping the four lines of code (i,e, the serial write and the boolean changes ) would work as a delay?
You haven't understood what I've said. There are no statements of any kind between setting the pulse pins
low at the end of the loop and taking them high again at the head of the loop - just the loop
variable housekeeping which will be < 1us or so.
Optocouplers as usually used in motor drivers are slow, take many us to respond.