gin66 / FastAccelStepper

A high speed stepper library for Atmega 168/328p (nano), Atmega32u4, Atmega 2560, ESP32, ESP32S2, ESP32S3, ESP32C3 and Atmel SAM Due
MIT License
283 stars 67 forks source link

Problems while using LEDC based PWM above 5khz #168

Closed honeybadger2023 closed 1 year ago

honeybadger2023 commented 1 year ago

Hi,

First things first: This is a great library. Well done and easy to integrate. I'm trying to run a single axis while simultaneously having a PWM switching a gate driver.

The PWM signal is generated this way:

  this->pwm_timer   = { LEDC_LOW_SPEED_MODE, LEDC_TIMER_10_BIT, LEDC_TIMER_0, this->freq_min, LEDC_USE_APB_CLK };
  this->pwm_channel = { this->pwm_pin, LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, LEDC_INTR_DISABLE, LEDC_TIMER_0 };
  ledc_timer_config(   &this->pwm_timer   );
  ledc_channel_config( &this->pwm_channel );
  ledc_bind_channel_timer( LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, LEDC_TIMER_0 );   

I run the FastAccelStepper engine on core 0 with:

engine.init(0);

Watchdogs and Wifi are disabled. There are three other tasks pinned to core 0. They all read pins and buffer the value. vTaskDelay for two of these tasks is 50 and one uses a vTaskDelay(10).

The problem I have is that above 5khz PWM the Stepper starts to make Problems. At 7khz it starts to vibrate and at 10khz there is no motion left at all. Without PWM or with a PWM about 5khz it works like intended.

It seems that the fast PWM signal won't allow the FastAccel engine to execute it's tasks.

Are there any solutions or known issues for this situation or is it just not possible?

honeybadger2023 commented 1 year ago

Turned out I had some problems in my wiring. Ground loop maybe. After fixing the wiring it works.

gin66 commented 1 year ago

congrats on fixing the issue :-)