Stepper motor using freeRTOS task

alelor
Posts: 1
Joined: Fri Jan 28, 2022 4:41 pm

Stepper motor using freeRTOS task

Postby alelor » Fri Jan 28, 2022 5:14 pm

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!

KupavtsevSergey
Posts: 2
Joined: Thu Feb 03, 2022 11:33 am

Re: Stepper motor using freeRTOS task

Postby KupavtsevSergey » Thu Feb 03, 2022 3:28 pm

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

ESP_Sprite
Posts: 8999
Joined: Thu Nov 26, 2015 4:08 am

Re: Stepper motor using freeRTOS task

Postby ESP_Sprite » Fri Feb 04, 2022 5:14 am

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.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 105 guests