6400 steps per revolution for Nema17 and TMC2208. Is it normal?

59 views
Skip to first unread message

Guy Jaminon

unread,
May 27, 2025, 9:24:17 AMMay 27
to accelstepper
Hi everybody,
I made a system with 2 motors that works well at a "maxspeed" around 1000.
I want to increase speed but if i increase "maxspeed" to 5000, the sync between the two motors become inaccurate.
To make one turn, the motors need 6400 steps. I've read somewhere that a stepper motor take 200 steps per revolution so can you please advise?
Thank's in advance.
Here is the code : 
#include <arduino.h>
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int OLED_RESET = -1;
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
const int boutonstart = 12;
const int boutonfilament = 13;
const int vitesse_pin = A1;
const int largeur_pin = A0;
const int moteurbobinems1_pin = 7;
const int moteurbobinems2_pin = 6;
const int moteurguidems1_pin = 10;
const int moteurguidems2_pin = 9;
const int moteurbobineen_pin = 8;
const int moteurguideen_pin = 11;
AccelStepper moteurbobine(AccelStepper::FULL2WIRE, 3, 2); // Step, Dir
AccelStepper moteurguide(AccelStepper::FULL2WIRE, 5, 4);
int vitesse = 0;
int largeur = 0;
long balayage = 0;
long distance = 0;
// Côté moteur bobine
// le rapport petite roue (36 dents) grande roue (92 dents) est 92/36=2.556. soit nombre de pas pour un tour de bobine = 6400*92/36=16356
// ce qui est équivalent au diamètre du filament soit 1.75mm . Pour un déplacement d'1mm, il faut 6400*92/36/1.75 pas soit 9346,03
// Côté moteur guide
// 160000 pas donnent un déplacement latéral de 97.5 mm. pour un déplacement d'1 mm, il faut 160000/97.5 pas soit 1641.025
// la vitesse de rotation du guide doit être proportionnelle à la vitesse de la bobine.
// le rapport devrait être : 6400*92/36/1.75/160000*97.5 soit : 5.695238
// Quand la bobine aura fait un tour, le guide sera déplacé de 1.75mm (diamètre du filament)
float pas = 3.9; // 1 tour moteurguide,  pas de la vis en mm.  6400/1641.025= 3.9
float rapport = 6400.0 * 92 / 36 / 1.75 / 160000 * 97.5;
int vitesseprecedente = 0;
float moteurbobinevitesse = 500;
float moteurguidevitesse = moteurbobinevitesse / rapport;
bool bobinageencours = false;
bool disable = true;
int startetat = 1;
int filamentetat = 1;
int moy = 15;
int largeurx = 0;
int couches = 0;
int decalage = 6564; // around 4 mm
void affichage();

void setup()
{
  Serial.begin(115200);
  delay(500);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.display();
  pinMode(boutonstart, INPUT_PULLUP);
  pinMode(boutonfilament, INPUT_PULLUP);
  pinMode(moteurbobinems1_pin, OUTPUT);
  pinMode(moteurbobinems2_pin, OUTPUT);
  pinMode(moteurguidems1_pin, OUTPUT);
  pinMode(moteurguidems2_pin, OUTPUT);
  pinMode(moteurbobineen_pin, OUTPUT);
  pinMode(moteurguideen_pin, OUTPUT);
  moteurbobine.setMaxSpeed(moteurbobinevitesse);
  moteurbobine.setAcceleration(500);
  moteurbobine.moveTo(-100000000); //
  moteurguide.setMaxSpeed(moteurguidevitesse);
  moteurguide.setAcceleration(500 / rapport);
  moteurguide.moveTo(0);
  digitalWrite(moteurbobinems1_pin, LOW);
  digitalWrite(moteurbobinems2_pin, LOW);
  digitalWrite(moteurguidems1_pin, LOW);
  digitalWrite(moteurguidems2_pin, LOW);
  digitalWrite(moteurbobineen_pin, disable); // coil motor disabled
  digitalWrite(moteurguideen_pin, disable);  // guide motor disabled
  affichage();
}

void loop()
{
  vitesse = map(analogRead(A1), 0, 1000, 1, 10);
  startetat = digitalRead(boutonstart);
  filamentetat = digitalRead(boutonfilament);

  if (bobinageencours == false) // Before starting the motors
  {
    largeurx = 0;
    for (int i = 0; i < moy; i++)
    {
      largeurx += analogRead(A0);
    }
    largeur = map(largeurx / moy, 20, 1022, 25, 60);
    distance = 6400L / pas * largeur; // number of steps the guide motor must move to cover the coil width
    balayage = distance;
    affichage();
  }

  if (filamentetat == 1) // if that switch opens, the motors and the process must stop
  {
    disable = true;
    digitalWrite(moteurbobineen_pin, disable); // coil motor disabled
    digitalWrite(moteurguideen_pin, disable);  // guide motor disabled
    bobinageencours = false;
  }

  if (startetat == 0) // when this switch close, the process must start
  {
    couches=0;
    disable = false;
    moteurguide.moveTo(-decalage);
    moteurbobine.setMaxSpeed(moteurbobinevitesse * vitesse);
    moteurguide.setMaxSpeed(moteurguidevitesse * vitesse);
    digitalWrite(moteurguideen_pin, disable); // guide motor enabled
    while (moteurguide.distanceToGo() != 0)
    { // move guide 4mm to the right limit of the coil
      moteurguide.run();
    }
    moteurguide.stop();
    moteurguide.setMaxSpeed(moteurguidevitesse * vitesse);
    moteurguide.moveTo(balayage);
    digitalWrite(moteurbobineen_pin, disable); // coil motor enabled
    bobinageencours = true;                    // Indicate that the process is started
  }

  if (vitesse != vitesseprecedente) // The speed can be modified during the process
  {
    vitesseprecedente = vitesse;
    moteurbobine.setMaxSpeed(moteurbobinevitesse * vitesse);
    moteurguide.setMaxSpeed(moteurguidevitesse * vitesse);
    affichage();
  }

  if (bobinageencours == true) // Following happens only if the process is started
  {
    if (moteurguide.distanceToGo() == 0)
    {
      moteurbobine.stop();
      if (balayage > 0)
      {
        moteurguide.stop();
        moteurguide.setMaxSpeed(moteurguidevitesse * vitesse);
        moteurguide.moveTo(balayage + decalage * 2);
        while (moteurguide.distanceToGo() != 0)
        { // move guide 4mm to the left limit of the coil
          moteurguide.run();
        }
        moteurguide.stop();
        moteurguide.setMaxSpeed(moteurguidevitesse * vitesse);
        balayage = 0L;
      }
      else
      {
        moteurguide.stop();
        moteurguide.setMaxSpeed(moteurguidevitesse * vitesse);
        moteurguide.moveTo(-decalage);
        while (moteurguide.distanceToGo() != 0)
        { // move guide 4mm to the right limit of the coil
          moteurguide.run();
        }
        moteurguide.stop();
        moteurguide.setMaxSpeed(moteurguidevitesse * vitesse);
        balayage = distance;
      }
      moteurguide.moveTo(balayage);
      couches++;
      affichage();
      moteurbobine.setMaxSpeed(moteurbobinevitesse * vitesse);
      moteurbobine.moveTo(-100000000);
    }
    moteurbobine.run();
    moteurguide.run();
  }
}

void affichage()
{
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Vitesse: ");
  display.println(vitesse);
  display.setCursor(0, 20);
  display.print("largeur: ");
  display.print(largeur);
  display.setCursor(0, 40);
  display.print("Couches : ");
  display.print(couches);
  display.display();
}

Jim Larson

unread,
May 27, 2025, 2:15:58 PMMay 27
to accelstepper
Welcome to the AccelStepper Forum!

Here are two thoughts about your motor speed of 6400 steps/revolution instead of the expected 200 steps per revolution:

I'm not sue this has anything to do with it, but I notice you are declaring your driver as AccelStepper::FULL2WIRE. Typically, step/direction drivers like the Trinamic 2208 are declared as AccelStepper::DRIVER. Try making that change and see if it matters.

More likely, I think, is that you have 32 step microstepping mode selected on your 2208s. AccelStepper does not know about microstepping, it can only issue steps. So if 32 step microstepping is selected, it will take 32 x 200 = 6400 steps per revolution. You should check this and perhaps select 2 or 4 step microstepping, depending on your needs.

HTH!
              -jim

guyjami

unread,
May 28, 2025, 3:39:47 PMMay 28
to accelstepper
Thank's a lot. It's my first experience with stepper motors. With MS1 LOW and MS2 High, the number of steps for a revolution is 1600. I've not yet try to modify the declaration. I'll do it tomorrow. I'll check also how to reprogram the TMC2208 with less microsteps.
I'll be back ;-)

guyjami

unread,
May 29, 2025, 8:12:45 AMMay 29
to accelstepper
Thank's Jim, you're absolutely right !
With the right declaration (DRIVER), the number of steps for one revolution goes down to 400 with MS1 HIGH and MS2 LOW. The other combinations of MS1  and MS2 correspond to 800, 1600 and 3200 steps per revolution ( 200*2, 200*4, 200*8 and 200*16).
In addition, the motors temperature is acceptable. In the previous configuration, they were very hot, impossible to let a finger on them !
I'll now solve some issues about my code.
Best Regards
Guy 
Reply all
Reply to author
Forward
0 new messages