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

Ultrasonic hogs the CPU #634

Open
2 of 7 tasks
nostromo-1 opened this issue May 17, 2024 · 1 comment
Open
2 of 7 tasks

Ultrasonic hogs the CPU #634

nostromo-1 opened this issue May 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@nostromo-1
Copy link

The issue

The ultrasonic module makes use of a critical section (between PORT_ENTER_CRITICAL and PORT_EXIT_CRITICAL). Within it, it uses active loops (that is, while (gpio_get_level(dev->echo_pin))).

If a task is continuously making calls to ultrasonic_measure, as it stops interrupts, it affects other tasks, causing delays in them. The function ultrasonic_measure hogs the CPU for several millisseconds. This causes difficulties in other tasks that need precise timing.

A solution would be to use interrupts in the echo pin and RTOS notifications.

Which SDK are you using?

esp-idf

Which version of SDK are you using?

5.1.2

Which build target have you used?

  • esp32
  • esp32s2
  • esp32s3
  • esp32c2
  • esp8266
  • other

Component causing the issue

ultrasonic

Anything in the logs that might be useful for us?

I have tested an alternative approach with interrupts in the echo pin and RTOS notifications in the interrupt handler. It works correctly, it does not hog the CPU, and it maintains measuring accuracy.

Additional information or context

No response

Confirmation

  • This report is not a question nor a request for drivers.
@UncleRus UncleRus added the enhancement New feature or request label May 19, 2024
@nostromo-1
Copy link
Author

A possible implementation with interrupts and RTOS signals can be found here: https://github.com/nostromo-1/robotic-car-ESP32/blob/master/components/ultrasonic/ultrasonic.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants