Page 1 of 1

Stepper motor using freeRTOS task

Posted: Fri Jan 28, 2022 5:14 pm
by alelor
Hi,
I have to drive a stepper motor with my esp32, with a frequency that requires a delay below milliseconds (for example 100 microseconds). The esp32 has WiFi and ESP-NOW active at the same time, receiving some data from another esp32. My idea was to create a freeRTOS task for the stepper motor on core 0, so that core 1 can run WiFi ESP-NOW, but I have a hard time managing microseconds delay by doing so. I know that the vTaskDelay() cannot go higher than 1kHz.
Any suggestions? Thanks in advance!

Re: Stepper motor using freeRTOS task

Posted: Thu Feb 03, 2022 3:28 pm
by KupavtsevSergey
Maybe this will help you. You can use ets_delay_us(stepper_delay); between steps. But, for example, every step 50 execute vTaskDelay(1);

or you can disable wtd in stepper task
esp_task_wdt_delete(NULL);
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(0));
in the stepper task before the infinite loop

Re: Stepper motor using freeRTOS task

Posted: Fri Feb 04, 2022 5:14 am
by ESP_Sprite
Suggest not using ets_delay_us, as it's polling. The proper way to get low-jitter sub-ms timing would be to use a hardware timer.