0

How to get around stepper topping out at 32767?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How to get around stepper topping out at 32767?

by Berniepfei on Tue Dec 18, 2018 11:02 pm

Ok I have a wire feeder that I have been using that's working well but has a weird limitation that when I set the steps above 32767 it just keeps going and never stops. anything under that it works fine. Apparently that's the max of int in stepper library.
Id like to get it to feed much longer lengths if I could. Like up to 10 or 12 feet. With the current drive wheel I can only get about 25 inches. I don't want to go larger or I lose torque and start to get feed problems if the spool binds.
I wondered if I should try and figure out how to just repeat shorter lengths multiple times until I get to the desired length but not sure how to proceed with that.
Thanks everyone for at least getting me to this point.

Aruduino Uno
Nema 17 stepper
TB6600 type stepper driver.

Code: Select all | TOGGLE FULL SIZE
#include <Pushbutton.h>

int led = 12;
int PUL=7; //define Pulse pin   //stepper driver setup
int DIR=6; //define Direction pin   
int ENA=5; //define Enable Pin


#define BUTTON_PIN 10
Pushbutton button(BUTTON_PIN);
void setup()
{
pinMode(9,INPUT_PULLUP);
  pinMode(10,INPUT_PULLUP);
  pinMode(led, OUTPUT);
  pinMode (PUL, OUTPUT);
  pinMode (DIR, OUTPUT);
  pinMode (ENA, OUTPUT);
  pinMode(led, OUTPUT);
 
}

void loop()
{
  while (!button.isPressed());  // wait for button to be pressed
 
  delay(500); //  and debounce the button press
 
 
  for (int i=0; i<32767; i++)    //  32767max 25iinches 6400 1rev. 3500 short wire.   8500long wire
 
  {
    digitalWrite(DIR,HIGH);
    digitalWrite(ENA,HIGH);
    digitalWrite(PUL,HIGH);
    delayMicroseconds(75);
    digitalWrite(PUL,LOW);
    delayMicroseconds(75);
  }
   
delay(500);
  digitalWrite(led, HIGH);   // air on (HIGH is the voltage level)
  delay(550);               // wait
  digitalWrite(led, LOW);    // air off by making the voltage LOW
  delay(100);               // wait for a second
}

Berniepfei
 
Posts: 10
Joined: Sat Apr 29, 2017 11:31 pm

Re: How to get around stepper topping out at 32767?

by adafruit_support_bill on Wed Dec 19, 2018 7:07 am

You are using an 'int' as the control variable in your 'for' loop.
Code: Select all | TOGGLE FULL SIZE
 for (int i=0; i<32767; i++)    //  32767max 25iinches 6400 1rev. 3500 short wire.   8500long wire

On most Arduinos and compatibles, that is a 16 bit signed integer and is capable of holding values from -32768 to +32767. If you exceed 32767, it will 'wrap around' to a negative number.

You could use an 'unsigned int' instead. That gives you values from 0 to 65535.

A better solution is to use an 'unsigned long'. That is a 32 bit unsigned integer and can hold values from 0 to 4,294,967,295.

adafruit_support_bill
 
Posts: 73049
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get around stepper topping out at 32767?

by Berniepfei on Wed Dec 19, 2018 9:45 pm

Thanks and I have run across the unsigned long in my searches but I'm having a hard time understanding how it would be used to count a loop like this. All examples I find use the time function. would it be possible for you to give a short example of how it would look?

I'm separated from my Arduino board by work and family right now so I cant play around with it.

Also something I thought about was putting a for loop inside another for loop giving me 32767 iterations of 32767. But I don't know if t will work that way.

Thanks again I really appreciate the help.

Berniepfei
 
Posts: 10
Joined: Sat Apr 29, 2017 11:31 pm

Re: How to get around stepper topping out at 32767?

by adafruit_support_bill on Thu Dec 20, 2018 7:27 am

Thanks and I have run across the unsigned long in my searches but I'm having a hard time understanding how it would be used to count a loop like this.

Just use long instead of int for the type of your loop variable.
Code: Select all | TOGGLE FULL SIZE
for (long i=0; i<32767; i++)

adafruit_support_bill
 
Posts: 73049
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get around stepper topping out at 32767?

by Berniepfei on Thu Dec 20, 2018 11:30 am

adafruit_support_bill wrote:
Thanks and I have run across the unsigned long in my searches but I'm having a hard time understanding how it would be used to count a loop like this.

Just use long instead of int for the type of your loop variable.
Code: Select all | TOGGLE FULL SIZE
for (long i=0; i<32767; i++)

Ok that's a lot simpler than I was thinking lol
Thanks so much!

Berniepfei
 
Posts: 10
Joined: Sat Apr 29, 2017 11:31 pm

Re: How to get around stepper topping out at 32767?

by petespaco on Fri Dec 21, 2018 11:55 pm

Shouldn't the 32767 be changed to 4,294,967,295?

petespaco
 
Posts: 70
Joined: Thu Apr 19, 2012 7:53 pm
Location: west central wisconsin

Re: How to get around stepper topping out at 32767?

by adafruit_support_bill on Sat Dec 22, 2018 6:41 am

Shouldn't the 32767 be changed to 4,294,967,295?

For that, you would need unsigned long. The OP said that 32767 was giving him about 2' of feed and he needed more like 10' or 12'. So he'll probably need something on the order of 200,000.

adafruit_support_bill
 
Posts: 73049
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get around stepper topping out at 32767?

by Berniepfei on Sat Dec 22, 2018 10:00 am

adafruit_support_bill wrote:
Shouldn't the 32767 be changed to 4,294,967,295?

For that, you would need unsigned long. The OP said that 32767 was giving him about 2' of feed and he needed more like 10' or 12'. So he'll probably need something on the order of 200,000.

When I need to make some transatlantic cables I will switch over to that lol.
Thanks guys.
in a little while I'll be off to the shop to start playing with it.

Berniepfei
 
Posts: 10
Joined: Sat Apr 29, 2017 11:31 pm

Re: How to get around stepper topping out at 32767?

by Berniepfei on Mon Dec 24, 2018 9:57 am

Ok its working. But I'm getting some inconsistent lengths. Like over 30 inches I might have 1/2 inch variations. More troubleshooting is in order.
Thanks very much for our help.

Berniepfei
 
Posts: 10
Joined: Sat Apr 29, 2017 11:31 pm

Re: How to get around stepper topping out at 32767?

by adafruit_support_bill on Mon Dec 24, 2018 11:04 am

Could be a number of things. The stepper could be missing steps if the step rate is too fast and/or there is too much resistance in your feed mechanism. Don't know much about the feed mechanism you are using. But it is possible that there is some slippage there too.

adafruit_support_bill
 
Posts: 73049
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get around stepper topping out at 32767?

by Berniepfei on Sat Dec 29, 2018 10:33 am

Yes, now that I have much more range to play with I will make a new, smaller drive wheel that will have more torque to hopefully cut down on any variations due to drag and slip.

Berniepfei
 
Posts: 10
Joined: Sat Apr 29, 2017 11:31 pm

Please be positive and constructive with your questions and comments.