Understanding the rotary table code

Here is some code that prints out how many steps correspond to 1, 10 and 100 degrees.
Firstly using 'Multiplier' as an int, then 'Multiplier' as a float, and finally as a float with 'steps' rounded.

Code
const int StepsPerRotation = 400;
const int TableRatio = 6;
int Multiplier = (StepsPerRotation * TableRatio) / 360;
float Degrees = 0;
float ToMove = 0;

void setup()
{
  Serial.begin(115200);

  Serial.println("Multiplier is an int");
  Degrees = 1;
  ToMove = (Degrees * Multiplier);
  Serial.print(Degrees, 0);
  Serial.print(" degree:\t ");
  Serial.print(ToMove);
  Serial.println(" steps");

  Degrees = 10;
  ToMove = (Degrees * Multiplier);
  Serial.print(Degrees, 0);
  Serial.print(" degrees:\t ");
  Serial.print(ToMove);
  Serial.println(" steps");

  Degrees = 100;
  ToMove = (Degrees * Multiplier);
  Serial.print(Degrees, 0);
  Serial.print(" degrees:\t ");
  Serial.print(ToMove);
  Serial.println(" steps\n");

  float Multiplier = (StepsPerRotation * TableRatio) / 360.0;

  Serial.println("Multiplier is a float");
  Degrees = 1;
  ToMove = (Degrees * Multiplier);
  Serial.print(Degrees, 0);
  Serial.print(" degree:\t ");
  Serial.print(ToMove);
  Serial.println(" steps");

  Degrees = 10;
  ToMove = (Degrees * Multiplier);
  Serial.print(Degrees, 0);
  Serial.print(" degrees:\t ");
  Serial.print(ToMove);
  Serial.println(" steps");

  Degrees = 100;
  ToMove = (Degrees * Multiplier);
  Serial.print(Degrees, 0);
  Serial.print(" degrees:\t ");
  Serial.print(ToMove);
  Serial.println(" steps\n");

  Serial.println("Multiplier is a float\nand steps are rounded");
  Degrees = 1;
  ToMove = (Degrees * Multiplier) + 0.5;
  Serial.print(Degrees, 0);
  Serial.print(" degree:\t ");
  Serial.print(ToMove, 0);
  Serial.println(" steps");

  Degrees = 10;
  ToMove = (Degrees * Multiplier) + 0.5;
  Serial.print(Degrees, 0);
  Serial.print(" degrees:\t ");
  Serial.print(ToMove, 0);
  Serial.println(" steps");

  Degrees = 100;
  ToMove = (Degrees * Multiplier) + 0.5;
  Serial.print(Degrees, 0);
  Serial.print(" degrees:\t ");
  Serial.print(ToMove, 0);
  Serial.println(" steps");
}
void loop()
{
}

The results are:

Good Day everybody. Thanks for your input.
I think I have to explain what I am trying to arrive at.

Basicall guys, I am building an indexer or rotary table. The sketch allows for selecting infinte divisions of 360 degrees or movement by degrees. It has a display and keypad.

My stumbling block has come up when I tried to turn the chuck for example 360 degrees or one complete revolution but the chuck does not make the correct revolutions.

I am using a TB6600 stepper driver
A nema 23 1.8 degree stepper motor with a 10 tooth cog (Driver)
A large 60 tooth cog on the chick side. So basically I have a 1 : 6 reduction.

The sketch I downloaded from the Arduino Library.
I am really lost what to do....

Lets to make the test opposite - try to determine on how many degrees the chunk should be directed to make one complete revolution.

400 * 6 = 2400
It all depends on the accuracy you need - 7220 steps will turn the dividing head exactly to the 1 degree position

good idea... I have to setup some things to check this because it was going off by too much....

What is the smallest increment you want to move the chuck (in degrees)?

That seems a bit high. My calculation was for 6.67 steps/degree, 7220 would turn 3 full turns plus 3 degrees.

I have setup a protractor with the disk and a pointer.
the settings are
const int StepsPerRotation = 400; const int TableRatio = 6; const int Multiplier = (StepsPerRotation * TableRatio)/360;
the chuck rotates 324 degrees instead of 360.

7200 = 2400+2400+2400 - 360 degrees
x = 361 degrees
x = 7200 * 361 / 360 = 7220 (361 - 360 = 1 degrees)
5th grade of the USSR school



this is my project for those wondering

the setup should divide 360 degrees into any combination. i have no idea about errors

This means we need to learn the appropriate mathematics - dividing 360 into parts, for example, by 144

You need a 5 : 9 pulley ratio, not 1 : 6.

Be aware that the result of expression (StepsPerRotation * TableRatio)/360 is not integer - it is a 6.6666667. But your Multiplier variable defined as const int.
So the value of 6.666667 wil be truncated to 6.000 before storing in the variable.

The difference of the multiplayer values between 6.666667 and 6.0000 give you exactly 324 degrees instead of 360.

You have to use a float:

const float Multiplier = (StepsPerRotation * TableRatio)/360.0;

a good dividing head can have 11 sets of gears for different ratios
I asked above what accuracy is needed, if 1 degree is enough, then I gave a simple solution on the existing set of gears

I have the const float......... in my sketch.

In that case why did posted the line

Are you trolling us?

Please show the sketch in full.

i am very aware... I had a huge machine-shop with 5 axis machines before i retired .. this is for my past time but seems there is no rest from complications... :
-)

/*
 4x4 matrix keypad amd a 20 x 4 LCD. 
 Edit StepsPerRotation & TableRatio(# of turns for 360 degrees)in line 29
 A4988 Stepstick/Pololu driver 
 5/2/2015
 */

 #include <Wire.h> 
 #include <LiquidCrystal_I2C.h>
 #include <Keypad.h>
 
 const byte ROWS = 4;
 const byte COLS = 4;
 char keys[ROWS][COLS] = {
 {'D','C','B','A'},
 {'#','9','6','3'},
 {'0','8','5','2'},
 {'*','7','4','1'}
 };

 byte rowPINS[ROWS] = {11,10,9,8};
 byte colPINS[COLS] = {7,6,5,4};

 Keypad kpd = Keypad(makeKeymap(keys),rowPINS,colPINS, ROWS, COLS);
 LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x20 for a 16 chars and 4 line display
                                   // SCL - A5, SDA - A4, VCC - +5, Gnd - Gnd 

const int stp = 2; // connect pin 2 to step 
const int dir = 3; // connect pin 3 to dir 

//Steps per rotation of stepper since stepper turns 1.8 deg per step, in 360 dgrees it does 200
// this comes about by 360divided by 1.8 drgrees
const int StepsPerRotation = 400;  

//tonio motor turns 6 times to turn chuck cog 1 rev
const int TableRatio = 6;  


const int Multiplier = (StepsPerRotation * TableRatio)/360;  // 400*90=36000/360 = 100 

 const int stepdelay = 1;
 float Degrees = 0;                // Degrees from Serial input
 float ToMove = 0;                 // Steps to move
 float bob = 0;
 int cho = 0;

 void setup()
 {
 lcd.init();      // initialize the lcd 

 pinMode(stp, OUTPUT); 
 pinMode(dir, OUTPUT); 

 // Print welcome message to the LCD.
 //lcd.backlight();
 //lcd.print("ROTARY TABLE INDEXER");
 // lcd.setCursor(4,2);
 //lcd.print(" ");
 //lcd.setCursor(3,3);
 //lcd.print("3D TECHNOLOGIES");

 lcd.backlight();
 lcd.print("ROTARY TABLE INDEXER");
 lcd.setCursor(4,1);lcd.print("MENDELEVIUM");
 lcd.setCursor(2,2);lcd.print("3D TECHNOLOGIES");
 lcd.setCursor(4,3);lcd.print("DESIGN_2025");
 
 delay(2000);
 lcd.init();
   cho = 0;
   char key = kpd.getKey();
   lcd.print("ENTER SELECTION:");   
   lcd.setCursor(0,1);
   lcd.print("DEGREES   = PRESS-A");
   lcd.setCursor(0,2);
   lcd.print("DIVISIONS = PRESS-B");
   lcd.setCursor(0,3);
   lcd.print("JOGGING   = PRESS-C");
   while(cho == 0)
   {
     key = kpd.getKey();
     switch (key)
     {
     case NO_KEY:
      break;
     case 'A':
       Degrees=getdegrees();
       lcd.clear();
       cho = 1;
       break; 
     case 'B':
       Degrees=getdivisions();  
       cho=2;
       break;
     case 'C':
       Degrees=getjog();
       lcd.clear();
       cho=3;
       break;
       }      // end case
     }      // end while cho=0
 }    // end setup
 
 void loop()      // MAIN LOOP
 {
   lcd.clear();  
   char key = kpd.getKey();
     bob = 0;
    // lcd.setCursor(7,0);lcd.print("Total:  ");lcd.print(bob,2);   // total steps
    // lcd.setCursor(0,1);lcd.print(" A FORWARD");
    // lcd.setCursor(0,2);lcd.print(" B REVERSE");
     //lcd.setCursor(0,3);lcd.print(" C RESET");
     




     lcd.setCursor(0,1);lcd.print("INCR_       -ABS POS");// added by tonio
    // lcd.setCursor(0,3);lcd.print("FOR=A   REV=B    X=C"); // original code
     lcd.setCursor(0,3);lcd.print("A=FOR B=REV  C=RESET"); //modified by tonio
   while(key != 'C')    // C will return to start menu
   {
     lcd.setCursor(0,0);lcd.print(abs(Degrees),2);lcd.print((char)223);
     key = kpd.getKey();
     if(key == 'A')            // FORWARD
       {
        bob = bob + Degrees;
        ToMove = (Degrees*Multiplier);
        digitalWrite(dir, LOW);
        printadvance();
       }
     if(key=='B')              // REVERSE
       {
        bob = bob - Degrees;  
        ToMove = (Degrees*Multiplier);
        digitalWrite(dir, HIGH);    // pin 13
        printadvance();
       }
   }      // end while not C loop
   lcd.init();
  setup();
 }      // end main VOID
 

float getjog()
{
  float Degrees = 0;
  float num = 0.00;
   char key = kpd.getKey();
   lcd.clear();
   lcd.setCursor(3,0);lcd.print("JOGGING_CYCLE");
   //lcd.setCursor(0,1);lcd.print("A=1 B=10 C=100 Steps");
   //lcd.setCursor(0,1);lcd.print("STEPS-A=1, B=10, C=100");
   lcd.setCursor(0,1);lcd.print("Ax1 Bx10 Cx100 STEPS");
   lcd.setCursor(0,2);lcd.print("enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = PRESS # ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
    while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
         case 'A':
            Degrees = 1;      
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'B':
            Degrees = 10;
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'C':
            Degrees = 100;
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'D':
          num=0.00;
          lcd.setCursor(14,2);lcd.print("     ");
          lcd.setCursor(14,2);
          break;
      }
      key = kpd.getKey();
   }
  return Degrees; 
}

 
float getdivisions()
{
  float Degrees = 0; 
  float num = 0.00;
   char key = kpd.getKey();
   lcd.clear();
   lcd.setCursor(0,1);lcd.print("Enter Division:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
   lcd.setCursor(16,1);

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
            
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
            num = num * 10 + (key - '0');
            lcd.print(key);
            break;
        
        case 'D':
          num=0.00;
          lcd.setCursor(16,1);lcd.print("     ");
          lcd.setCursor(16,1);
          break;
      }
      Degrees = 360/num;
      key = kpd.getKey();
   }
  return Degrees;  //num;
}


float getdegrees()
{ 
   //int key = 0;
   float num = 0.00;
   float decimal = 0.00;
   float decnum = 0.00;
   int counter = 0;
   lcd.clear();
   //lcd.init();
   char key = kpd.getKey();
   lcd.setCursor(0,1);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
   lcd.setCursor(15,1);
   bool decOffset = false;

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
            
         case '.':
           if(!decOffset)
           {
             decOffset = true;
           }
            lcd.print(key);
            break;   
         
         case 'D':
          num=0.00;
          lcd.setCursor(15,1);lcd.print("     ");
          lcd.setCursor(15,1);
          break;
         
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
         if(!decOffset)
         {
            num = num * 10 + (key - '0');
            lcd.print(key);
         }
         else if((decOffset) && (counter <= 1))
         {
            num = num * 10 + (key - '0');
            lcd.print(key);
            counter++;
         }
            break;
      }    //end case
      decnum = num / pow(10, counter);
      key = kpd.getKey();
   }    //end while not #
    return decnum;
}      // end getdegrees
 
 void printadvance()      // print function
   {
    // lcd.setCursor(6,1);lcd.print("Moving");//original code
     lcd.setCursor(5,1);lcd.print("TURNING");//modified by tonio
     lcd.setCursor(4,2);lcd.print("Steps  ");lcd.print(ToMove,0); 
     lcd.setCursor(13,0);lcd.print(bob,2);
     rotation(ToMove,0);
     lcd.setCursor(6,1);lcd.print("      "); 
  } 

 void rotation(float tm, int d)
   { 
     for(int i = 0; i < tm; i++) 
       { 
       digitalWrite(stp, HIGH); 
       delay(stepdelay); 
       digitalWrite(stp, LOW); 
       delay(stepdelay); 
       }
   }

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
  {
  asm volatile ("  jmp 0");  
  } 

Did you notice that in b707's post # 34, that the 360 has been changed to 360.0

This forces the computation to be done in floating pint.

Edit, you posted the code whilst I was writing my reply.
I can see that you didn't notice and change it.