-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Unable to Use PWM & GPIO.PULSE Concurrently #2494
Comments
As far as I understand: pwm, pcm, sigma-delta, switec, somfy, perf modules and gpio.pulse.*, gpio.serout functions of gpio module share the same hardware timer (FRC1) available in esp8266. There is a second timer (see FRC2_COUNT_ADDRESS in eagle_soc.h), but it is not documented, except in app/pm/swtimer.c and app/include/rtc/rtctime_internal.h. |
@pjsg Is there any way possible to use Not being able to generate a variable PWM signal and a set of fixed frequency PULSE signals using the ESP8266 is a real show stopper for me. |
The problem here is that there is a single hardware timer that is used for both of these modules. The current code does not support more than one use of the timer at the same time, so one module wins and the other loses. [There are also other modules that make use of the hardware timer that run into the same problem.] Having said that, it ought to be reasonably easy to build a layer on top of the existing hardware timer to allow use by multiple modules. When we started out on using the hardware timers, we decided not to build this layern -- mostly to keep the code simple. I would certainly look favorably on a PR to fix this. The relevant code is in app/platform/hw_timer.c -- there are probably five APIs that would need to be changed: platform_hw_timer_arm_*, platform_hw_timer_set_func, platform_hw_timer_get_delay_ticks, platform_hw_timer_init, platform_hw_timer_close. Happily, each of them takes a module ID as an argument, so the implementation could be changed to support multiple modules without needing to change any of the modules. |
-- Understood.
-- This statement needs to be expressed in the docs for each of the modules in scope.
-- Would it be possible for you or one of the other crack firmware collaborators / contributors to whip this up? I lack the intimate firmware knowledge and C skills to pull it off myself. |
It also turned out that gpio.pulse and pwm used the same 'unique' timer id which caused other problems. |
@pjsg You rock. This is very much appreciated. I anxiously await the |
@pjsg FYI: I grabbed a copy of |
Thank you for that test. It implies that the code works on at least two boards! Seriously, if you find any strangeness, then please let me know. |
@marcelstoer @pjsg Did this make the latest |
Expected behavior
Use PWM and GPIO.PULSE modules concurrently.
Actual behavior
Coding for both (first PWM then GPIO.PULSE) causes PWM output to stop (output remains HIGH), GPIO.PULSE output works as expected.
Test code
NodeMCU version
NodeMCU 2.2.0.0 built with Docker provided by frightanic.com
branch: master
commit: 3661b8d
SSL: false
Build type: float
LFS: disabled
modules: adc,bit,file,gpio,gpio_pulse,i2c,net,node,pwm,rtctime,tmr,uart,websocket,wifi
build created on 2018-09-20 09:40
powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
Hardware
Amica / AI-Thinker ESP8266 ESP-12E Development Board
Attachments
PWM1 Code Only - PWM1 Output:
PULSE Code Only - PULSE1 Output:
PWM+PULSE Code - PWM1 Output:
PWM+PULSE Code - PULSE1 Output:
[ ping @pjsg ]
The text was updated successfully, but these errors were encountered: