Project of the Month built by SilverSanJuan
Home Model Engine Machinist > CNC and 3-D Printers > Software and Programming > Tips for Arduno software for Rotary Table Controllers

Reply
 
Thread Tools
Old 10-31-2016, 10:06 PM   #251
Foozer
HMEM_LIFETIMESUPPORTER.png
 
Join Date: Nov 2008
Location: Camano Island, WA
Posts: 1,088
Liked 64 Times on 60 Posts
Likes Given: 2

Default

Quote:
Originally Posted by rodw View Post
But if you are changing the direction value on the wrong port, it will be permanently stuck in either forward or reverse motion.
Time to hook up my little cigar box stepper test and load your program

if (setupForm.isCurrent(sDirPinField)) {
globals.DirPin = sDirPinField.value();

input value from sDirPinField becomes DirPin [High, Low] value becomes actual direction ? - - Oh Boy . . .


__________________
"Nothing is more irritating than that which exposes the pedigree of ideas"----Lord Acton----
Foozer is offline  
 
Reply With Quote
Old 11-01-2016, 10:45 AM   #252
markcadcam
 
Join Date: Dec 2012
Posts: 3
Liked 1 Times on 1 Posts

Default

RodW

I got my controller configured and everything works fine now. Thanks for your help and your great program.

Mark


markcadcam is offline  
rodw Likes This 
Reply With Quote
Old 11-01-2016, 10:47 AM   #253
rodw
 
Join Date: Dec 2012
Posts: 1,009
Liked 300 Times on 235 Posts
Likes Given: 155

Default

Quote:
Originally Posted by Foozer View Post
Time to hook up my little cigar box stepper test and load your program

if (setupForm.isCurrent(sDirPinField)) {
globals.DirPin = sDirPinField.value();

input value from sDirPinField becomes DirPin [High, Low] value becomes actual direction ? - - Oh Boy . . .
Long time since I've looked at this code. What you are looking at is code using the 3rd party LCD class that drives the menus and data entry in one of the libraries. Classes are part of C++ and did not exist in the original C language.

So if the current field being edited is the direction pin field, get the value from the LCD class and store it in the globals structure. LOW and HIGH are defines in the Arduino and are the same as TRUE and FALSE which is a fancy way of saying 1 or 0.

So now we know the pin to write direction to. All globals are stored in a structure so it is super simple to read and write them all to the EEPROM.

So in a rotary table, we are interested in moving CLOCKWISE or ANTICLOCKWISE which are DEFINED to be LOW and HIGH. Different tables may have a different default rotation direction so we can change the definition around by swapping the CLOCKWISE/ANTICLOCKWISE LOW and HIGH defines.

So in theory the code should become more readable even if it is compact and efficient as there is no room for verbose code!

So Foozer, finally, the last procedure in the file is the actual timer interrupt service routine (ISR). It is attached in the setup routine and taken from the default setup in Hz. THe trick here is that a Hz is one cycle per second so that implies 2 passes through the ISR, one for off and one for on. Thats why i have some conversion routines as it makes more sense to configure a stepper motor in Hz as this is how the data sheet is written.

Here endeth the lesson. Good luck!
__________________
RodW
Brisbane, Australia
vehiclemods.net.au
rodw is offline  
 
Reply With Quote
Old 11-01-2016, 10:55 AM   #254
rodw
 
Join Date: Dec 2012
Posts: 1,009
Liked 300 Times on 235 Posts
Likes Given: 155

Default

Quote:
Originally Posted by markcadcam View Post
RodW

I got my controller configured and everything works fine now. Thanks for your help and your great program.

Mark
Glad you got it going. I was thinking that if you compiled and ran the default program, the EEPROM would be overwritten with the default data. If you subsequently edited the globals in the code and recompiled, the EEPROM data did not get overwritten. Because the data existed in EEPROM, it would be retrieved and stored over the top of your globals data.
__________________
RodW
Brisbane, Australia
vehiclemods.net.au
rodw is offline  
 
Reply With Quote
Old 11-01-2016, 05:35 PM   #255
Foozer
HMEM_LIFETIMESUPPORTER.png
 
Join Date: Nov 2008
Location: Camano Island, WA
Posts: 1,088
Liked 64 Times on 60 Posts
Likes Given: 2

Default

Quote:
Originally Posted by rodw View Post

So in theory the code should become more readable even if it is compact and efficient as there is no room for verbose code!

So Foozer, finally, the last procedure in the file is the actual timer interrupt service routine (ISR).

Here endeth the lesson. Good luck!
Got it, naw I don't, but it's percolating . .

Didn't like having to write over and over the stepper commands in the script so wouldn't exactly call it a library but made a cpp to hold the blash blah blah then in script one line does it
Stepper.CW(dirR,stepR,rateR);
Stepper.CCW(dirR,stepR,rateR);

void StepperXY::CW(int pin1, int pin2, int pin3) // pin1 dir, pin2 step, pin3 rate microseconds
{
pinMode(pin1, OUTPUT); // dir
pinMode(pin2, OUTPUT); // step
digitalWrite(pin1, HIGH); // CW
delayMicroseconds(5);
if (digitalRead(pin1) == HIGH) // probably not needed
{
digitalWrite(pin2, !digitalRead(pin2));
delayMicroseconds(pin3);
}
}

It's always fun to learn something new, just keep the aspirin coming .
__________________
"Nothing is more irritating than that which exposes the pedigree of ideas"----Lord Acton----
Foozer is offline  
rodw Likes This 
Reply With Quote
Old 11-02-2016, 12:08 PM   #256
rodw
 
Join Date: Dec 2012
Posts: 1,009
Liked 300 Times on 235 Posts
Likes Given: 155

Default

Quote:
Originally Posted by Foozer View Post
Got it, naw I don't, but it's percolating . .

It's always fun to learn something new, just keep the aspirin coming .
I try and avoid using delay() as it locks the Arduino to see whats going on. Here's how I did it after displaying the welcome screen while still servicing the keyboard.

Code:
   while(1){  // Delay 2 seconds without using delay();
     currentMillis = millis();
     if(currentMillis - previousMillis > interval) {
        previousMillis = currentMillis;
        break;  
     }
     event = lcd.getButton();
   }
Rolling right back to Version 2 of my script, you can do it with interrupts in 200 lines of code. Still uses the LCD library. I think V1 had about 150 lines of code to prove the interrupt approach would work.

This simpler example will make it much easier to learn whats going on. Here's the minimalist ISR routine. In the ZIP file it still includes the original sample code to flash the LED so I knew what was going on but I've removed that below as its a distraction.

Code:
void timerIsr()
{
    // Toggle LED
  if(steps){
      state = state ^ 1;
      digitalWrite( stepPin, state );
      steps--;
  }
So for each alternate call to the ISR, we need to swap between LOW or HIGH to make the stepper move. We do that with the state variable
Code:
state = state ^ 1;
This line does a Bitwise XOR (Exclusive OR) with 1
so:
0 XOR 1 = 1 and
1 XOR 1 = 0

which is a lot simpler (and faster) than
Code:
if(state ==1) 
   state = 0
else 
   state = 1;
Remember, speed is king in the ISR!
Attached Files
File Type: zip RotaryTableChuck2.zip (1.7 KB, 114 views)
__________________
RodW
Brisbane, Australia
vehiclemods.net.au
rodw is offline  
 
Reply With Quote
Old 11-02-2016, 05:02 PM   #257
Foozer
HMEM_LIFETIMESUPPORTER.png
 
Join Date: Nov 2008
Location: Camano Island, WA
Posts: 1,088
Liked 64 Times on 60 Posts
Likes Given: 2

Default

Quote:
Originally Posted by rodw View Post
I try and avoid using delay() as it locks the Arduino to see whats going on. Remember, speed is king in the ISR!
Getting dark earlier so it's time to look back into interrupts . .
Oh ya - Your program works on my little cigar box stepper test platform - Had to get the values from freetronics and rig up the voltage divide for the buttons - Turn it on, push some buttons and away it goes . . .

I know i'm missing something - if I run
for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, !digitalRead(thisPin));
delayMicroseconds(600);
)
It's only 1/2 revolution whereas

for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, LOW);
delayMicroseconds(600);
digitalWrite(thisPin, HIGH);
delayMicroseconds(600);
}
is a full turn - But what it is I don't see . . .
__________________
"Nothing is more irritating than that which exposes the pedigree of ideas"----Lord Acton----
Foozer is offline  
 
Reply With Quote
Old 11-03-2016, 11:30 AM   #258
rodw
 
Join Date: Dec 2012
Posts: 1,009
Liked 300 Times on 235 Posts
Likes Given: 155

Default

Quote:
Originally Posted by Foozer View Post
Getting dark earlier so it's time to look back into interrupts . .
Oh ya - Your program works on my little cigar box stepper test platform - Had to get the values from freetronics and rig up the voltage divide for the buttons - Turn it on, push some buttons and away it goes . . .

I know i'm missing something - if I run
for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, !digitalRead(thisPin));
delayMicroseconds(600);
)
It's only 1/2 revolution whereas

for(int jog; jog<400; jog++); // 400 steps per rev
{
digitalWrite(thisPin, LOW);
delayMicroseconds(600);
digitalWrite(thisPin, HIGH);
delayMicroseconds(600);
}
is a full turn - But what it is I don't see . . .
Because the first example writes to the stepper pin half as often as the second.

Eg first loop has 1 x digitalWrite (either on or off each iteration)
second loop has 2 x digitalWrites (both on and off each iteration)

Good luck with it.
__________________
RodW
Brisbane, Australia
vehiclemods.net.au
rodw is offline  
 
Reply With Quote
Old 04-19-2017, 06:36 PM   #259
Maxmekker50
 
Maxmekker50's Avatar
 
Join Date: Apr 2017
Location: Norway
Posts: 3
Liked 3 Times on 1 Posts
Likes Given: 28

Default

Hello In all, Fight Contributions I am quite dull What you can

I Need Help An Old Norwegian, I Have a rotary table Ratation 1:72 Having read through the forum for a few days now, Don mostly but not the relationship between 1:72 ratation And Nema motor 23 looks we are talking about 200 step 400 step . Can anyone help me What motor should I buy and possibly how to change code in arduino ?? I have all the parts in place but can not find this out with engine and ratation, HAS TB6560 3A stepper motor driver that I thought I'd use. If eny have the file for 1:72 ratation and can giwe me Tips which motor to use , I can do it *_*

Thanks All
And I am very grateful for the help here

Call me a dummy but at this trips I checkmate
Maxmekker50 is offline  
 
Reply With Quote
Old 04-20-2017, 06:14 AM   #260
rodw
 
Join Date: Dec 2012
Posts: 1,009
Liked 300 Times on 235 Posts
Likes Given: 155

Default

If you go.to this thread
http://www.homemodelenginemachinist....ad.php?t=25091

, the installation is set out step by step. Pretty much any NEMA23 will have enough power to turn a rotary table.provided.if has enough volts. I found 19v was not enough and went to 48v. Most steppers are 200 steps per rev. I get my steppers from steppersonline who I think have an .eu site. Is get a 4 wire 2.8 amp stepper with your controller

Once the software is installed, go to the setup menu to set the software.to agree with your Arduino pins etc.


__________________
RodW
Brisbane, Australia
vehiclemods.net.au
rodw is offline  
 
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotary Table Fix cfellows Tools 12 08-13-2013 06:09 PM
Rotary Table -- What Do I Need To Know? Jeremy_BP Tools 10 01-17-2012 02:42 PM
Rotary table for my X2 tmuir Tools 16 02-03-2010 09:40 AM
X2 table dissassembly tips wanted tmuir General Engine Discussion 3 05-14-2009 11:43 PM
Rotary table Julian Tips and Tricks 3 11-04-2007 07:01 PM



Newest Threads






- Top - Member List