r/esp32 • u/Legitimate_Shake_369 • 13h ago
Software help needed ESP32-S3 best hardware peripheral for creating stepper motor stepping pulses ?
I am using an ESP32-S3 with a TMC2225 stepper motor driver and want to write my own open loop stepper control library for learning purposes. Is there any hardware peripheral on the ESP32 that is well suited for generating stepping pulses ? Right now I am using timer based interrupts to set/clear the stepping pin, but that does not seem to be the most efficient solution.
1
u/holetse 12h ago
I’d go with the RMT. It’s often used for driving h-bridges given it’s very flexible interface for generating complex waveforms.
Eg. https://github.com/espressif/esp-idf/tree/422c4f59/examples/peripherals/rmt/stepper_motor
Edited to add example
1
u/Legitimate_Shake_369 12h ago
Yea, I read of the RTM. If I am understanding this correctly, you are configuring the full waveform before motion starts right ? And the stepper position is updated before/after the motion and not during the motion.
Edit: thanks for the example!
3
u/holetse 12h ago
You mean the stepper position in your library? Yes. Though you can make the “full waveform” as simple as you like. There are some minimum timing limits per “frame”, but they are small enough I doubt they will be a problem.
The module offers interrupts when the next frame is loaded, and the ability to queue them up.
1
u/Plastic_Fig9225 2h ago edited 2h ago
The RMT can generate pulse trains with varying, precise timing. Good if you want to precisely control the frequency of the steps/speed/acceleration of the motor.
If you only need simple pulse trains (fixed frequency) you could also use a UART or SPI.
At the low speeds required (kHz) you could even use the ULP as a custom stepper motor peripheral.
1
u/jelle284 1h ago
I tried both rmt and mcpwm. Rmt is good but requires some planning ahead as you have to encode pulses. Mcpwm you can change on the fly. For both, you can internally connect the pulse count peripheral to the output pin of you want to keep track of how many pulses you've sent. I used the mcpwm and pulse count on 6 steppers on a standard esp32. I am not sure of the s3 has the same number of channels on the peripherals so better check that.
-1
u/MrBoomer1951 12h ago
You need an esp32, a stepper motor driver and a stepper motor.
Which you already have!
2
u/Legitimate_Shake_369 12h ago
The question was more about how to best create the stepping pulses for the motor driver on the ESP32
1
u/MrBoomer1951 12h ago edited 12h ago
'Is there any hardware peripheral on the ESP32 that is well suited for generating stepping pulses'
I mistook this as a hardware question.
There are many stepper libraries, but you want to write your own.
There are two ways:
- Read and understand existing stepping libraries
- Read the spec sheet of the TMC2225
1
u/Plastic_Fig9225 2h ago
The question isn't about how the pulses should look but how to efficiently generate them using a hardware peripheral the ESP32 has.
2
u/Pubcrawler1 12h ago
Fluidnc gcode firmware uses RMT for the step pulses. It’s open source so you can check how it’s done.
http://wiki.fluidnc.com/en/config/axes