I am using a NEMA23 stepper motor with RMCS-1101 DRIVE. The drive is having PULSE and DIRECTION inputs. I am trying to stop the motor after some rotations and then again start rotating it in opposite direction. But the motor is not stopping. I have written the following code for ARDUINO MEGA2560.
int pulse= 8;
int dir = 22;
int pin1 = 52;
int pin2 = 53;
float step_angle= 1.8;
void setup()
{
pinMode(pulse,OUTPUT);
pinMode(dir,OUTPUT);
}
void move_clockwise(unsigned long rev)
{
for(unsigned long i=0; i<(rev*360)/step_angle; i++)
{
digitalWrite(dir,HIGH);
{
digitalWrite(pulse,HIGH);
delay(1);
digitalWrite(pulse,LOW);
delay(1);
}
}
}
void move_anticlockwise(unsigned long rev)
{
for(unsigned long i=0; i<(rev*360)/step_angle; i++)
{
digitalWrite(dir,LOW);
{
digitalWrite(pulse,HIGH);
delay(1);
digitalWrite(pulse,LOW);
delay(1);
}
}
}
I can't figure what your brake function will achieve. The idea for steppers is that they don't move if they don't get step instructions.
You are sending pulses that are 1 millisec long and you have a 1 millisec delay bewteen pulses - so a 2msec delay between steps. Generally the step pulse just needs to be a few microsecs long and I would all the delay between the pulses - it makes it easier to see what is happening.
Have you tried running the motor much slower - perhaps 100msecs between pulses? (Or even longer). If it works at slow speed but not at higher speed it may mean that you need to accelerate/decelerate the motor and/or it may mean you need a higher drive voltage to overcome the motor coil inductance at higher frequencies. With higher voltages you must use a driver that can limoit the current.
I presume you have a suitable power supply for the motor and you are not trying to drive it from the Arduino 5v pin.
I'm not sure what will happen when you divide an integer by a float (1.8). Best not to try. Just work with the number of steps per revolution.
Also, where you have calculations that always give the same answer "360/step_angle" and within the loop "(rev360)/step_angle just do the calculation once and store the result.
Thank you for your reply. The driver that I am using is having STEPS/REVOLUTION setting. I have set it to 1600.
For my project, I want to rotate the motor clockwise for some revolutions then I want to Stop the motor for some time(not using delay) then again rotate it in the opposite direction and stop. Please do give some suggestions. I do not have much idea on this.
Details of motor and driver: http://robokits.co.in/shop/index.php?main_page=product_info&cPath=2&products_id=384
Your brake loop has no delay in it, so it will execute is basically no time at all and you cannot perceive the delay while the motor is paused.
You don't need to change any output pins to pause the motor (unless deceleration is required, but given you're stepping at 500Hz, this is not a problem at all unless you have huge moment of inertia connected to the motor). For brake, just put a delay() in with no IO actions.
That motor and driver combination seems fine. make sure to set the correct current limit or you risk damaging the motor.
You haven't given any details of your power supply.
For testing purposes taake the 3 lines of code you have in loop() and put them at the end of setup() leaving loop() empty.
Delete the line "motor_brake1();"
Change the lines
digitalWrite(pulse,LOW);
delay(1);
in both places to read
digitalWrite(pulse,LOW);
delay(100);
Change the calls "move_clockwise(10);" (and anticlockwise) jusst to do a single revolution.
And I presume you are changing the calculation of the number of steps to use 1600 rather than steps/deg etc.
And, of course, if you want the motor to stay stationary for a time between moves you will need to put delay() between the moves with a suitable number of millisecs. By the way, later you will need to learn how to have long "delays" without using the delay() function.
You could get away with a single move function if you pass the direction as a parameter - but that won't affect the working of the present code.
Thank you for your reply. I am using a 24 Volts DC power Supply and current setting is in 2 Amperes. (In the driver there is provision of reducing current when the motor is paused. Now I am able to pause the motor.