I at the moment trying smoothly move a stepper motor. The problem with the stepper motor, is that it makes a high pitch noise while it moves, or sometime a crackling noise from the motor.
So i tried ramping up the frequency of the step signal, which seemed to help a bit but not perfect. Then I tried micro stepping rather than full stepping, which also helped a bit but still, the noise is very clear.
The motor I am using is a PK244-01A And the driver it is connected to is this one
I am not at all sure if the ramping I do is either too steep, or completely incorrect, but here is the code that controls the motor.
void stepper_motor::step_pwm()
{
digitalWrite(en_pin,HIGH);
delay(0.005);
digitalWrite(dir_pin,HIGH);
//LOW - Move towards the sensor
//HIGH - Move away from the sensor
delay(0.005);
int increment = 0;
int step_count = 0;
while(step_count <= max_step)
{
digitalWrite(step_pin,LOW);
delayMicroseconds(2000);
digitalWrite(step_pin,HIGH);
delayMicroseconds(2000-increment);
step_count++;
if(step_count >= 1)
{
increment++;
step_count = 0;
}
}
}
Anything I could do to make the noise of the motor less significant?
increment
variable, yet how often you increment theincrement
variable depends on the step period. Shorter steps lead to more frequent increments. I'd use a hardware timer of the ATmega to generate the step signal, an interrupt of said timer to increment the step count on each step, and have the speed control logic running in parallel as the main task, at a fixed frequency. An easier option would be to have a library do all that for you, e.g. accelStepper.