Page 2 of 2

Re: Fast IO pin toggle with WiFi seems to cause issues

Posted: Mon Jan 27, 2025 4:43 pm
by MicroController
Does that sound like a plan?
Sure does :)
What does RMT do that would be better than that?
With the RMT, you can directly define the duration of every pulse individually, which may be more simple to do than via SPI, and also with a higher resolution (15 bits for the high + 15 bits for the low phase); and using the loop functionality you can have the hardware repeat a given pulse (sequence) a specific number of times, which could ease implementing the constant-speed phase. Using the 'encoder' callback mechanism of the RMT driver, you can possibly calculate all pulses on the fly as&when the RMT needs them.

Re: Fast IO pin toggle with WiFi seems to cause issues

Posted: Tue Jan 28, 2025 1:15 am
by ok-home
In your code you used the bitbang variant, which is not good for esp
You have been given 2 options to choose from SPI and RMT
I reread your task again, I understood correctly you generate PWM sequences with different pulse widths at stages
Acceleration phase, regular speed and deceleration
Apparently, there is a third option that also fits the task -> LEDC with fade mode

Which one to choose -> it's your decision

Re: Fast IO pin toggle with WiFi seems to cause issues

Posted: Tue Jan 28, 2025 8:17 am
by MicroController
I understood correctly you generate PWM sequences with different pulse widths at stages
As I understand it, he needs pulses with varying frequencies (stepper motor?).

Re: Fast IO pin toggle with WiFi seems to cause issues

Posted: Tue Jan 28, 2025 8:51 am
by brebisson
Hello,

Yes, it is for a stepper

The 2 requirements are:
- The pulses duration (both 0 and 1 parts) will need to vary over time (slow, at first, getting shorter, a steady phase (short) and a slow down).
- I need to "program" an exact number of pulses

A typical pulse sequence might have around 640000 pulses over a 20s range.

As far as I can tell the RTM will not allow me to easely do this as it seems to be more of a modulator for a base frequency...
SPI, I think that I can make work, but I need to check the memory useage and be carefull with that...
LEDC with fade is something that I have not yet looked at... Knowing about LED and PWM I assume that it can do the accelerateion/deceleration... But can I predict/program the number of pulses?

For the moment, it looks like the best option is SPI...

Cyrille

Re: Fast IO pin toggle with WiFi seems to cause issues

Posted: Tue Jan 28, 2025 9:25 am
by floitsch_toit
What is wrong with using the SPI to send a pulse which can be of variable size?
The SPI has a fixed duration for each bit. If that is good enough (as you mention 20% accuracy), then the SPI should work just fine for you.
What does RMT do that would be better than that?
The RMT has insanely precise timings. You can specify the duration of each of them based on a 80MHz clock. It is (or at least "was") more useful for fewer pulses. The RMT is my favorite peripheral on the ESP32, but it looks like SPI should work for you.

Re: Fast IO pin toggle with WiFi seems to cause issues

Posted: Tue Jan 28, 2025 9:44 am
by MicroController
As far as I can tell the RTM will not allow me to easely do this as it seems to be more of a modulator for a base frequency...
You can optionally have the RMT output modulate some carrier frequency; for IR remote control signals, you'd typically have it modulate a 38kHz carrier. If you choose not to use a carrier, the RMT allows you to just output pulses where you define the high and low duration of each pulse individually, enabling both frequency and duty cycle to be controlled per pulse.

Re: Fast IO pin toggle with WiFi seems to cause issues

Posted: Wed Jan 29, 2025 12:49 pm
by floitsch_toit
The current suggestions are mainly to use the SPI. However, the I2S peripheral might be a better choice. It is designed to output bits at a constant speed which is what you need to have a reliable pulse-width. The SPI is probably emitting the bits at the correct pace too, but there are fewer guarantees.