Giter Site home page Giter Site logo

khoih-prog / esp32_pwm Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 9.0 170 KB

This library enables you to use Interrupt from Hardware Timers on an ESP32, ESP32_S2 or ESP32_C3-based board to create and output PWM to pins. It now supports 16 ISR-based synchronized PWM channels, while consuming only 1 Hardware Timer. PWM interval can be very long (uint32_t millisecs). The most important feature is they're ISR-based PWM channels. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware PWM channels, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.

License: MIT License

C++ 48.54% C 51.07% Shell 0.39%
esp32 esp32-s2 esp32-c3 timer-interrupt isr pwm pwm-driver multi-channel-pwm isr-based precise

esp32_pwm's People

Contributors

khoih-prog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

esp32_pwm's Issues

Example ISR_Modify_PWM.ino does not compile

Tried compiling the example and saw the following errors. Using ESP32 core versions 2.0.1 and 2.0.0 in Arduino IDE v1.8.16. I'm not sure if its my mistake or if the example is out of date?

Arduino: 1.8.16 (Mac OS X), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 115200, Core 1, Core 1, None"

/Users/kd/Documents/Arduino/esp32_libraries_test/esp32_libraries_test.ino: In function 'void setup()':
esp32_libraries_test:123:74: error: void value not ignored as it ought to be
channelNum = ISR_PWM.setPWM_Period(PWM_Pin, PWM_Period1, PWM_DutyCycle1);
^
/Users/kd/Documents/Arduino/esp32_libraries_test/esp32_libraries_test.ino: In function 'void changePWM()':
esp32_libraries_test:152:16: error: 'class ESP32_PWM' has no member named 'modifyPWMChannel'; did you mean 'setupPWMChannel'?
if (!ISR_PWM.modifyPWMChannel(channelNum, PWM_Pin, PWM_Freq, PWM_DutyCycle))
^~~~~~~~~~~~~~~~
setupPWMChannel
exit status 1
void value not ignored as it ought to be

tried to compile the simple array example

i get this error....

In file included from C:\Users\Fahr Radl\Documents\Arduino\esp32pwm\esp32pwm.ino:33:0:
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h: In member function 'bool ESP32TimerInterrupt::setFrequency(float, esp32_timer_callback)':
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:296:100: error: 'timer_isr_callback_add' was not declared in this scope
timer_isr_callback_add(_timerGroup, _timerIndex, _callback, (void *) (uint32_t) _timerNo, 0);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h: In member function 'void ESP32TimerInterrupt::detachInterrupt()':
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:338:66: error: 'TIMER_INTR_T0' was not declared in this scope
timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:338:82: error: 'TIMER_INTR_T1' was not declared in this scope
timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h: In member function 'void ESP32TimerInterrupt::disableTimer()':
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:347:66: error: 'TIMER_INTR_T0' was not declared in this scope
timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:347:82: error: 'TIMER_INTR_T1' was not declared in this scope
timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h: In member function 'void ESP32TimerInterrupt::reattachInterrupt()':
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:357:65: error: 'TIMER_INTR_T0' was not declared in this scope
timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:357:81: error: 'TIMER_INTR_T1' was not declared in this scope
timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h: In member function 'void ESP32TimerInterrupt::enableTimer()':
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:367:65: error: 'TIMER_INTR_T0' was not declared in this scope
timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
C:\Users\Fahr Radl\Documents\Arduino\libraries\ESP32_PWM\src/ESP32_PWM.h:367:81: error: 'TIMER_INTR_T1' was not declared in this scope
timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
^
exit status 1
Error compiling for board ESP32 Dev Module.

setting duty cycle to zero is not solid GND

Describe the bug

I used the ISR_16_PWMs_Array.ino and set duty cycle to zero. No matter on frequency connected LED is still partially on. It seems to me, that even set to zero, it is not solid ground.

Steps to Reproduce

Compile ISR_16_PWMs_Array.ino with duty cycle set to zero.

Expected behavior

Solid logical 0

Actual behavior

I have no osciloscope, but considering connected LED behavior, there is still duty cycle > 0 applied

Debug and AT-command log (if applicable)

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Information

  • Arduino IDE version 2.0.2
  • ESP32 Core Version ESP32 core v2.0.5
  • ESP32 ESP-32 Development Board

Question about 500Hz Maximum PWM Frequency

Hello, Thanks for creating a great library, particularly its non-blocking feature.

I understand controllers and interrupt driven timers but don't have experience with the ESP32 family to fully understand its features and limitations.

Do you see a problem with extending the maximum frequency from 500Hz to 1,000Hz?

My simple testing seems to suggest it works but I don't have access to an Oscilloscope at the moment to confirm both the frequency and waveform.

Could pwmDuty be given in microseconds instead of milliseconds? I need sub-millisecond duty cycles.

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like

A clear and concise description of what you want to happen.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.