Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulseio.PulseIn maxlen is limited to 128 in esp32 #9234

Open
tkomde opened this issue May 10, 2024 · 3 comments
Open

pulseio.PulseIn maxlen is limited to 128 in esp32 #9234

tkomde opened this issue May 10, 2024 · 3 comments
Labels
bug espressif applies to multiple Espressif chips pulseio
Milestone

Comments

@tkomde
Copy link

tkomde commented May 10, 2024

CircuitPython version

Adafruit CircuitPython 9.1.0-beta.1-18-g781c577745-dirty on 2024-05-10; M5Stack AtomS3 with ESP32S3

Code/REPL

import board
import pulseio
import adafruit_irremote

pulsein = pulseio.PulseIn(board.D1, maxlen=1020, idle_state=True)
decoder = adafruit_irremote.GenericDecode()

while True:
    pulses = decoder.read_pulses(pulsein,max_pulse=91000)
    print(len(pulses))

Behavior

prints "128"

Description

It is possible that this is an intended specification, but I am reporting it.

I have a HITACHI air conditioner remote control data (848+6 data length) being read by pulseio.pulseIn. Regardless of the maxlen I gave it, it only read a maximum of 128 data.

I looked into the cause and found the following code in ports/espressif/common-hal/pulseio/PulseIn.c#103 .

self->raw_symbols_size = MIN(64, maxlen / 2 + 1) * sizeof(rmt_symbol_word_t);

When I delete the MIN(64, x) calculation as follows, the behavior differed depending on the CPU.
The ESP32S3(M5 AtomS3) and ESP32C6(M5 NanoC6) received all 854 data as desired, but the ESP32-PICO(M5 Matrix) still had 128 data. This seems to reproduce #7352.

self->raw_symbols_size = (maxlen / 2 + 1) * sizeof(rmt_symbol_word_t);

Is MIN(64, x) required by some constraint? If almost esp32 chips can receive more data, I would like to receive it.

Additional information

No response

@tkomde tkomde added the bug label May 10, 2024
@dhalbert dhalbert added this to the Support milestone May 13, 2024
@dhalbert dhalbert added pulseio esp32 espressif applies to multiple Espressif chips and removed esp32 labels May 13, 2024
@dhalbert dhalbert modified the milestones: Support, 9.x.x May 13, 2024
@dhalbert
Copy link
Collaborator

SOC_RMT_MEM_WORDS_PER_CHANNEL, which is used in PulseIn.c, varies per processor. However, on the ESP32, it is 64, and on ESP32-S3 and C6, it is 48. Not sure what to make of that, given your test results above.

@tannewt
Copy link
Member

tannewt commented May 13, 2024

Its been a little while since I wrote this code. I think my intent was to limit the maxlen to the amount the RMT peripheral can buffer. I didn't want to assume PSRAM was accessible when PulseIn was running. (Writing the filesystem will disable it temporarily.)

I think some RMTs can use multiple channels worth of memory if needed. That could improve things.

Note each RMT word stores two "pulses" one active and one inactive. That's why 64 words give a length of 128.

@tkomde
Copy link
Author

tkomde commented May 13, 2024

@dhalbert

Thanks for your comment.

This is a difficult area to understand for me, but I found an article that might be relevant. It seems that chips with the feature SOC_RMT_SUPPORT_RX_PINGPONG can handle more data than buffers.

https://esp32.com/viewtopic.php?t=24484

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug espressif applies to multiple Espressif chips pulseio
Projects
None yet
Development

No branches or pull requests

3 participants