Go Down

Topic: [Solved] Steppers work fine with PWM, but worthlessly jittery otherwise (Read 606 times) previous topic - next topic

manofsc1ence

Hi,

I'm a bit stuck and I've been unable to troubleshoot or Google my way out. I'm using:

 - 3.3 V SAMD Microcontroller (Adafruit Feather M0)
 - NEMA 23 stepper motor rated 4.0 V / 2.5 A per phase
 - TB6600 4A 9-42V stepper motor driver (set to no micro stepping, current 2.0 / pk current 2.2)
 - 12 V / 14 A computer PSU I use as a poor man's bench supply

The motor works fine when I send a PWM signal with analogWrite
The motor does not work fine when I use delay statements, such as:
Code: [Select]

for (int i = 0; i < 200; i++) {
    digitalWrite(PULSEPIN, HIGH);
    delay(5)
    digitalWrite(PULSEPIN, LOW);
    delay(5);
}

In this case the motor stutters back and forth around the point of origin making an awful racket on the table.

The motor is somewhat jittery, yet still reliably makes foreword progress when I manually take the pulse pin and jam it in and out of the 3.3V rail on my breadboard in frustration. I attribute the jitter here to my barbaric lack of debouncing.

Thoughts?

FredScuttle

Try this, if the motor does not turn 1 rev in about 20 seconds, you have something wired wrong or the TB6600 is not configured correctly, post a wiring diagram and your full code so we can see your setup.
Code: [Select]
for (int i = 0; i < 200; i++) {
    digitalWrite(PULSEPIN, HIGH);
    delayMicroseconds(20);
    digitalWrite(PULSEPIN, LOW);
    delay(100);
}
Awww! Who needs an instruction manual to use a simple chain sa......

manofsc1ence

I tested that code with no luck. It just jittered at the starting position.

I have attached some of the requested files as a zip [EDIT file size limits, man]

- Circuit diagram
- Motor driver user guide
- Motor driver data sheet [EDIT TB6600 data sheet is too large to upload]
- Nema23 motor spec sheet
- code working example
- code not working example (the copy-pasted code from above reply)

Note that I did not list microcontroller pin connections for PUL+ (pulse) and DIR+ (direction) on the circuit diagram because I have tried several combinations. However, for the code snippets included I am using 11 for PUL+ and 10 for DIR+

I'll copy/paste my code below as well for convenience:

Code: [Select]

//CODE THAT DOES NOT WORK, CAUSES JITTER AND NO MOTOR PROGRESS
const int DIR = 10;
const int PUL = 11;

void setup() {
  pinMode(DIR, OUTPUT);
  pinMode(PUL, OUTPUT);

  digitalWrite(DIR, HIGH);
}

void loop() {
  digitalWrite(DIR, !digitalRead(DIR));
  for (int i = 0; i < 200; i++) {
    digitalWrite(PUL, HIGH);
    delayMicroseconds(20);
    digitalWrite(PUL, LOW);
    delay(100);
}
  delay(10000);
 
}



Code: [Select]

//CODE THAT DOES WORK, USING PWM
const int DIR = 10;
const int PUL = 11;

void setup() {
  pinMode(DIR, OUTPUT);
  pinMode(PUL, OUTPUT);

  digitalWrite(DIR, HIGH);
}

void loop() {
  digitalWrite(DIR, !digitalRead(DIR));
  analogWrite(PUL, 255);
  delay(10000);
  analogWrite(PUL, 0);
  delay(10000);
}


In case it helps to know the use case, I'm embarking on a long project to build a serious desktop manipulator robot. PWM is not useful to me as-is because I need much more control of motor acceleration, velocity, and speed. If I can ever figure out why the basic code won't run as expected, I'll start to write some interrupt routines that will help to handle these kinematics.

I will try to replicate this issue with an Arduino Uno and then if all else fails I'll switch to PIC.

Robin2

Stepper motors do not use PWM as produced by analogWrite(). They just need a brief HIGH pulse (maybe 10 microsecs) for every step. The interval between pulses determines the speed.

Always start testing with a very low speed - maybe 4 steps per second.

These links may help
Stepper Motor Basics
Simple Stepper Code


Are you sure that a 3.3v microprocessor is capable of controlling the stepper driver?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

FredScuttle

Code: [Select]
void loop() {
  digitalWrite(DIR, !digitalRead(DIR));
  analogWrite(PUL, 255);
  delay(10000);
  analogWrite(PUL, 0);
  delay(10000);
}

This is switching direction on every iteration of loop() and you are sending the driver a rising edge (step) every 20 seconds, you say it works? I think one of the motor coils is wired backward, reverse the wires on one of the the coils and try my sketch.
Awww! Who needs an instruction manual to use a simple chain sa......

manofsc1ence

These links may help
Stepper Motor Basics
Simple Stepper Code


Are you sure that a 3.3v microprocessor is capable of controlling the stepper driver?
Very helpful links indeed. They cleared up several hazy things for me right away. To clarify, I wasn't trying to use PWM as one might use it for a DC motor-- I just figured it would give me a pretty stable pulse train in the 500 Hz neighborhood. I have since switched to an Arduino UNO at 5V.

This is switching direction on every iteration of loop() and you are sending the driver a rising edge (step) every 20 seconds, you say it works? I think one of the motor coils is wired backward, reverse the wires on one of the the coils and try my sketch.
No luck with reversing one of the coils and using your sketch. Specifically I tried:

    A+ Blue Stepper Wire     ->  A+ Blue Stepper Wire
    A-  Yellow Stepper Wire  ->  A-  Yellow Stepper Wire
    B+ Green Stepper Wire  ->  B+  Red Stepper Wire
    B-  Red Stepper Wire     ->  B-  Green Stepper Wire
(According to the wire color to coil scheme diagrammed in the motor spec sheet I attached)

It still jitters around the starting point when running your for loop.

--------------------------------------

New findings with the Arduino UNO:

The following code works as expected*

Code: [Select]

const int DIR = 4;
const int PUL = 3;
const int DELAY_TIME = 100;
void setup() {
  pinMode(DIR, OUTPUT);
  pinMode(PUL, OUTPUT);

  digitalWrite(DIR, HIGH);
}

void loop() {
  for (int i = 0; i < 200; i++) {
    digitalWrite(PUL, HIGH);
    delay(DELAY_TIME);
    digitalWrite(PUL, LOW);
    delay(DELAY_TIME);
}
}


*PROVIDED I do the following things:
1. I switch the driver board to 1/4 Microstepping or below
2. DELAY_TIME > 55-ish (ms)

If I drop below DELAY_TIME of 60, the motor often jumps forward or backward but more or less continues making forward progress
If try full-stepping or drop below DELAY_TIME of 50, the motor jitters in place

I'm really at a loss for how else to continue troubleshooting this... Perhaps increasing the voltage and/or trying with a real power supply as opposed to this repurposed CPU PSU? I'm really confused why PWM works in this case, but there are so many hoops to jump through to get the digital outputs to crawl at a snail's pace.

FredScuttle

The datasheet shows (for a 4 lead motor) a black & green pair and a red & blue pair, How many leads on your motor?
Awww! Who needs an instruction manual to use a simple chain sa......

manofsc1ence

There are only four leads on the motor. Red, Green, Yellow, and Blue wires.

FredScuttle

Quote
I'm really at a loss for how else to continue troubleshooting this...
Me too, without being there   :smiley-confuse:  sorry.
One more thing, try making red/blue and green/yellow the pairs, then reverse the wires on one pair if it still doesn't work.
Awww! Who needs an instruction manual to use a simple chain sa......

manofsc1ence

WAHOO PRETTY SURE I SOLVED IT

Somewhere between fits of rage and wails of abject misery I had a sudden curiosity to see what lowering the current output on the driver board would do to the torque on the motor. Lo and behold my motor works perfectly running at 1.0 A / 1.2 peak instead of 2.0 A / 2.2 peak.



So...

How can I learn from this?

The motor spec sheet lists rated its current at 2.5 A per phase. I assumed that I should choose a current level on the driver board that approached this rated current, so I picked 2.0 A / 2.2 peak. Ultimately 1.0 A / 1.2 peak on the driver board ended up getting this dang thing working. Is it a stupid assumption to think that the rated current for the motor per phase should dictate the driver board current limits? Assuming that the motor data sheet is truthful (here I go making assumptions again...) how should one pick the working current on the driver board?

Many thanks for all the help, suggestions, and well-wishes!

MorganS

I think the max current for most stepper drivers is very optimistic. The chip itself might be capable of 2A but only when a lot of other conditions are satisfied. It must have big enough PCB traces and a heatsink and fan cooling and lots of other expensive things that don't fit on a basic 1" square breakout board.

But in general, you would expect the motor to run well with 70-110% of its nameplate current rating.
"The problem is in the code you didn't post."

Southpark

I'm really at a loss for how else to continue troubleshooting this...
It appears that you need to get your foundations/bearings right..... eg. pwm isn't used for driving stepper motors. It would be beneficial to maybe start from basics --- eg. stepper motor tutorials to begin with. Otherwise, if you are applying pwm to a stepper motor, then the first thing to do is to explain the reason behind it, so that everyone is clear about the intention.

The comment relating to your observation in the thread title ... 'worthlessly jittery' ..... is not due to any fault(s) in the hardware components. Describing it simply as 'jittery' is ok. We should avoid throwing in 'worthlessly' if we can help it.

Robin2

There are only four leads on the motor. Red, Green, Yellow, and Blue wires.
Ignore the colours unless you have the manufacturer's datasheet for your specific motor. Just figure out which pair belongs to which coil by measuring the resistance with your multimeter.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MarkT

A big heavy stepper motor requires acceleration and decelaration ramping of the step rate, otherwise it
will miss-step due to the large inertia of the rotor.

Try the AccelStepper library
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

manofsc1ence

Thanks for the replies everyone. This issue has been solved. (How to mark this thread as solved?)

It appears that you need to get your foundations/bearings right..... eg. pwm isn't used for driving stepper motors. It would be beneficial to maybe start from basics --- eg. stepper motor tutorials to begin with. Otherwise, if you are applying pwm to a stepper motor, then the first thing to do is to explain the reason behind it, so that everyone is clear about the intention.
I was just using PWM to easily get a known pulse-train. The reason for the post is really my amusement that PWM worked at all considering delay statements did not produce any meaningful results.

The comment relating to your observation in the thread title ... 'worthlessly jittery' ..... is not due to any fault(s) in the hardware components. Describing it simply as 'jittery' is ok. We should avoid throwing in 'worthlessly' if we can help it.
I guess what I was going for is "This motor is so jittery that it does not make any revolute progress" so as to distinguish my issue from a simple case of a few skipped steps.

I think the max current for most stepper drivers is very optimistic. The chip itself might be capable of 2A but only when a lot of other conditions are satisfied. It must have big enough PCB traces and a heatsink and fan cooling and lots of other expensive things that don't fit on a basic 1" square breakout board.

But in general, you would expect the motor to run well with 70-110% of its nameplate current rating.
This is exactly the kind of rule of thumb I was looking for. Perhaps @Robin2 can add this to his stepper motor post? It would have prevented many hours of frustration on my part had I thought to try reducing the current sooner.

As you can tell I'm new here... Can someone tell me how to mark this issue as solved? I don't remember seeing that in the stickied user guide.

Go Up