Skip to content

ESP32-S2: Add PulseOut and PulseIn #3279

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

Merged
merged 6 commits into from
Aug 20, 2020
Merged

ESP32-S2: Add PulseOut and PulseIn #3279

merged 6 commits into from
Aug 20, 2020

Conversation

hierophect
Copy link
Collaborator

This PR adds the PulseOut and PulseIn IR transmission and reception modules to the ESP32-S2 port. Unlike other ports, which transmit pulse trains using timers and PWMOut carrier objects, the ESP32-S2 has a dedicated pulse train peripheral, the "RMT", which is capable of both sending and receiving pulses with and without carrier modulation.

Because of this, PulseOut does not require a PWMOut object, which uses an entirely different peripheral, the LEDC PWM controller. Thus, the API for PulseOut has been expanded to allow the ESP32 to receive a pin object, frequency and duty cycle in place of a PWMOut object. Other ports have been correspondingly internally updated for the change, but should see no difference in their python calls for the time being.

PulseIn has a couple of quirks that should be noted when reviewing.

  • The RMT does not acknowledge or store any detected pulses until a certain "idle period" of no activity is met. I've set this to 90ms, which seemed like a practical value, but it does mean that long pulse trains with no breaks at all will not be acknowledged by the ESP32 - I'm not sure if this is an issue.
  • The internal timing and storage of the RMT required that I slow the clock down by 3x in order to accommodate pulses of 65ms, which are common in the module's examples on ReadTheDocs and Learn. Pulses are thus delivered as smaller numbers from the RMT internally, and then multiplied by 3x before being returned.
  • The RMT has no real sense of "idle state", using the idle period threshold to detect the start of a pulse train. I've set this by using pullups so the trigger pulse is meaningful, but I'm not sure if more work needs to be done there.

The RMT is shared by the Neopixel Write system. A mediator system in Peripherals reserves RMT channels individually. Up to 4 channels are available on any pin, so you can have a combination of 4 total PulseOut, PulseIn, and Neopixel lines active at any given time.

Tested on the ESP32-S2 Saola1 Wrover. Resolves #3264

@hierophect hierophect added the espressif applies to multiple Espressif chips label Aug 14, 2020
@hierophect hierophect requested review from tannewt and dhalbert August 14, 2020 20:51
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this! Just a few corner cases to think about.

@hierophect hierophect requested a review from tannewt August 18, 2020 15:42
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to make the builds pass and then should be good. Thanks!

@hierophect hierophect requested a review from tannewt August 18, 2020 21:25
@hierophect
Copy link
Collaborator Author

@tannewt I think this should be good to go.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks great.

@tannewt tannewt merged commit 4007010 into adafruit:main Aug 20, 2020
@hierophect hierophect deleted the esp32-pulseinout branch September 21, 2020 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
espressif applies to multiple Espressif chips
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor PulseOut to not take PWMOut as parameter
2 participants