hot and trembly stepper

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

hot and trembly stepper

Postby hotpod » Fri May 11, 2012 5:16 am

hi... i've googled the web and searched the forums and haven't quite found the answer to this. i'm running one astrosyn b355 stepper from the motorshield, controling direction with a potentiometer using this code;

Code: Select all
#include <AFMotor.h>



AF_Stepper motor(48, 2);


int analogPin = 0;     // potentiometer wiper (middle terminal)
//connected to analog pin 3
// outside leads to ground and +5V
int val = 0;           // variable to store the value read
int prepos = 0;
int pos = 0;
void setup()
{
  motor.setSpeed(100);
}

void loop() {

  prepos = pos;
  val = analogRead(analogPin);    // read the input pin

  pos = map (val, 0, 1023, 0, 96);

  if (pos != prepos){
    int diststep = pos - prepos;
    if (diststep < 0) {
    motor.step(-diststep, BACKWARD, INTERLEAVE);
    }
    if (diststep > 0) {
    motor.step(diststep, FORWARD, INTERLEAVE);
    }
  }

}



it responds beautifully, but i saw that there was a twitch and a tremble when the stepper is holding position. when i put my finger on the spindle i also noticed that the whole motor is very very hot. the tech specs say that the coil temp is 115º - though being new to steppers i'm not sure if that's a maximum or if its a normal operating temperature. the temperature of the h-bridges on the shield is fine.

i'd like to add in a motor.release() for when the motor is not actually being moved - (it will be panning a suspended camera so releasing the coils won't be a problem). putting the release in the loop just causes unpredicatable behaviour, and outside the loop doesn't seem to do anything.

any tips for how to eliminate the trembles and run my motor a bit cooler?

thanks
hotpod
 
Posts: 6
Joined: Fri May 11, 2012 5:08 am

Re: hot and trembly stepper

Postby adafruit_support_bill » Fri May 11, 2012 5:57 am

The "trembles" are likely due to noise on your analog pin. Although you may not be moving the pot, the noise will translate into small step changes for the motor. You can filter this by taking a moving average of the analog reads. Or you can just ignore any moves less than some threshold.

Stepper motors do run hot. Coil temp specs in excess of 100C are not at all uncommon. Temp specs are typically based on some specification for expected motor lifetime. At cooler temps they will last longer. Higher temps mean a shorter lifetime. A general rule of thumb is that a 10C rise will cut the motor life in half.

If holding torque is not needed, you can do a "release". The problem is that the motor will always power up in the same phase - which is not necessarily the same as the phase of the last position it stopped at. If you search these forums, a user recently added a modification to the library to "Hold" the motor at the current step but at reduced holding current. That should let the motor run cooler when stopped, but not forget the position.
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am

Re: hot and trembly stepper

Postby hotpod » Fri May 11, 2012 7:06 am

ok, thanks. i've implemented the moving average code and that seems to work just fine.

i'm still wondering about the heat issue and implementing the HOLD mode though. the motor will be bolted to a piece of aluminium (yes, i'm english :D ) approx 60cm square which i guess will act as a reasonably effective heatsink and will dissipate a certain amount of heat.

is this the HOLD mode you mentioned?

Code: Select all
    void AF_Stepper::hold(uint8_t pwm, uint8_t style) {
      uint8_t a, b, c, d;
      uint8_t ocrb, ocra;

      ocra = ocrb = pwm;

      if (steppernum == 1) {
        a = _BV(MOTOR1_A);
        b = _BV(MOTOR2_A);
        c = _BV(MOTOR1_B);
        d = _BV(MOTOR2_B);
      } else if (steppernum == 2) {
        a = _BV(MOTOR3_A);
        b = _BV(MOTOR4_A);
        c = _BV(MOTOR3_B);
        d = _BV(MOTOR4_B);
      } else {
        return;
      }


      if (steppernum == 1) {
        setPWM1(ocra);
        setPWM2(ocrb);
      } else if (steppernum == 2) {
        setPWM3(ocra);
        setPWM4(ocrb);
      }


      // release all
      latch_state &= ~a & ~b & ~c & ~d; // all motor pins to 0

      //Serial.println(step, DEC);
      if (style == MICROSTEP) {
        if ((currentstep >= 0) && (currentstep < MICROSTEPS))
          latch_state |= a | b;
        if ((currentstep >= MICROSTEPS) && (currentstep < MICROSTEPS*2))
          latch_state |= b | c;
        if ((currentstep >= MICROSTEPS*2) && (currentstep < MICROSTEPS*3))
          latch_state |= c | d;
        if ((currentstep >= MICROSTEPS*3) && (currentstep < MICROSTEPS*4))
          latch_state |= d | a;
      } else {
        switch (currentstep/(MICROSTEPS/2)) {
        case 0:
          latch_state |= a; // energize coil 1 only
          break;
        case 1:
          latch_state |= a | b; // energize coil 1+2
          break;
        case 2:
          latch_state |= b; // energize coil 2 only
          break;
        case 3:
          latch_state |= b | c; // energize coil 2+3
          break;
        case 4:
          latch_state |= c; // energize coil 3 only
          break;
        case 5:
          latch_state |= c | d; // energize coil 3+4
          break;
        case 6:
          latch_state |= d; // energize coil 4 only
          break;
        case 7:
          latch_state |= d | a; // energize coil 1+4
          break;
        }
      }


      MC.latch_tx();
      return;
    }



this would go outside of my loop and my set up, right?


thanks
hotpod
 
Posts: 6
Joined: Fri May 11, 2012 5:08 am

Re: hot and trembly stepper

Postby adafruit_support_bill » Fri May 11, 2012 7:43 am

the motor will be bolted to a piece of aluminium (yes, i'm english :D )

Heat sinks are good. A dab of thermal grease on the mating surfaces will make it even more effective. I spent a fair amount of time in England. Never quite mastered the language though... :wink:
is this the HOLD mode you mentioned?

That looks like the one. It needs to go in the library. You'll need a function prototype for the Hold() in the .h file also.
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am

Re: hot and trembly stepper

Postby hotpod » Fri May 11, 2012 7:55 am

thermal grease... check.

so, the HOLD code gets pasted into the AFmotor.cpp. it can go anywhere in the *** MOTORS ***section, right? i think i can do that.

creating a 'function prototype for the Hold() in the .h file'... i'm not exactly sure what this means. does this mean that after "class AF_Stepper {
public:
AF_Stepper(uint16_t, uint8_t);"

i add the line "void hold(void);" ?

then, when i want to use the hold function in my code i just use motor.hold() instead of motor.release()? what is the optimum location in the code for this?


thanks so much again for such quick and helpful responses...
hotpod
 
Posts: 6
Joined: Fri May 11, 2012 5:08 am

Re: hot and trembly stepper

Postby adafruit_support_bill » Fri May 11, 2012 8:43 am

Your hold function has arguments, so you need to specify those in the prototype too:
Code: Select all
void hold(uint8_t, uint8_t);

You can add it to the code as below:
Code: Select all
    if (diststep < 0)
    {
        motor.step(-diststep, BACKWARD, INTERLEAVE);
    }
    else if (diststep > 0)
    {
        motor.step(diststep, FORWARD, INTERLEAVE);
    }
    else
    {
        hold(10, INTERLEAVE); // use as little holding current as you need
    }
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am

Re: hot and trembly stepper

Postby hotpod » Mon May 21, 2012 12:15 pm

coming back to this jittery thing...

its still jittery. :(

i've added in the moving average code, which sees some improvement, but now and again in what seems to be random positions it just starts to vibrate pretty badly. at least badly enough that it will be a major problem for the camera mounted on it. with the pot turned full either way its solid as a rock, but at certain positions through the arc it sets off jittering.

the odd thing is that the only time it doesn't jitter is when its running only off the USB power without the 12v supply plugged into the arduino. beautifully smooth. its a 12v motor though so i'm a little confused about this. surely the solution wouldn't be as simple as running a 12v motor off a 5v supply? i don't need much torque so maybe it is...
hotpod
 
Posts: 6
Joined: Fri May 11, 2012 5:08 am

Re: hot and trembly stepper

Postby adafruit_support_bill » Mon May 21, 2012 12:54 pm

the odd thing is that the only time it doesn't jitter is when its running only off the USB power without the 12v supply plugged into the arduino.

At higher voltages the motors will draw more current and create more noise. Are you running the steppers and the Arduino on separate supplies? That will minimize the amount of noise that feeds back into the Arduino. You can also use the 3.3v pin as your analog reference. It tends to be quieter than the 5v rail. http://arduino.cc/it/Reference/AnalogReference

On the software side, you can increase the sample size for your moving average. There are other filtering techniques that can be employed, but it helps to know the nature of the noise. Do you have access to a scope?
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am

Re: hot and trembly stepper

Postby hotpod » Fri May 25, 2012 9:51 am

the arduino and the motor are now on seperate supplies and i've tried moving average sample sizes between 20 and 500 with no great difference in effect.

i don't have access to a scope (and i wouldn't really know how to use one if i had...), but watching the serial monitor i see the values jump about within a range of 2 or 3 values every now and again.

i'll switch to the 3.3v pin and see if that helps anything...
hotpod
 
Posts: 6
Joined: Fri May 11, 2012 5:08 am

Re: hot and trembly stepper

Postby adafruit_support_bill » Fri May 25, 2012 10:03 am

You must have some good-sized spikes on the line to cause that much variation in a 500-sample average.

Another option if the 3.3v reference doesn't help is to use a rotary encoder instead of a pot. That will be immune to any motor noise.
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am

Re: hot and trembly stepper

Postby hotpod » Fri May 25, 2012 10:43 am

actually, now i look more closely its not such high values constantly - though some were initially - more of a plus/minus 1 from time to time. if the motor begins to tremble a very tiny adjustment of the pot will bring it stable again. a colleague suggested (without seeing my code) that it was somehow 'getting stuck between steps' - which would make sense. however, i don't see anything in my code that could make that happen. i'll post it below in case anyone wants to review it. the only oddity i can't explain (probably through lack of technical experience) is that although its supposed to be a 48 step motor (7.5º per step) i need to give it 96 steps to complete 360º rotation.

Code: Select all
#include <AFMotor.h>

AF_Stepper motor(48, 2);


int analogPin = 0;     
int val = 0;           // variable to store the value read
int prepos = 0;
int pos = 0;     //0 to 96

const int numReadings = 100;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

//int inputPin = 0;


void setup()
{
{
  motor.setSpeed(30);  // 30 rpm
motor.release();
delay(1000);
}

  Serial.begin(9600);
}

void loop() {
 
  // subtract the last reading:
  total= total - readings[index];       
  // read from the sensor: 
  readings[index] = analogRead(analogPin);
  // add the reading to the total:
  total= total + readings[index];     
  // advance to the next position in the array: 
  index = index + 1;                   

  // if we're at the end of the array...
  if (index >= numReadings)             
    // ...wrap around to the beginning:
    index = 0;                         

  // calculate the average:
  average = total / numReadings;       
  // send it to the computer as ASCII digits
  Serial.println(average, DEC);

  prepos = pos;
  val = analogRead(analogPin);    // read the input pin

  pos = map (val, 0, 1023, 0, 96);

  if (pos != prepos){
    int diststep = pos - prepos;
    if (diststep < 0) {
    motor.step(-diststep, BACKWARD, INTERLEAVE);
    }
    if (diststep > 0) {
    motor.step(diststep, FORWARD, INTERLEAVE);
    }
  // motor.release();
  }
{
   Serial.print(0);
}
}
hotpod
 
Posts: 6
Joined: Fri May 11, 2012 5:08 am

Re: hot and trembly stepper

Postby adafruit_support_bill » Fri May 25, 2012 10:54 am

If you do the map() on the raw readings instead of the average it should quiet things down a bit.

Code: Select all
readings[index] = map(analogRead(analogPin),0, 1023, 0, 96);


The 96 steps is because you are using "INTERLEAVE" mode. That gives you half-steps between each full-step.
User avatar
adafruit_support_bill
 
Posts: 15987
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino Shields from Adafruit

Who is online

Users browsing this forum: No registered users and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]