Tips for Arduno software for Rotary Table Controllers

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 RodW, I am still having trouble with speed control in V7, as I did in V5. I am running V4 and V5 with all "Speed set" commented out and speed set TIMER_DELAY =100 in place of 80 and my Nema 17 is happy there. Keep up the great work.

I also had to add the version number in the splash screen to keep track of witch version I am playing with. Had them all up at one time and got corn fused. Thanks, Carl
 
Hi Rod
I had some time to play with V7, wow that is a bunch of code ! And most of it is way over my head :( The previous versions I could mostly understand. Very impressive coding my friend.
I just hooked up to a stepper on my bench. The ramp up and down is very nice. I was able to run this nema 34 motor at 16000 max.
I did notice some odd behavior with go to home, I set home and then bumped a few steps (3) with the right button and then went back and went to "Go Home" and it continued in the same direction a few more steps and stopped. I am guessing about 7-8 steps from home. I tried a few other things with continuous turn a step but it seemed confused where home was.
Everything else seemed to work well. I may have time to hook it back up to my machine this weekend.

Here is a thought.. Would it be possible to control speed with a potentiometer ? I am pretty sure we have some analog pins free. That might make a nice feature. The pot min max would be what was used in setup.

Thanks again for all your hard work !!

Scott
 
Hi RodW, I am still having trouble with speed control in V7, as I did in V5. I am running V4 and V5 with all "Speed set" commented out and speed set TIMER_DELAY =100 in place of 80 and my Nema 17 is happy there. Keep up the great work.

I also had to add the version number in the splash screen to keep track of witch version I am playing with. Had them all up at one time and got corn fused. Thanks, Carl

Great you have it going on your NEMA17. I would have thought V7 would let you sort the speed out from the Config menu. by increasing TIMER_DELAY, you are decreasing the stepper frequency. From memory, 80 is 6250 Hz so you need to take that down by 20%. I'd try the max freq at about 4000 and see how you go.

The version is a great idea. It keeps a 3 char signature internally in the EEPROM so it knows if there is any data stored or not. I should add an extra field for version number.

I'm now writing the device number on the start up screen. :)
I've added code to create and add devices but need to add the select device code.

Hi Rod
I had some time to play with V7, wow that is a bunch of code ! And most of it is way over my head :( The previous versions I could mostly understand. Very impressive coding my friend.
I just hooked up to a stepper on my bench. The ramp up and down is very nice. I was able to run this nema 34 motor at 16000 max.
I did notice some odd behavior with go to home, I set home and then bumped a few steps (3) with the right button and then went back and went to "Go Home" and it continued in the same direction a few more steps and stopped. I am guessing about 7-8 steps from home. I tried a few other things with continuous turn a step but it seemed confused where home was.
Everything else seemed to work well. I may have time to hook it back up to my machine this weekend.

Here is a thought.. Would it be possible to control speed with a potentiometer ? I am pretty sure we have some analog pins free. That might make a nice feature. The pot min max would be what was used in setup.

Thanks again for all your hard work !!

Scott

Scott, thanks for the feedback. It will inspire me to keep going! Hard to think the <200 lines of code I started with is now pushing 1000...

I think I will reenable the speed control in 5% increment between maxHz and minHz but not save it in eeprom which will give temporary control of speed that is wiped out on a reboot. If there is a speed you particularly like, you will be able to save the settings to EEProm as a separate device and retrieve it later.

A knob for speed control is a good idea. Not sure if it should be a pot or a rotary encoder though. The encoder could work just as the speed control is described above. a Pot might require calibration.

And most of it is way over my head :(
kinda over mine too! heaps of trial and error.

When the stepper goes LOW, that is the end of a complete cycle (Hz) so thats when we change the speed.

When we want to move a given number of steps, We calculate the max and min timer delay
Then the number of frequency changes (in timer delay steps - microseconds) are calculated to go from the minimum frequency to the maximum frequency.
If there are not enough steps to go right up and then right back down, this number is altered to a lower number so the ramp up and ramp down fits to the available steps and the operating speed will not reach max Hz.

It then calculates pointers to endRampUp and StartRampDown.
The #steps is decremented so endRampUp is a big number
so we start at min Hz and go up 1 delay setting on each step until we reach endRampUp, we go along at max speed until we get to StartRampDwn at which time we start slowing down. In theory, we should hit the minimum speed on the last step.

I did notice some odd behavior with go to home, I set home and then bumped a few steps (3) with the right button and then went back and went to "Go Home" and it continued in the same direction a few more steps and stopped. I am guessing about 7-8 steps from home. I tried a few other things with continuous turn a step but it seemed confused where home was.
Scott, I did notice some issues with Home and will review it when I finish my changes and get it back on the rotary table. I am not sure if we are missing steps in the hardware or it is my code. The home tracking has not changed..

The other bug is that on continuous turning and continuous jogging, the rampdown when your finger off starts at max frequency, not the current frequency so that if it is turning very slowly, it will instantly leap to full speed, then ramp down. If you have a reasonable min Hz (say 1000), the operating speed is reached quickly and not an issue but if you set min Hz to say 400, it is noticeable...
 
Hi RodW, I am still having trouble with speed control in V7, as I did in V5. I am running V4 and V5 with all "Speed set" commented out and speed set TIMER_DELAY =100 in place of 80 and my Nema 17 is happy there. Keep up the great work.

I also had to add the version number in the splash screen to keep track of witch version I am playing with. Had them all up at one time and got corn fused. Thanks, Carl

Carl, to convert TIMER_DELAY to Hz it works like this.
There are 1,000,000 microseconds per second. Thats how any times a second the timer interrupt is triggered.

But there are 2 pulses per stepper step (on and off) and a Herz measures cycles per second so the maximum frequency the Arduino can generate is 500,000 Hz (1,000,000/2)

So with a TIMER_DELAY of 100 you are running at 5,000 Hz (500,000/100)

You know your stepper will operate at 5,000 Hz so start by trying say Min Hz of 4000 and max Hz of 5000. if no good, try 5000 and 5500 or 4500 and 5500. Once you get it started, I'd reduce the min Hz until you get a reasonable ramp up period and then try increasing max Hz

Steppers have lower torque at lower speeds so the idea is to start slow to overcome inertia.
 
Hay Rod. In V7, I also noticed the when using Jog the stepper would keep going for some time and then go slowly a few more motor turns after button release befor stoping. I would think that in Jog mode it should stop when you release the button like in V4 and V5.

In Speed Set, the speed didn't increase much when trying to go faster and would slow down about half after a few cycles.

THe reason I needed to change the delay in speed set was because the stepper would "Lock up" when almost top speed was reached. By slowing it down to 100 from 80 the motor didn't stall or "Lock up". It would lock up at 95 but not at 100 so I went with 105 . Carl
 
I can see the home problem. At the very bottom of the code in the timerIsr ISR service routine, we are not maintaining the current direction anywhere as we are setting it directly throughout the code like this

Code:
 digitalWrite( globals.DirPin, ANTICLOCKWISE );

We never really know which direction we are travelling. We should be reading the direction pin in the ISR so we can't get it wrong!

Here is the fix. At the very bottom of the code in the timerIsr ISR service routine (about 12 lines from the end of the file), where it says this:

Code:
      steps--;
      if(!goinghome){
          if(globals.dir == CLOCKWISE){
             homePos++;

Change
Code:
          if(globals.dir == CLOCKWISE){

To
Code:
          if(digitalRead(globals.DirPin) == CLOCKWISE ){

we don't need to keep the direction in a variable as the hardware port does it for us!

Let me know if this fixes it.
 
Finally got this back in the shed on my rotary table. The Home code above fixed half of the problem Literally! I ended up with 2 home positions each 180 degrees apart.

I went and mowed the lawn and it dawned on me that I must not have allowed for both sides (on and off) of a stepper pulse so I was only moving half a circle.

Anyway, I have fixed this now and added all of my eeprom features (load device, add device and select device. By my calculations the UNO has enough EEPROM storage to store up to 53 devices.

Hay Rod. In V7, I also noticed the when using Jog the stepper would keep going for some time and then go slowly a few more motor turns after button release befor stoping. I would think that in Jog mode it should stop when you release the button like in V4 and V5.

In Speed Set, the speed didn't increase much when trying to go faster and would slow down about half after a few cycles.

THe reason I needed to change the delay in speed set was because the stepper would "Lock up" when almost top speed was reached. By slowing it down to 100 from 80 the motor didn't stall or "Lock up". It would lock up at 95 but not at 100 so I went with 105 . Carl


Carl, It sounds like you have not found the Setup menu that lets you change the speed settings and ports etc without changing any #defines in software code to configure the controller.

the reason why the system runs on is that the stepper winds down so the inertia of the table could push it on a step or 2. The default settings have too big a gap between the starting frequency and the maximum frequency so the ramp up and down takes too long.

Now that I've had more of a play, I found that a minimum frequency for my smallish NEMA 23 need to be around 5,000 Hz This will mean the ramp down is short and almost instantaneous.

So I have set my my Min stepper Hz to 5,000 and the Max Stepper Hz to 10,000 and it runs nice 60% faster than when I was just using a fixed timer frequency. Try those settings and see how you go. If you miss steps, alter the settings.

You will need to get your head around the frequency settings and forget totally about the timer delay setting as the next version will not have a Timer Delay setting at all.
 
Version 8 is here!

Massive changes and this I think is the final feature set, memory is going to get very tight..

Hopefully all bugs are squashed.
The menu has changed a bit and all settings are now in the Config Menu so the main menu now contains:
<Divide #>, <Divide Angle>, <Jog>, <Home>, <Contin Turn>, <Config>

The Config Menu contains:
<Set Speed>, <Jog Step>, <Setup>, <Devices>

<Set Speed> and <Jog Step> make temporary changes to the Jog Step and Max Stepper HZ which will be lost on reboot unless you go into setup and Save it.

Followers will be pleased to know the <Set Speed> menu has been reinstated.

<Devices> menu has 3 options
Load Device, New Device, Erase Devices

New Device and Erase Devices are Yes/No options

Erase clears the EEPROM (well changes the first 3 bytes so it thinks it is empty,

New Device makes a new device in memory and installs it.

Load Device allows you to select a device using up and down arrows. First device is numbered 0 (Thats how C works). There is enough memory for 53 devices but you'll have to remember which number is what.

Software version and current device are displayed on startup.

View attachment RotaryTableChuck8.zip
 
Version 8 now attached to the previous post
 
Oops,

The set speed code is wrong. Replace the setSpeed() procedure with this code:

Code:
void setSpeed(int spdPct)
{
  long newspeed;
  long mindelay =  HzToTimeDelay(Operating_Hz); 
  long maxdelay =  HzToTimeDelay(globals.minStepperHz);

  long DelayRangeHz = Operating_Hz-globals.minStepperHz;
  float changeRatio = (float)spdPct/100.0;
  long offset = (long)((float)DelayRangeHz * changeRatio);
  if(spdPct == 100)                          // Override the calculations ere so 100% is the max frequency
      newspeed = Operating_Hz; 
  else
      newspeed = globals.minStepperHz + offset;
  globals.timerDelay = HzToTimeDelay(newspeed);             // save globally
  globals.maxStepperHz = newspeed;

  Timer1.setPeriod(globals.timerDelay);      // set a timer of length in microseconds
}

I've reworked this to do the maths on the frequency instead of the timer delay. This has made it more accurate as well as I'm using much bigger numbers.

Just remember that the % is based on the speed range (between max Hz and Min Hz and this is then added to the Min Hz so it is not 90% of 10000 hz which you might expect on first glance. it is:
(maxHz - MinHz) * 90% + MinHz

This means a speed of 0% is valid and will run at the lowest speed you have set in config for Min Hz.

You can check the speeds in the Setup
 
Version 8 now attached to the previous post

Wow Rod, fantastic work! Thank you so very much.

I hope that it's going to be easy enough for me to figure out how to modify for 4x20 IC2 display and to add code to display the stepper motor current on the 3rd or fourth line of the display
 
Wow Rod, fantastic work! Thank you so very much.

I hope that it's going to be easy enough for me to figure out how to modify for 4x20 IC2 display and to add code to display the stepper motor current on the 3rd or fourth line of the display

I can't see it will be too much of a drama. Files to work with are LCD.h and LCD.cpp in the library and the LiquidCrystal files in the Utilities folder.

LCD.cpp has this code
Code:
void LCD::init()
{
    // The Freetronics display is 16x2.
    begin(16, 2);
You just need to insert your version of the Liquidcrystal files. I think this page will guide you

https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
 
Ok Rod, I now have my RT working with the nema 17. At this time I am still using V5 and had to make some tweaks. How ever it is running very smooth. I am getting 9 degs per second and that is faster then ChuckF's sketch would run. I am running nema 17 70 oz. three to one reduction with timing pulleys into a 90 turn 8 inch table. I had to tell the program that my stepper needed 600 steps per turn but that fell a few degrees short so I ended up using 640 steps per turn and after about 10 full revolutions it was spot on. I also had to slow the stepper down to pervert missed steps. I am running a DVR 8825 driver at just over one amp and only 12 volts from an ATX power supply. I know more voltage would run faster but I don't need any more speed. I will keep working on V8. How ever, I have played with these programs so much my buttons are starting to fail. LOL Might have to replace some of them. I need to find the correct diagram for the voltage divider so I can make a switch panel. Now to make the enclosure. Thanks again, Carl
 
Ok Rod, I now have my RT working with the nema 17. At this time I am still using V5 and had to make some tweaks. How ever it is running very smooth. I am getting 9 degs per second and that is faster then ChuckF's sketch would run. I am running nema 17 70 oz. three to one reduction with timing pulleys into a 90 turn 8 inch table. I had to tell the program that my stepper needed 600 steps per turn but that fell a few degrees short so I ended up using 640 steps per turn and after about 10 full revolutions it was spot on. I also had to slow the stepper down to pervert missed steps. I am running a DVR 8825 driver at just over one amp and only 12 volts from an ATX power supply. I know more voltage would run faster but I don't need any more speed. I will keep working on V8. How ever, I have played with these programs so much my buttons are starting to fail. LOL Might have to replace some of them. I need to find the correct diagram for the voltage divider so I can make a switch panel. Now to make the enclosure. Thanks again, Carl

I know the feeling re fingers..and I had to buy a new lcd shield myself.

The circuit diagram for the keyboard is here http://www.freetronics.com.au/pages/16x2-lcd-shield-quickstart-guide

And of course, I found some bugs so here is V9. No new functionality, just cleaned up and a bit of a memory cleanup as I could not load devices in Version 8. Also the go home seemed to get confused on continuous turning if you chopped and changed direction. I think that was also related to lack of memory.

Try it. Just compile it as is and then go to <config> / <setup> and set the pins and parameters to suit you. There are 3 numbers to change the ratios
M/Steps: if you are microstepping
Div ratio: this will be 270:1 for you
Stepr Steps/rev: 1.8 degrees stepper is usually 200

Then set the min Hz to 5000 and max Hz to say 5500

Once you are happy, say Yes to Save?, reboot and check the settings are saved.

EDIT:For some reason, I can't edit Post #1 with thislink but version 10 is here http://www.homemodelenginemachinist.com/showpost.php?p=263734&postcount=188

View attachment RotaryTableChuck9.zip
 
Try it. Just compile it as is and then go to <config> / <setup> and set the pins and parameters to suit you. There are 3 numbers to change the ratios
M/Steps: if you are microstepping
Div ratio: this will be 270:1 for you
Stepr Steps/rev: 1.8 degrees stepper is usually 200

Then set the min Hz to 5000 and max Hz to say 5500

Once you are happy, say Yes to Save?, reboot and check the settings are saved.

Carl on second thoughts for you, I think you need to set the
M/Steps: = 1 - no microstepping
Div ratio: = 90
Stepr Steps/rev: = 640
 
Carl on second thoughts for you, I think you need to set the
M/Steps: = 1 - no microstepping
Div ratio: = 90
Stepr Steps/rev: = 640
Rod, I am trying V9 and have it MOSTLY working but I still have a problem with speed control. Some kind of bug? I have divisions set to 4 and watch turn table move 90 degs. No problem Always turns 90 degs. Ramp up is for the first 3 degs of turn and ramp down is the last 3 degs. No problem. But, the top speed is fast for the first three movements. 3 times 90 degs, about 10 degs per second, then the speed halves for all future moves to about 5 degs per seconds. Reboot and speed set made no different. Three times full speed then drops to about half. I had similar speed problems in earlier versions. What's up with that? Carl

PS Yes I am saving setting by using yes in save settings.
 
Rod, I am trying V9 and have it MOSTLY working but I still have a problem with speed control. Some kind of bug? I have divisions set to 4 and watch turn table move 90 degs. No problem Always turns 90 degs. Ramp up is for the first 3 degs of turn and ramp down is the last 3 degs. No problem. But, the top speed is fast for the first three movements. 3 times 90 degs, about 10 degs per second, then the speed halves for all future moves to about 5 degs per seconds. Reboot and speed set made no different. Three times full speed then drops to about half. I had similar speed problems in earlier versions. What's up with that? Carl

PS Yes I am saving setting by using yes in save settings.

Carl, cool you have got it mostly working. After division 4 go into setup and see if Max Hz has changed. Then reboot and see what it is.

I'll try and replicate it. It is possible we are running out of memory. I found the latest version of the IDE cut smaller code.

Either that or the marker to set the end of ramp up and start of rampdown is notgetting set correctly.
 
Carl, cool you have got it mostly working. After division 4 go into setup and see if Max Hz has changed. Then reboot and see what it is.

I'll try and replicate it. It is possible we are running out of memory. I found the latest version of the IDE cut smaller code.

Either that or the marker to set the end of ramp up and start of rampdown is not getting set correctly.

Carl, I just went out and did well over 20 x 90 degree divisions with a digital tacho on the stepper shaft and the speed was constant at 300 rpm. I think your problems will be memory related as I had problems with continuous turning which went away when I shortened some of the prompts.. Have a look at the first post where I talk about this and then see what your results are and post up your compiler message. I'll check mine and we can compare.
 
Here's what I mean.
Code:
Sketch uses 24,412 bytes (75%) of program storage space. Maximum is 32,256 bytes.
Global variables use 900 bytes (43%) of dynamic memory, leaving 1,148 bytes for local variables. Maximum is 2,048 bytes.


This is the critical part
Code:
 leaving 1,148 bytes for local variables.

If when running this memory runs out crazy things start happening.

If your number is smaller, chances are this is the problem

Try commenting out the setup routine with a /* and */ immediately after the first brace and immediately before the last brace like this.

Code:
void doSetupMenu(void)
{
/*  
  Form setupForm(lcd);
  int saveSetup = false;
.
.
.
  if(saveSetup){
    int retval = putGlobals();
  }
*/
}

This will save a lot of memory (100 bytes for me).
Code:
leaving 1,246 bytes for local variables.
If it works then we know its memory related.
 

Latest posts

Back
Top