Interrupt Driven Rotary Table controller

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

rodw

Well-Known Member
Joined
Dec 2, 2012
Messages
1,146
Reaction score
340
You can read the thread where this is documented form go to woe during the development here:
http://www.homemodelenginemachinist.com/showthread.php?p=273830#post273830
if you need more help but this thread is designed to provide a simple easy to install solution of version 10 of my Rotary Table controller.

I am going to assume you already have installed the Arduino IDE on your PC. Don't worry if you don't have an Arduino at this stage.

All you have to do is to find the Arduino folder in "My Documents". On my PC it was in this folder C:\Users\Rod\Documents\Arduino and unzip the attached file into it. I am guessing that you have a different name to me so it will be a bit different on your PC :) Please substitute my name with yours....

So you should now have the following folders in the Arduino folder
C:\Users\Rod\Documents\Arduino\libraries
C:\Users\Rod\Documents\Arduino\RotaryTable10


In the Libraries folder you should find the following folders
C:\Users\Rod\Documents\Arduino\libraries\LCD
C:\Users\Rod\Documents\Arduino\libraries\TimerOne-r11


In the C:\Users\Rod\Documents\Arduino\RotaryTable10 folder you will find the following files:
EEPROMAnything.h
RotaryTable10.ino


Assuming you have the Arduino IDE installed on your PC if you double click on
RotaryTable10.ino and it should open in the IDE.

Arduino%20IDE_zpsvpxi42ia.png


Click the Button marked with the Red Arrow to verify that the script will compile. This does not require an Arduino attached to your PC so you can get it compiling before you spend your money.

Then, grab yourself these things:
1. An Arduino Uno or equivalent
2. A Freetronics LCD display; see http://www.freetronics.com.au/collections/display/products/lcd-keypad-shield
3. A stepper controller
4. A stepper motor. NEMA 23 is a good size for a 6 inch Rotary table
5. Power supply (minimum 24 volt in my experience, around 80% of what you stepper driver is rated for - I use a 48 volt power supply).

With the LCD attached to your Arduino, plug your Arduino into a USB port, check your system is properly configured and hit the button pointed to by the blue arrow. The script will be recompiled and downloaded to your Arduino. The Arduino screen should light up after this process.

Connect up your stepper controller to the Arduino. making sure you are working on the low voltage side of the controller. You need to provide 5 volt power, ground and a step and direction port. The Arduino has enough current to drive the stepper controller.

Then connect power to the high voltage side of your controller and connect the wires correctly to your stepper motor.

Check the Setup menu and set up the step and direction ports to agree with those you chose when connecting your Arduino to the Stepper controller. Also set the various pulse parameters to suit your hardware.

Check the maxHz and MinHz settings in the setup folder. Start at around 5,000 and 9,000 (for Max and Min respectively or accept the defaults).

Makee sure you save the setup.

You should not need to touch the code to get it going as everything is set in the setup menu and stored in the EEPROM memory forever on the Arduino.

Note that the script also supports linear devices and multiple devices. via the new device function in setup. This simply creates a new numbered setup in the EEPROM. You can load devices at will to swap between devices when setup.

The main feature of this controller is that it uses interrupts for high performance and this also allows it to ramp up and down to speed so that it can overcome inertia by running slowly at maximum torque and ramping up to speed.

There are heaps of dividing functions, jogging and continuous turning. Some people have modified this script to alter the speed while continuous turning but on a 90:1 rotary table like mine, the maximum speed you are going to get is about 4 RPM so it is a bit pointless attempting to change the speed IMHO.

Anyway, I'm sure I've overlooked some stuff but please try this and report back. Just remember if you are not using a Freetronics LCD display and keyboard you are on your own!

View attachment RotaryTable10.zip
 
Here are links to hardware that will work (and you can grab both in the one order)
Freetronics Arduino Compatible board : http://www.freetronics.com.au/collections/arduino/products/eleven#
Freetronics Keyboard and LCD: http://www.freetronics.com.au/collections/display/products/lcd-keypad-shield#

Any Arduino UNO Compatible board will work. I have used the board above, a genuine UNO and a Chinese Clone without any dramas.
As stated above, the LCD display on this link is the one the LCD library is designed for.
 
Hi Rod

I Downloaded your Rotary Table 10 program but get an Error message when Verifying sketch, Error:

Temp1_RotaryTable10.zip\RotaryTable10\RotaryTable10.ino:1:23: fatal error: BoolField.h: No such file or directory
#include <BoolField.h>
^
compilation terminated.
exit status 1
Error compiling.

Any idea if it's me, my computer or the sketch ?

Emgee
 
Hi Rod

I Downloaded your Rotary Table 10 program but get an Error message when Verifying sketch, Error:

Temp1_RotaryTable10.zip\RotaryTable10\RotaryTable10.ino:1:23: fatal error: BoolField.h: No such file or directory
#include <BoolField.h>
^
compilation terminated.
exit status 1
Error compiling.

Any idea if it's me, my computer or the sketch ?

Emgee

The error message shows the compiler cannot find an include file. You have not installed the LCD library which should be in
C:\Users\YourName\Documents\Arduino\libraries\LCD

Please read the first post carefully and follow the instructions as the missing file is included in the Zip file.
 
hi Rodw, amazing work. i wrote a programme to do this for a pic, but yours is far superior.
my controller has a common anode (5v) pin and 3 pins for step pulse and enable. i think this means my controller requires the inputs to go low to step. is this compatible with your programme? i think it is backwards to most stepper controllers.
 
hi Rodw, amazing work. i wrote a programme to do this for a pic, but yours is far superior.
my controller has a common anode (5v) pin and 3 pins for step pulse and enable. i think this means my controller requires the inputs to go low to step. is this compatible with your programme? i think it is backwards to most stepper controllers.

Thanks Mulac.

I don't think you will have any problem. I might be wrong, but I don't think this code has any concept of low and high signals. This is because if it has to move 100 steps, there are 200 distinct states which alternate on and off. The worst you could be out is therefore one step because the first state change is ignored as you started on the wrong foot so to speak. In this case, changing the definition for the variable "state" would start you off on the right foot.
 
Mike has a great video of this working here:
https://youtu.be/thxf7Uw0q2Y

Thanks Mike!

At 1:50 he makes the unit move 3 divisions or 120 degrees.
On the first move one chuck jaw is vertically down, subsequent moves should leave one jaw still vertically down but on the last move the jaws are well out ??
 
At 1:50 he makes the unit move 3 divisions or 120 degrees.
On the first move one chuck jaw is vertically down, subsequent moves should leave one jaw still vertically down but on the last move the jaws are well out ??

It can only be missed steps from poorly configured hardware, (maybe too low a voltage) as the software is spot on and proven by a number of other users.
 
Hi Rodw.
First of all thank you for all the time and effort documenting a great program.
That said I can't for the life of me get it to work lol. I am using Saintsmart uno and 1602 lcd six button shield and a tb6560 driver. I can load the sketch no worries but I dont seem to be able to get the driver part working. I have the liming sketch up and running ok. My question is I can't seem to find a wiring diagram .Is there one posted?
Cheers
john
 
Hi Rodw.
First of all thank you for all the time and effort documenting a great program.
That said I can't for the life of me get it to work lol. I am using Saintsmart uno and 1602 lcd six button shield and a tb6560 driver. I can load the sketch no worries but I dont seem to be able to get the driver part working. I have the liming sketch up and running ok. My question is I can't seem to find a wiring diagram .Is there one posted?
Cheers
john

John, first of all, I have never used the Sainsmart but a few people have used it with this sketch. I think that you may need to modify the LCD library in the keyboard sensing code and its been documented bys others in my other thread linked to in the first post. However by the sounds of it you have got this part working. If the displays and menus work, it will be fine!

So its always best to start with basics in the Arduino core library before you use a complex program. Maybe this one. https://www.arduino.cc/en/Reference/Stepper

So once you know you have a working stepper driver, install my sketch and configure the settings including the step and direction pins in the setup menu. If you have not done that, it probably is the reason why nothing moves.

There is not much to the wiring. step+ and dir+ go to the relevant digital pins and step- and dir- go to the Arduino ground. Attach the high voltage for the stepper to your controllers stepper power terminals. I'm not sure of the TB6660
but in some cases you need active low wiring so check your documentation. I've never had to do that with the Arduino though.
 
Hi Rod
Yes you are right .I never configured the step and dir pins. I will read through your thread again as I glossed over a lot of parts which were flying well over my head.
I do find this project very interesting.
Thanks
John
 
Last edited:
Hi Rod
Yes you are right .I never configured the step and dir pins. I will read through your thread again as I glossed over a lot of parts which were flying well over my head.
I do find this project very interesting.
Thanks
John

Glad you got it going.
 
Hmm Captain_Obvious reported a not so obvious bug in my software that bit where a rotary table has a coarse resolution. Where say a division required say 100.333 steps per division, the number was rounded to 100.0. This meant on say 36 divisions around a complete circle, the final division could end up being 12 steps short.

I don't currently have any working hardware to test this on but I know it compiles.

Here is a replacement GoDivide procedure. Can those using this sketch cut and paste this into your config to replace the existing goDivide procedure and see if it is working correctly?

Code:
void goDivide(long gAngle)
{
   long thisDiv = 1; 
   int event = LCD_BUTTON_NONE;
   int flag = 0;
   float tmpSTEPS_PER_REV = (float)globals.stepsPerRev;
   float remainder;
   float divLeftOver = 0.0;
   long adjustSteps = 0;
   
   stepsPerDiv = (long)(tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder = (float) (tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder -= (float)stepsPerDiv;
   divisions = (long)((float) MINUTES_IN_CIRCLE / (float) gAngle);
   printDivideVals(thisDiv,gAngle);
   while(event != LCD_BUTTON_SELECT){
      event = lcd.getButton();
      switch(event){
        case LCD_BUTTON_LEFT:
          flag++;
          thisDiv--;
          divLeftOver -= remainder;
          if(thisDiv < 1)
            thisDiv = divisions;
          digitalWrite( globals.DirPin, ANTICLOCKWISE );
          break;
        case LCD_BUTTON_RIGHT:
          flag++;
          thisDiv++;
          divLeftOver += remainder; 
          if(thisDiv > divisions)
            thisDiv = 1;          
          digitalWrite( globals.DirPin, CLOCKWISE );
          break;       
    }
    if(flag){ 
      if(abs(divLeftOver) >= 1.0){
        adjustSteps = 1;
        if(abs(divLeftOver) == divLeftOver)  
          divLeftOver -= 1.0;    // Positive value >= 1.0
        else
            divLeftOver += 1.0;  // Negative Value <= 1.0
      } else
          adjustSteps = 0;
    }   
    setSteps((stepsPerDiv + adjustSteps) * 2, 1);
    printDivideVals(thisDiv,gAngle);
    flag = 0;
  }
}

So what the code attempts to do is to now is to save the fractional steps in a variable called remainder (say 0.33 in our 100.33 example). This is accumulated in each step in the variable divLeftOver every time a division is made. If this variable is <= 1.0 or >=1.0, it is adjusted by 1.0 closer to zero and the number of steps in the current division is incremented by 1. That way, we should end up back on track when we complete a complete circle.

Please provide your feedback.
 
Hello again,

I tried the new script but I don't know what went wrong. As soon as I start the division or the angle program, the stepper motor just runs continuously, briefly stopping at the given number of divisions. None of the buttons do anything except for the reset button. I'm not anywhere near advanced enough to analyze to script myself. All the other functions work just like they did before.

Attached is the misbehaving script.

View attachment rotaryscript.zip
 
Hi Rod,
I don't have the hardware to test either, nor do I have a lot of experience programming in C but looking at the code in your if(flag) I saw this line: if(abs(divLeftOver) == divLeftOver) , which is comparing floats for equality. I realise it's the same variable and you're just taking the absolute value, but because of the abs function return I think you still run the normal risks of float equalities here. I've been stung by it before so it just sort of jumped out at me, so I thought I'd mention it.
 
Guys, I'm not sure what I got wrong. I'll have another look at this. Cogsy, yes I hate working with floats too. What I wanted to do is to determine if divLeftOver is a positive or negative number and there are other ways to do that.

Before I started, I modified the code to eliminate a couple of lines of duplicated code so I might have then stuffed up the working code...
 
OK, no worries. I appreciate you taking the time to do this in the first place.
 

Latest posts

Back
Top