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.
Hi All,
Rod - congratulations on a great project. I'm not making it currently, but I have decades of experience in mechatronics.
I see many this thread are baffled or asking questions which reflect a lack of experience, and responders are reacting with patience (mostly) and cannot be blamed if readers don't read all the posts or follow instructions. As noted, electronics is not simple, even though those who stayed to profit from selling you stuff try to tell you it is. So I'd like to offer a couple of suggestions to electronics 'newbies'.

In Rod's OP he said - " 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)." I would always provide a motor - or any inductive load - with the rated voltage. As voltage drops, current increases, and this results in heat - bad for coils. Make sure the power supply can provide double the rated max current demand of the motor (pay attention to 'peak' ratings). If the motor stalls (in some way that does not trigger an emergency shutdown), you will release the 'magic smoke' from the power supply. And don't forget your flyback diodes!

Breadboards (or protoboards, as in the pics) can be great for prototyping, but are prone to bent contacts inside and so can be a source of frustrating intermittent faults. Don't jam big wires in, and don't carry them around unprotected. I would transfer all circuitry to a soldered perfboard as soon as the circuit is tested and working. Knowing how to make a reliable solder joint is fundamental. Sheilds, (blank boards that plug into the sockets of the Arduino) are a great way to avoid extra straggly wires. And on the subject of wires - only use solid wire for on-board connections. Use stranded wire for wires that will move/bend/vibrate - or your project will not last. If you get really ambitious, you can use a CAD program to lay out a PCB (printed circuit board) - but don't do this before you'r absolutely sure of your circuit.

More generally, an Arduino is a microcontroller, it deals in digital data (ones and zeros or ons and offs), which is a specialised form of electronics in which most of the information in the signal is thrown away. Newbies to electronics imagine voltage is the only number that matter. This is an oversimplification. Current flow seems a much more obscure concept for people to grasp. But it is fundamental.

Analog signal electronics and power electronics are very different realms from the digital. An analog circuit does not transfer data, it sings. I mean this in all seriousness - in analog electronics there is no input and output or on and off, there are resonances which are perturbed. Most of the stuff hanging on the outside of Arduino is like this to some extent.

For those in USA, I suggest Allelectronics, an electronics surplus house with good prices. I think they're currently offering UNOs for a few bucks. I've bought from them for years.
 
and another thing ! :)
Very important

while your Arduino is connected to both the stepper controller and its power supply, and also your computer, you have two power supplies. You MUST MUST MUST make sure all the ground lines in your circuit - power and signal - are tied together, or you may FRY parts of your computer. UNLESS your power circuit is totally electrically isolated from the signal/data side via optoisolators (or electromechanical relays).

The theoretical reason for this is as follows: Voltage is potential DIFFERENCE wrt an arbitrary refernence, which is what 'ground' is. DC circuits are closed worlds. When signal wires between two circuits with separate grounds are connected, havoc can ensue.

Think of it this way - each circuit is a bubble with its own atmospheric pressure, say one is at 1 atmosphere and the other is at 10. When two bubbles join, there will be a huge flow from the higher pressure to the lower pressure bubble.

At some point you will disconnect your Arduino from your computer, at which point you will require a smoothed 5v external power supply (or 7-10 v supply, depending on the input you choose), in addition to your stepper motor power supply.
 
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 80029

Uploaded code.
But buttons not working?
Used generic LCD key pad shield
 
Sorry, its been quite a while since I've been on this forum and missed the last couple of posts. Anatol, thank you very much for your compliment and additional descriptions.

For others like Shehan Perra, I don't know how many times I have said that the Arduino is not Plug and Play, The required hardware is listed. If you choose to use some other hardware, then you are on your own. Don't ask me for help.

If you don't know how to modify the code (and the answer is on this forum), then buy the required hardware or find another simpler script. This script uses advanced high performance code that works. Its well written and documented in the source. Its not really a beginner Arduino project as it pushes the limits of the Arduino.
 
I printed the first post in this thread , and followed the instructions to the letter .
It all works like a charm and I had it going in abt 10 minutes .
That includes installing the IDE and arduino clone driver .

BIG thumbs up for RodW .

Do I need to cut n paste the bug fix in the code , or has the rotary10.zip file been updated and can it be used as is ?

Pat
 
Last edited:
I think my previous post was a bit to optimistic .

I have what looks to be a sainsmart clone lcd shield .
duino2.jpg

I tried it with a "button test " sketch , and they all work as intended .
Left returns a left , select returns a select etc .

But with the rotary table sketch , the "left" button is not functional , and the "select" button seems to act as a left . It's a hardware/software incompatible issue I'm sure .

And I know I'm on my own :) .
I'll try to figure it out and report back if I can find it .
I'll probably start by checking resistor values .

Anyone else had this behaviour ... feel free to give me hint .
I did modify the backlight pins as suggested , and that makes the backlight turn off when the screensaver kicks in .
But offcourse , it doen nothing to the button problem .

I wouldn't mind buying the freetronics display shield , but the shipping cost is outrageous .
It cost more for shipping it then the actual price .

Pat
 
Hi Pat
do you mean you changed the backlight pin assignment from 3 to 10 as explained here ?
That was all I needed to do to get the Sainsmart shield to work. I also tried a DFRobot shield and could not get it to work. It was awhile ago but I think I remember googleing the difference between the two and think it is fixable. I think.
The Sainsmarts do work.

Scott
 
Yes , the backlight pin from 3 to 10 does what it should .

As for the shield itself , looking at the schematics , both sainsmart and freetronics
use thesame resistor values for the buttons . 2K ; 330E ; 620E ; 1K ; and 3K3 .
But the dfRobot uses a 2K2 resistor instead of a 2K . That is the cause of the problem .
For now I soldered a 22K in parallel to the 2K2 , wich results in a value of 2K .

That makes my "left" and "select" buttons operational .
Most lilely it's all it takes .
I'm sure it can also be solved in software , but I'm not good with software .

Trying to figure out the menu structure now , and wich button does what .

I'll post a picture and "schematic" when I'm sure it works .

Pat
 
As promised I report back here with my findings .
I had to make a small modification to the df Robot shield to make it freetronics/sainsmart compatible .

Basicly what happend is that the designers of the freetronics display shield used a non common resistor .
2K . No that uncommon , but the std value is 2K2 .
IMG-20060402-00190.jpg

The df robot shield designers decided probably to save a few pennies and used a std 2K2 resistor instead .
Remember , this is a 3$ shield , s&h included . I'll never understand how they are able to build it
at that price .
No problem really , it still works , and various test sketches read the buttons correctly .
However the different resistor throws the two lower voltages off just enough for Rod's sketch not to recognise them .
I fixed it by adding a 22K resistor in parallel to the 2K2 resistor wich results in a 2K value .
This makes all the buttons function as they should .
The resistors are hidden inder the lcd , you can't see them in t he picture .
Just above the RST button , you can see the 22K I added .


This also can be solved in software . At least it should be .
I can calculate the voltages for each button , and even the expected ADC counts both with a 2K or with a 2K2 resistor .
And then it should be just a couple of numers somewhere need to be changed .

I think it's the piece of code copied below that reads and maps the buttons .
Copied it from the lcd.cpp wich is in the library .
But I just can't understand how it works . Maybe someone who does could explain it to me .

It's academic , I'll most likely build a custom display shield with a much larger lcd , and offcourse I'll use the correct
resistors there . But still , I like to learn things and understand what I'm doing .


Pat



// Button mapping table generated by genlookup.c
static unsigned char const buttonMappings[] PROGMEM = {
2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
};
#define mapButton(value) (pgm_read_byte(&(buttonMappings[(value) >> 5])))

/**
* \brief Gets the next button press, release, or idle event.
*
* If no buttons are pressed, this function will return LCD_BUTTON_NONE.
*
* When a button is pressed, this function will return one of
* LCD_BUTTON_LEFT, LCD_BUTTON_RIGHT, LCD_BUTTON_UP, LCD_BUTTON_DOWN,
* or LCD_BUTTON_SELECT. While the button is pressed, this function
* will return LCD_BUTTON_NONE until the button is released. When the
* button is released, this function will return one of
* LCD_BUTTON_LEFT_RELEASED, LCD_BUTTON_RIGHT_RELEASED,
* LCD_BUTTON_UP_RELEAED, LCD_BUTTON_DOWN_RELEASED,
* or LCD_BUTTON_SELECT_RELEASED.
 
Sorry, its been quite a while since I've been on this forum and missed the last couple of posts. Anatol, thank you very much for your compliment and additional descriptions.

For others like Shehan Perra, I don't know how many times I have said that the Arduino is not Plug and Play, The required hardware is listed. If you choose to use some other hardware, then you are on your own. Don't ask me for help.

If you don't know how to modify the code (and the answer is on this forum), then buy the required hardware or find another simpler script. This script uses advanced high performance code that works. Its well written and documented in the source. Its not really a beginner Arduino project as it pushes the limits of the Arduino.

I've been away from this forum for years what with life and all. I came back because I recalled this project and wanted to move from a simple stepping collet chuck to a rotary table design.

Great work Rod making this available to people. I sure appreciate your efforts.
 
Welcome back John. I must say I'm a bit the same. I've migrated to Linuxcnc
 
Welcome back John. I must say I'm a bit the same. I've migrated to Linuxcnc
Nice, one of my bucketlist items is to build a cnc router and I did download and play with cnc software, but the laptop I had it on went kaput.

Am I correct to suppose that linuxcnc can be used to control single axis items like rotary table, or even just to control travel on a table that has a stepper motor attached?
 
Yes, I'm going to use language based on the latest development branch of Linuxcnc as its changed a bit from the current release. Linuxcnc can support up to 9 joints (or motors) and these are mapped to axes. It is possible to map 2 or more joints to the one axis so they work in unison (as per a gantry on your router) and the homing sequence will square the gantry. It is possible to control a one axis machine without resorting to go code. Today, I've just installed a version of Linuxcnc on my windows machine using Virtualbox. This won't work to drive a real machine but it does allw you to run all of the supplied simulations which are useful for development
 
I ran it. working fine. however, the jog mode does not return a different direction. There is a nuisance in the code.

Can you review it and publish it. I thank you.
 
I ran it. working fine. however, the jog mode does not return a different direction. There is a nuisance in the code.

Can you review it and publish it. I thank you.

Please read the hardware dependencies in the first post. Your keyboard hardware is different to what I used and the Arduino environment is not plug and play. Others have worked around the problem.
 
Rod,
My name is Scott and I have been following this post for quite a while. Thank you for all of the time and effort you have put into this project. I have finally collected all of the parts I need to make this work for my application. I plan on using a Hass 5c collet stepper indexing head for use on my cnc mill. I have got the Hass head to index like it should and it works great. I now just need to figure out how to interface it to my cnc mill. It is a VMC with a fanuc control. I plan on doing the same thing as Scott did by using a remote switch to index the head. I have some available M codes I can use on my machine to call for the arduino to make the step move. The problem I have is that when I request an m40 code in the g code The cnc will activate a relay which will simulate a right button push. That m40 relay then stays active until the cnc gets a signal to de activate m40. The machine will not progress with nc code until this condition is met. I have looked though your code and I have not found what looks like a finish movement signal. If I can capture that signal and activate a relay to end m40 that will let the nc code continue. I would appreciate if you could point me in the right direction and maybe give me a little help with the code part of it. I am not super savvy on the arduino side of things. It could be as simple as a potentiometer going to an analog input that changes the length of time before the arduino activates a pulse to de activate the M40 code. I think that you would want to use interrupts to time this so that the processor is not counting and waiting for that time period. I would appreciate any help you can give me
Thanks
Scott
 
Back
Top