Fast IO pin toggle with WiFi seems to cause issues

MicroController
Posts: 2046
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Mon Jan 27, 2025 4:43 pm

brebisson wrote:
Mon Jan 27, 2025 4:14 pm
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.

User avatar
ok-home
Posts: 116
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

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

Postby ok-home » Tue Jan 28, 2025 1:15 am

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

MicroController
Posts: 2046
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Tue Jan 28, 2025 8:17 am

ok-home wrote:
Tue Jan 28, 2025 1:15 am
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?).

brebisson
Posts: 32
Joined: Fri Dec 22, 2023 9:44 am

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

Postby brebisson » Tue Jan 28, 2025 8:51 am

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

floitsch_toit
Posts: 29
Joined: Wed Jun 29, 2022 4:25 pm

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

Postby floitsch_toit » Tue Jan 28, 2025 9:25 am

brebisson wrote:
Mon Jan 27, 2025 4:14 pm
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.
brebisson wrote:
Mon Jan 27, 2025 4:14 pm
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.

MicroController
Posts: 2046
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Tue Jan 28, 2025 9:44 am

brebisson wrote:
Tue Jan 28, 2025 8:51 am
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.

floitsch_toit
Posts: 29
Joined: Wed Jun 29, 2022 4:25 pm

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

Postby floitsch_toit » Wed Jan 29, 2025 12:49 pm

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.

Who is online

Users browsing this forum: Bing [Bot], floitsch_toit, Google [Bot] and 116 guests