Hey guys,
So, I am currently working on a project that requires accurate RPM control.
I have JK86HS115-6004 stepper motor and JKD2060AC stepper driver. I set the driver to 800 pulses/revolution and I power it from a 60V / 6A DC power supply. It is going to be a part of a cnc I am building. The ball screws have 5mm lead which I take into account.
Here is the problem. Since it is a future cnc, I work with mm/min feed values. I set the feed to 5mm/min. Since the lead is 5mm, it should take the motor 1 minute to make 1 revolution. But that is not the case. It takes 25 seconds or less but it makes exactly one revolution. I calculate the needed values in the code (see below) such as frequency, RPM, period etc. What seems to be the problem is the period (pd), no matter what I do with it (I tried dividing, multiplying, setting the value manually) the revolution is always too quick. I read somewhere here that 10us delay is enough for the driver to send the pulse and for the motor to move. So I changed the code accordingly, but no dice.
What am I not seeing?
#define DIR 3
#define PUL 4
#define ENA 5
float freq; //frequency
float p_rev = 800.0; //pulses(steps) per revolution
float rpm; //RPM
float s = 5.0; //lead of the ball screw
float mm_min = 5.0; //feed
float dist_mm = 5.0; //the distance the nut should travel
float mm_step; //the distance the nut travels with one step
int pd; //delay period
int stp; //number of steps the motor has to make
void setup() {
pinMode(DIR, OUTPUT);
pinMode(PUL, OUTPUT);
pinMode(ENA, OUTPUT);
}
void loop() {
rpm = mm_min/s;
freq = (p_rev * rpm)/60.0;
pd = ((1/freq) * 1000000.0)-10;
mm_step = s/p_rev;
stp = dist_mm/mm_step;
for(int i = 0; i <= stp; i++){
digitalWrite(PUL,HIGH);
delayMicroseconds(10);
digitalWrite(PUL,LOW);
delayMicroseconds(pd);
}
delay(2000);
}