LEDC Fade in Frequency instead of duty

michox
Posts: 8
Joined: Tue Jun 02, 2020 4:38 pm

LEDC Fade in Frequency instead of duty

Postby michox » Mon Dec 28, 2020 11:53 am

Hello,
I am working on a project where I am controlling several stepper motors using the LEDC component. The stepper motors have their own stepper driver which takes in a step signal. On each logic rise the stepper will rotate by a certain amount. The speed of the motor is controlled by the frequency of the signal. So I am just using an LEDC with a 50% duty cycle and adjusting the frequency.

Such motors, of course, have inertia which means you can't ramp them up to full speed immediately but you need fade between frequencies. I know the LEDC has a function to fade in duty cycle but I need to fade in frequency here.

Since a lot is going on on the ESP32 I want to pay attention to efficiency and was wondering what the most efficient way of doing this would be?

The first thing that comes to my mind would be a FreeRTOS task with a queue updating the frequency and pausing itself once it achieved the set frequency but I would be happy to learn whether there is a better and more efficient way of doing this.

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

Re: LEDC Fade in Frequency instead of duty

Postby ESP_Sprite » Tue Dec 29, 2020 2:00 am

No, that sounds like a valid idea. As the frequency updates don't need to happen super-often (once every 10? 100? ms) a task is perfectly fine for that. Possibly use esp_timer if you need better precision than that.

Who is online

Users browsing this forum: Google [Bot] and 69 guests