ESP32 Generate varying PWM duty cycle signal using interrupts

Edgey95
Posts: 1
Joined: Sun May 02, 2021 4:51 pm

ESP32 Generate varying PWM duty cycle signal using interrupts

Postby Edgey95 » Sun May 02, 2021 4:59 pm

Hi,

I have been working on a self balancing robot project as a hobby and I am getting a little stuck on what to do next in terms of running stepper motors to keep my robot upright.

I am reading data from a MPU6050, scaling and converting the data to get an angle, all fine.

I now want to control the stepper motors via the ESP32 interrupts, varying the duty cycle off period. I am a little stuck and reaching out for some guidance, I see MCPWM, ledcWrite as options that keep popping up on my google feed on controlling the STEP pin of my stepper motors, is that right?

My robot loop is running every 5ms, I will read the sensor data and perform calculations via a PID controller which will then spit out an off period value for my duty cycle on the stepper motors. I am unsure what is the best approach for controlling these stepper motors?

MCPWM, ledcWrite? or using the general purpose timers and generating the pulse on that pin?

Any tips would be really appreciated. I am not looking for code because that's not fun, I just want to be told the best route to go down.

Thank you

Who is online

Users browsing this forum: No registered users and 15 guests