Stepper count ~4x greater than expected on Teensy 3.0

Status
Not open for further replies.

styler

New member
Hi Paul and the rest of the internets

I've been trying to figure out a problem with my stepper count being ~4x higher than expected while running on a Teensy 3.0.

I have a 200 step/rev NEMA23 bipolar stepper motor connected to a G203V Gecko driver with 10x microstepping. Thus, the stepper motor is capable of 2000 steps or positions per revolution. I have a high resolution (20000 steps/rev) quadrature encoder mounted on the same shaft as the stepper motor. The Geckodriver is supplied with 30VDC and is current limited to 2A. I am trying to get the stepper motor to rotate at 1.5RPM.

I am using Teensyduino 1.16 and Arduino 1.0.5.

Using the included code below, I would expect that after one revolution, the step count would be 2000 and the encoder count would be 20000. However, in testing, the step count is 7926 and the encoder count is 20008. I timed a single revolution at roughly 2min38s. The timing of 20000microseconds (sincePrint) should give rise to 50pps (1.5RPM). I've also tried it at a higher speed (2000microseconds/15RPM) which yielded similar results. I realise there are easier ways to do what I'm trying to do, but those methods gave similar results. :/ The code I've included is just a sanity check...

I'm unsure if this is an implementation problem or if I've run into a bug? Any suggestions would be much appreciated!

Here is the last bit of output from serial:

7912 19973
7913 19973
7914 19981
7915 19981
7916 19981
7917 19981
7918 19989
7919 19989
7920 19989
7921 19990
7922 19999
7923 19999
7924 19999
7925 19999
7926 20008
7927 20008
7928 20008
7929 20008

The output seems to suggest that the stepper motor only takes a physical microstep every 4th command.

Here is the code:

Code:
#include <Stepper.h>
#include <Encoder.h>

Stepper disk1_stepper(2000, 7, 8);  // 2000 = number of microsteps per revolution
                                      // pin 7 = step
                                      // pin 8 = direction

Encoder disk1_encoder(11, 12);

elapsedMicros sincePrint;

char command = '0';

String tab = String("\t");

long disk1_stepper_count = 0;
long disk1_encoder_count = 0;


void setup()                        // run once, when the sketch starts
{
  Serial.begin(115200);             // set up serial library at 115200 bps
  delay(15000);  
  Serial.println("Please enter 1 to continue: ");
  
  while (command != '1') {
    if (Serial.available()) {
      command = Serial.read();
    }
  }
  

  disk1_encoder.write(0); 
  
}

void loop()                         // run over and over again
{ 
  

  
  if (sincePrint > 20000) 
  {
    sincePrint = 0;
    disk1_stepper.step(1);
    disk1_stepper_count++;
    disk1_encoder_count = disk1_encoder.read();
    String output = disk1_stepper_count + tab + disk1_encoder_count;
    Serial.println(output);
  }
  

}

I tried to do something similar with the Accelstepper library and ended up with values of 1999 and 20150. Close, but not perfect. Not sure if this is relevant?
 
I have a high resolution (20000 steps/rev) quadrature encoder mounted on the same shaft as the stepper motor.
......
I would expect that after one revolution, the step count would be 2000 and the encoder count would be 20000.

Quadrature decoding gives you 4 counts per pulse from the encoder. An encoder that's specified as 20000 pulses/rev gives 80000 quadrature counts per revolution.

On the Encoder page (scroll down to "Understanding Quadrature Encoded Signals"), there's a little animated widget that shows how the signals work. You can click the Clockwise and Counterclockwise buttons to move it. The wheel depicted on that drawing would be specified as 6 pulses/rev, because it has 6 notches for the sensors to detect. Each of the 2 signals does indeed pulse 6 times per revolution. Each signal alone gives 12 indications of movement (the beginning of the pulse and the end of the pulse). Because they're in quadrature (90 degree) phase, that gives 24 events for quadrature decoding to detect.
 
Quadrature decoding gives you 4 counts per pulse from the encoder. An encoder that's specified as 20000 pulses/rev gives 80000 quadrature counts per revolution.

On the Encoder page (scroll down to "Understanding Quadrature Encoded Signals"), there's a little animated widget that shows how the signals work. You can click the Clockwise and Counterclockwise buttons to move it. The wheel depicted on that drawing would be specified as 6 pulses/rev, because it has 6 notches for the sensors to detect. Each of the 2 signals does indeed pulse 6 times per revolution. Each signal alone gives 12 indications of movement (the beginning of the pulse and the end of the pulse). Because they're in quadrature (90 degree) phase, that gives 24 events for quadrature decoding to detect.

Thanks Paul

Unfortunately, the encoder I'm using is a 5000 step/rev encoder with 20000 quadrature steps. I should have been more specific. Any other ideas?
 
That library you are using isn't intended for the Gecko. It just happens to kind of work.

If you look at Stepper.h:
Step C0 C1
1 0 1
2 1 1
3 1 0
4 0 0


You will kind of get one step pulse going to the Gecko for 4 'step increments' (with a semi-screwed up direction signal).
 
That library you are using isn't intended for the Gecko. It just happens to kind of work.

If you look at Stepper.h:
Step C0 C1
1 0 1
2 1 1
3 1 0
4 0 0


You will kind of get one step pulse going to the Gecko for 4 'step increments' (with a semi-screwed up direction signal).

Ah... Thanks. What library should I be using? I was doing something similar on an Arduino Uno using the encoder and stepper libraries. That worked (more or less) as expected. I thought I could use the same libraries with the Teensy 3?
 
Status
Not open for further replies.
Back
Top