0
\$\begingroup\$

I trying to interface with an stepper motor driver board (ST330-v3 - page 7)

Timing diagram from the datasheet: enter image description here

The board need sequence of signals, which i tried create by this code. but aren't sure if the code follows the timing required, or descriped in the data sheet.

Which is why i hoped that any of you guys could look through the code and see if the timing fits or not..

Here is the code:

.h file:

/* Class: stepper_motor
 * Info: contains the setup, and primary interface to control
 * the stepper motor
 *  
 * stepper_motor(): constructor -  setup the connection to the control board
 * void step_pwm():  Moves the tilt - uses the bool to determine the direction. 
 * bool alive_bool: Is either high (1) or low (0), used for the alive void. 
 */

#ifndef stepper_motor_h
#define stepper_motor_h

#include "Arduino.h"
#include "pins_arduino.h"

#define step_pin  D0
#define dir_pin   D1
#define en_pin    D2

 class stepper_motor
{
  public:
    stepper_motor();
    void alive();
    void init_communication();
    void step_pwm();
  private:
    bool alive_bool;
    bool position_bool;
};

#endif

.cpp file

#include "stepper_motor.h"

stepper_motor::stepper_motor()
{
  pinMode(BUILTIN_LED,OUTPUT);
  pinMode(step_pin,OUTPUT);
  pinMode(dir_pin,OUTPUT);
  pinMode(en_pin,OUTPUT);

  alive_bool = true;
  position_bool = true;
}


void stepper_motor::alive()
{
  if(alive_bool == true)
  {
    digitalWrite(BUILTIN_LED,HIGH); 
    alive_bool = false;
    delay(2000);
  }
  else if(alive_bool == false)
  {
    digitalWrite(BUILTIN_LED,LOW);
    alive_bool = true;
    delay(2000);
  }
}

void stepper_motor::init_communication()
{
  digitalWrite(step_pin, HIGH);
  digitalWrite(dir_pin,HIGH);
  digitalWrite(en_pin,LOW);

  delay(0.01); //t1

  digitalWrite(step_pin,HIGH);
  digitalWrite(dir_pin,HIGH);
  digitalWrite(en_pin,HIGH);

  delay(0.005); // t2

  digitalWrite(step_pin,HIGH);
  digitalWrite(dir_pin,LOW);
  digitalWrite(en_pin,HIGH);

  delay(0.005); //t4

  digitalWrite(step_pin,LOW);
  digitalWrite(dir_pin,LOW);
  digitalWrite(en_pin,HIGH);

  delay(0.0025); //t3

  digitalWrite(step_pin,HIGH);
  digitalWrite(dir_pin,LOW);
  digitalWrite(en_pin,HIGH);

  delay(0.0025);

  digitalWrite(step_pin,LOW);
  digitalWrite(dir_pin,LOW);
  digitalWrite(en_pin,HIGH);

  delay(0.0025);

  digitalWrite(step_pin,HIGH);
  digitalWrite(dir_pin,LOW);
  digitalWrite(en_pin,HIGH);


  delay(1000);

  digitalWrite(step_pin,HIGH);
  digitalWrite(dir_pin,HIGH);
  digitalWrite(en_pin,HIGH);

  delay(0.005);

  digitalWrite(step_pin,LOW);
  digitalWrite(dir_pin,HIGH);
  digitalWrite(en_pin,HIGH);

  delay(0.0025);

  digitalWrite(step_pin,HIGH);
  digitalWrite(dir_pin,HIGH);
  digitalWrite(en_pin,HIGH);

  delay(0.0025);

  digitalWrite(step_pin,LOW);
  digitalWrite(dir_pin,HIGH);
  digitalWrite(en_pin,HIGH);

  delay(0.0025);

  digitalWrite(step_pin,HIGH);
  digitalWrite(dir_pin,HIGH);
  digitalWrite(en_pin,HIGH);

}

The init_communication() is here in question.

Thanks in advance

\$\endgroup\$
1
\$\begingroup\$

This isn't an EEPROM, display or accelerometer which you have to initialize with a sequence of specific steps before it will work; You are misinterpreting the timing requirements as some kind of initialization sequence. This is somewhat understandable, given the quality of the datasheet.

To get a better picture, take a look at the datasheet of the actual stepper driver IC used.

In summary, the TB6560AHQ is a step/direction interface stepper driver. To move one microstep in one direction, you drive the clock line high and back low. The driver simply counts the amount of pulses you send and increments the commutation phase one microstep with each rising edge of the step (clock) signal. To reverse the direction you simply switch the state of the direction signal. The driver does no motor speed/acceleration ramps by itself, so you will have to do them in software.

To actually initialize the driver, you just wait a bit and then pull /reset and /enable high and keep them high.

Turn on VDD. Then, when the VDD voltage has stabilized, turn on VMA/B. Hold the control input pins Low while turning on VDD and VMA/B. (All the control input pins are internally pulled down.) After VDD and VMA/B completely stabilizes at the rated voltages, the RESET and ENABLE pins can be set High. If this sequence is not properly followed, the IC may not operate correctly, or the IC and the peripheral parts may be damaged

If you do release the enable line the driver will just de-energize the motor and you will lose steps.

\$\endgroup\$
  • \$\begingroup\$ The only port which seem accessible to me from the driver is the Step,DIR and en pin... Which of these would be the clock signal?.. \$\endgroup\$ – Carlton Banks Sep 21 '16 at 22:08
  • \$\begingroup\$ So basically.. Step would be a simple PWM signal in which the time in-between would determine the speed of the motor => possible ramp-up so motor doesn't hum. And dir, is either pulled low or high depending on the direction it has to move. \$\endgroup\$ – Carlton Banks Sep 21 '16 at 22:13
  • \$\begingroup\$ And lastly is the en pin used to enable the use of the driver. \$\endgroup\$ – Carlton Banks Sep 21 '16 at 22:17
  • \$\begingroup\$ @CarltonBanks Don't PWM the step AKA clock signal! Keep it at 50% esp. at high frequencies, or you will miss steps. You cannot control the winding current from the microcontroller by PWM or otherwise. The duty cycle of step signal has no effect at all. The TB6560AHQ has two current (torque) setting pins (TQ1 and TQ2) but your board connects them to a DIP switch. Just select a suitable current with the switches. The settings can be found under the label "static current setting" in the ST330 datasheet. Your understanding of the direction and enable pins is correct. \$\endgroup\$ – jms Sep 21 '16 at 22:31
  • \$\begingroup\$ How the step signal works: the driver rotates the motor one microstep for each step pulse. Say you have a 3.6 degrees/step motor, and you have set the stepping resolution to 8 microsteps (found under "segments settings" in the datasheet). If you want the motor to move one full revolution, you need to output exactly 800 low to high transitions to the step pin. How much you space these pulses apart determines the speed: 400 pulses per second would result in 180 degrees per second. \$\endgroup\$ – jms Sep 21 '16 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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