TeensyStep Questions

Hi,

Hardware: Teensy3.6
Software: Arduino using Ubuntu 20.04

I was experimenting with teensyStep library and made some observations that I thought was odd and would like some clarification.
I modified the "HelloStepper" example to use StepControl::moveAysnc()
Code:
#include "TeensyStep.h"

Stepper motor(2, 3);       // STEP pin: 2, DIR pin: 3
StepControl controller;    // Use default settings 

void setup()
{
  motor.setStepPinPolarity(LOW);
  motor.setInverseRotation(true);
  motor.setAcceleration(3500);
  motor.setMaxSpeed(3500);
  motor.setTargetRel(40000)
}

void loop() 
{
  controller.moveAsync(motor);    // Do the move
  delay(2000);
}
When executing the code, the motor initially starts at max speed, but in equal intervals of time for a small duration slows down and speeds back up again. The frequency of motor slow down increases with decrease in delay time. Without the delay the motor does not move at all.
With StepControl::move(), setting setTargetRel(40000), moves the motor 180 degrees, whereas when executing the above code, the motor moves only about 90 degrees. Even after increasing the setTargetRel value to 80000 (360 degrees), the motor moves about 90 degrees only.

Any help is appreciated.
Thank you.
 
moveAsync is not blocking (hence the name). In loop you call moveAsync every 2 seconds, i.e. you call moveAsync while the motor still runs which will mess up the controller. Try using controller.move(motor) (which blocks until the movement is done) instead of moveAsync.
 
Thanks for the quick reply!

I'm new to Teensy3.6 and TeensyStep, could you please explain how moveAsync() works. It is it running in a separate thread or is it some other mechanism.
I would like to add ZMCT103C current sensor to the teensy. The sensor will use a blocking for loop to collect multiple reading to give the rms current. Would that cause any issue with TeensyStep?
 
I'm new to Teensy3.6 and TeensyStep, could you please explain how moveAsync() works. It is it running in a separate thread or is it some other mechanism.
It is running from a timer interrupt. I.e., the moveAsync() sets up all parameters for the movement and starts a timer which generates the pulses, adjusts the timing as needed and keeps track of the steps in its interrupt routine.

I would like to add ZMCT103C current sensor to the teensy. The sensor will use a blocking for loop to collect multiple reading to give the rms current. Would that cause any issue with TeensyStep?

That should be fine. Here an example showing how to do stuff while the motor moves:

Code:
#include "Arduino.h"
#include "TeensyStep.h"

Stepper motor(2, 3);    // STEP pin: 2, DIR pin: 3
StepControl controller; // Use default settings

void setup()
{
    motor.setStepPinPolarity(LOW);  
    motor.setInverseRotation(true);
    motor.setAcceleration(3500);
    motor.setMaxSpeed(3500);
}

void loop()
{
    motor.setTargetRel(random(10'000, -10'000)); // set some random target
    controller.moveAsync(motor);                 // start the movement

    // do something while the motor moves, e.g. read sensor
    delay(2000);

    // make sure the motor reached the target before setting a new one
    while (controller.isRunning())
    {
        delay(10);
    }
}
 
Thank you for the explanation!
With StepControl::move(), setting setTargetRel(40000), moves the motor 180 degrees, whereas when executing the above code, the motor moves only about 90 degrees. Even after increasing the setTargetRel value to 80000 (360 degrees), the motor moves about 90 degrees only.
For better understanding, could you explain that might be the reason for this?
 
As mentioned in #2 you must not call a move command while the motor is still moving. The code in #1 calls moveAsync every 2 seconds regardless if the motor moves or not. -> the movement will be disturbed every 2 seconds. Increasing the target position will not change this. If you use move() the motor will finalize its movement and wait 2 seconds afterwards.

The rule is quite simple: If you call any movement command while the controller still moves motors, anything can happen! The motor can stop, the counter can be messed up, the controller could start beaming little green men down from Mars... So, just don't do it.

I'm curious: You said that your motor moves 180° for 40'000 steps. This is an unusually high resolution. Can you post which motor / driver / microstep setting you are using to actually get 80'000 steps per revolution?
 
Last edited:
Thanks! Will keep a note of that!
I'm curious: You said that your motor moves 180° for 40'000 steps. This is a unusually high resolution. Can you post which motor / driver / microstep setting you are using to actually get 80'000 steps per revolution?
Sorry for the confusion. The motor has 1600 microsteps, I use a 50:1 gear box with the motor, which makes it 40,000
 
Ah, that makes sense.
Let me know if you need further support with TeensyStep
 
Back
Top