Skip to content

lots of jitter on step movements #4

@3ricj

Description

@3ricj

Hi there,

I was having problems running this as a service at 6khz pulses. There was breaks in the pulses nearly 20ms (6-10ms typical) long! That made for very rough movement of the stage at times... it would jitter and chatter.. not to mention cause vibration.

I've started to try and optimize this a bit. It's much better now -- pretty stable pulses. I'm still seeing some minor bugaboos (slow fall times?) randomly seeing 1ms pulse lengths on the step line. But much much better now.

Before:
https://www.dropbox.com/s/arb881iok61ibbv/stock.png?dl=0
https://www.dropbox.com/s/1k708hg0hwj6nsq/stock2.png?dl=0

After:
https://www.dropbox.com/s/5knigkzt73tjq9a/changes.png?dl=0

Here's what I changed:

    disableCore0WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper
    disableCore1WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper
    xTaskCreatePinnedToCore(
        ESP_FlexyStepper::taskRunner, /* Task function. */
        "FlexyStepper",               /* String with name of task (by default max 16 characters long) */
        2000,                         /* Stack size in bytes. */
        this,                         /* Parameter passed as input of the task */
        1,                            /* Priority of the task, 1 seems to work just fine for us */
        &this->xHandle,              /* Task handle. */
        1  /*  what core? */
    );                          

This forces the step processing onto core1 -- it seems pretty happy there. This may have other bad side effects -- not sure.

Finally, there are some faster digital pin options on the ESP32 -- bitmask style. here's some info on that:

https://www.instructables.com/Faster-ESP32/

It may help drive things even faster.

Best I can tell the library is doing a bunch of stuff between the rising and falling edge of the pulse. Something in here may be causing the existing jitter, but I'm not sure how to best find it.

  // execute the step on the rising edge
  digitalWrite(stepPin, HIGH);

  // update the current position and speed
  currentPosition_InSteps += directionOfMotion;
  currentStepPeriod_InUS = nextStepPeriod_InUS;

  // remember the time that this step occured
  lastStepTime_InUS = currentTime_InUS;

  // figure out how long before the next step
  DeterminePeriodOfNextStep();

  // return the step line low
  digitalWrite(stepPin, LOW);

Here you can see the 1m pause between rising and falling:
https://www.dropbox.com/s/n9lzfshqx4ar0r1/screenshot.png?dl=0

Thanks for the library, it's awesome.

Best,
-3ric Johanson

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions