0

I have been following this tutorial using the same hardware, TB6600 driver, 42HS48-1704A (yes I think its supposed to be 42hs40 but thats not what it says the sticker) stepper but am controlling via a Nano.

The code,

const int stepPin = 5; 
const int dirPin = 2; 
const int enPin = 8;

int num_steps = 200;
int dt = 1000;

void setup() {

  pinMode(stepPin, OUTPUT); 
  pinMode(dirPin, OUTPUT);
  pinMode(enPin, OUTPUT);
  digitalWrite(enPin, LOW);
  
}

void loop() {

  digitalWrite(dirPin, HIGH); // Enables the motor to move in a particular direction

  for(int x = 0; x < num_steps; x++) {

    digitalWrite(stepPin, HIGH); 
    delayMicroseconds(dt); 
    digitalWrite(stepPin, LOW); 
    delayMicroseconds(dt); 

  }

  delay(1000); // One second delay
  digitalWrite(dirPin, LOW); //Changes the direction of rotation

  for(int x = 0; x < num_steps; x++) {

    digitalWrite(stepPin, HIGH);
    delayMicroseconds(dt);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(dt);

  }

  delay(1000); 
}

I added dt so I could control the step speed but its not behaving as I thought it would.

The original code has dt = 500 which needed 15V to run & runs not quite chunky movement but bordering on it & just over 1 revolution when num_steps = 2000

I changed to dt = 1000 & now its got really smooth faster motion & doing quite a few revolutions (too fast for me to count with my eyes) but if reduce num_steps = 200 that results in 1 revolution & now only needs 9V to run.

So, how come when I increase the delay it runs faster? Is this some kind of clocking/synching issue?

1 Answer 1

2

With dt = 500 you get one step per millisecond. This is probably too fast for the motor/driver combination. When the driver tries to execute another step, while the previous is not fully executed by the motor shaft (which needs some time due to the shafts inertia), the magnets will misalign and the coil current of the current step will not result in a proper rotation of the shaft. Some of the pulses are aligned enough to the motor shaft position just by chance and can result in a correct step. So the motor skips some of the pulses due to its inertia. Increasing the voltage will increase the force of the motor coils, which drive the shaft. Thus it can overcome the described problems easier (the shaft moving faster by the force of one pulse than before)

Increasing to dt = 1000 gives the motor enough time to follow each step. You aren't loosing steps because the magnets and coils in the motor always align correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.