- Notifications
You must be signed in to change notification settings - Fork0
This library enables you to use ISR-based PWM channels on an nRF52-based board using Adafruit_nRF52_Arduino core such as Itsy-Bitsy nRF52840 to create and output PWM any GPIO pin. It now supports 16 ISR-based PWM channels, while consuming only 1 Hardware Timer. PWM channel interval can be very long (ulong microsecs / millisecs). The most importa…
License
khoih-prog/nRF52_Slow_PWM
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- Important Change from v1.2.0
- Why do we need this nRF52_Slow_PWM library
- Changelog
- Prerequisites
- Installation
- Packages' Patches
- HOWTO Fix
Multiple DefinitionsLinker Error - Usage
- Examples
- Example ISR_16_PWMs_Array_Complex
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Please have a look atHOWTO FixMultiple Definitions Linker Error
As more complex calculation and checkinside ISR are introduced from v1.2.0, there is possibly some crash depending on use-case.
You can modify to use largerHW_TIMER_INTERVAL_US, (from current 10uS), according to your board and use-case if crash happens.
// Don't change these numbers to make higher Timer freq. System can hang#defineHW_TIMER_INTERVAL_US10L
Why do we need thisnRF52_Slow_PWM library
This library enables you to use ISR-based PWM channels on an nRF52-based board, such asItsy-Bitsy nRF52840, usingAdafruit nRF52 core core to create and output PWM any GPIO pin. Because this library doesn't use the powerful purely hardware-controlled PWM with many limitations, the maximum PWM frequency is currently limited at1000Hz, which is still suitable for many real-life applications. Now you can also modify PWM settings on-the-fly.
This library enables you to use Interrupt from Hardware Timers on nRF52-based boards 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 (uint64_t microsecs / 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 PWM using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.
AsHardware Timers are rare, and very precious assets of any board, this library now enables you to use up to16 ISR-based synchronized PWM channels, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs).
Now with these new16 ISR-based PWM-channels, the maximum interval ispractically unlimited (limited only by unsigned long milliseconds) whilethe accuracy is nearly perfect compared to software PWM channels.
The most important feature is they're ISR-based PWM channels. Therefore, their executions arenot blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks.
TheISR_16_PWMs_Array_Complex example will demonstrate the nearly perfect accuracy, compared to software PWM, by printing the actual period / duty-cycle inmicrosecs of each of PWM-channels.
Being ISR-based PWM, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet or Blynk services. You can also have many(up to 16) PWM channels to use.
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
You'll seesoftware-based SimpleTimer is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking taskin loop(), using delay() function as an example. The elapsed time then is very unaccurate
Imagine you have a system with amission-critical function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function isblocking the loop() or setup().
So your functionmight not be executed, and the result would be disastrous.
You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.).
The correct choice is to use a Hardware Timer withInterrupt to call your function.
These hardware PWM channels, using interrupt, still work even if other functions are blocking. Moreover, they are much moreprecise (certainly depending on clock frequency accuracy) than other software PWM channels using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.
Functions using normal software PWM channels, relying on loop() and calling millis(), won't work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
The catch isyour function is now part of an ISR (Interrupt Service Routine), and must be lean / mean, and follow certain rules. More to read on:
- AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox etc.
- Sparkfun Pro nRF52840 Mini
- Seeeduino nRF52840-based boards such as SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE, etc. using Seeeduino
nRF52core
Inside the attached function,delay() won’t work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare asvolatile any variables that you modify within the attached function.
Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.
Adafruit nRF52 v1.3.0+for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON,NINA_B302_ublox, etc.Seeeduino nRF52 core 1.0.0+for Seeeduino nRF52840-based boards such asSeeed_XIAO_NRF52840 and Seeed_XIAO_NRF52840_SENSE.To use with certain example
The best and easiest way is to useArduino Library Manager. Search fornRF52_Slow_PWM, then select / install the latest version.You can also use this link for more detailed instructions.
Another way to install is to:
- Navigate tonRF52_Slow_PWM page.
- Download the latest release
nRF52_Slow_PWM-main.zip. - Extract the zip file to
nRF52_Slow_PWM-maindirectory - Copy whole
nRF52_Slow_PWM-mainfolder to Arduino libraries' directory such as~/Arduino/libraries/.
- InstallVS Code
- InstallPlatformIO
- InstallnRF52_Slow_PWM library by usingLibrary Manager. Search fornRF52_Slow_PWM inPlatform.io Author's Libraries
- Use includedplatformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples atProject Configuration File
To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards, you have to copy the wholenRF52 1.3.0 directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0).
Supposing the Adafruit nRF52 version is 1.3.0. These files must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/platform.txt~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/boards.txt~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B302_ublox/variant.h~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B302_ublox/variant.cpp~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B112_ublox/variant.h~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B112_ublox/variant.cpp~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/cores/nRF5/Udp.h
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.zThese files must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/platform.txt~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/boards.txt~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B302_ublox/variant.h~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B302_ublox/variant.cpp~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.h~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.cpp~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h
To be able to compile and run on Xiao nRF52840 boards, you have to copy the wholenRF52 1.0.0 directory into Seeeduino nRF52 directory (~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0).
Supposing the Seeeduino nRF52 version is 1.0.0. These files must be copied into the directory:
~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Print.h~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Print.cpp~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Udp.h
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.zThese files must be copied into the directory:
~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Print.h~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Print.cpp~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h
To useSparkfun Pro nRF52840 Mini, you must installPackages_Patches and use Adafruit nrf52 core v1.0.0+
The current library implementation, usingxyz-Impl.h instead of standardxyz.cpp, possibly creates certainMultiple Definitions Linker error in certain use cases.
You can include this.hpp file
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error#include"nRF52_Slow_PWM.hpp"//https://github.com/khoih-prog/nRF52_Slow_PWM
in many files. But be sure to use the following.h filein just 1.h,.cpp or.ino file, which mustnot be included in any other file, to avoidMultiple Definitions Linker Error
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error#include"nRF52_Slow_PWM.h"//https://github.com/khoih-prog/nRF52_Slow_PWM
Check the newmultiFileProject example for aHOWTO demo.
Have a look at the discussion inDifferent behaviour using the src_cpp or src_h lib #80
Before using any Timer, you have to make sure the Timer has not been used by any other purpose. Depending on the board, you can select NRF52 Hardware Timer from NRF_TIMER_1-NRF_TIMER_4 (1 to 4)
// Depending on the board, you can select NRF52 Hardware Timer from NRF_TIMER_1-NRF_TIMER_4 (1 to 4)// If you select the already-used NRF_TIMER_0, it'll be auto modified to use NRF_TIMER_1// Init NRF52 timer NRF_TIMER2NRF52TimerITimer(NRF_TIMER_2);// Init nRF52_Slow_PWM, each can service 16 different ISR-based PWM channelsNRF52_Slow_PWM ISR_PWM;
voidirqCallbackStartFunc(){}voidirqCallbackStopFunc(){}voidsetup(){ ....// You can use this with PWM_Freq in Hz ISR_PWM.setPWM(PWM_Pin, PWM_Freq, PWM_DutyCycle, irqCallbackStartFunc, irqCallbackStopFunc); .... }
- ISR_16_PWMs_Array
- ISR_16_PWMs_Array_Complex
- ISR_16_PWMs_Array_Simple
- ISR_Changing_PWM
- ISR_Modify_PWM
- multiFileProjectNew
ExampleISR_16_PWMs_Array_Complex
nRF52_Slow_PWM/examples/ISR_16_PWMs_Array_Complex/ISR_16_PWMs_Array_Complex.ino
Lines 16 to 595 in2c86fbf
| // These define's must be placed at the beginning before #include "ESP32_PWM.h" | |
| // _PWM_LOGLEVEL_ from 0 to 4 | |
| // Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. | |
| #define_PWM_LOGLEVEL_3 | |
| #defineUSING_MICROS_RESOLUTIONtrue//false | |
| // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error | |
| #include"nRF52_Slow_PWM.h" | |
| #include<SimpleTimer.h>// https://github.com/jfturcot/SimpleTimer | |
| #defineLED_OFF HIGH | |
| #defineLED_ON LOW | |
| #ifndef LED_BUILTIN | |
| #defineLED_BUILTIN25 | |
| #endif | |
| #ifndef LED_BLUE_PIN | |
| #if defined(LED_BLUE) | |
| #defineLED_BLUE_PIN LED_BLUE | |
| #else | |
| #defineLED_BLUE_PIN7 | |
| #endif | |
| #endif | |
| #ifndef LED_GREEN_PIN | |
| #if defined(LED_GREEN) | |
| #defineLED_GREEN_PIN LED_GREEN | |
| #else | |
| #defineLED_GREEN_PIN8 | |
| #endif | |
| #endif | |
| #defineHW_TIMER_INTERVAL_US5L | |
| volatileuint64_t startMicros =0; | |
| // Depending on the board, you can select NRF52 Hardware Timer from NRF_TIMER_1-NRF_TIMER_4 (1 to 4) | |
| // If you select the already-used NRF_TIMER_0, it'll be auto modified to use NRF_TIMER_1 | |
| // Init NRF52 timer NRF_TIMER3 | |
| NRF52TimerITimer(NRF_TIMER_3); | |
| // Init nRF52_Slow_PWM, each can service 16 different ISR-based PWM channels | |
| NRF52_Slow_PWM ISR_PWM; | |
| ////////////////////////////////////////////////////// | |
| voidTimerHandler() | |
| { | |
| ISR_PWM.run(); | |
| } | |
| ///////////////////////////////////////////////// | |
| #defineNUMBER_ISR_PWMS16 | |
| #definePIN_D00 | |
| #definePIN_D11 | |
| #definePIN_D22 | |
| #definePIN_D33 | |
| #definePIN_D44 | |
| #definePIN_D55 | |
| #definePIN_D66 | |
| #definePIN_D77 | |
| #definePIN_D88 | |
| #definePIN_D99 | |
| #definePIN_D1010 | |
| #definePIN_D1111 | |
| #definePIN_D1212 | |
| typedefvoid (*irqCallback) (); | |
| ////////////////////////////////////////////////////// | |
| #defineUSE_COMPLEX_STRUCTtrue | |
| #defineUSING_PWM_FREQUENCYtrue | |
| ////////////////////////////////////////////////////// | |
| #if USE_COMPLEX_STRUCT | |
| typedefstruct | |
| { | |
| uint32_t PWM_Pin; | |
| irqCallback irqCallbackStartFunc; | |
| irqCallback irqCallbackStopFunc; | |
| #if USING_PWM_FREQUENCY | |
| float PWM_Freq; | |
| #else | |
| uint32_t PWM_Period; | |
| #endif | |
| float PWM_DutyCycle; | |
| uint64_t deltaMicrosStart; | |
| uint64_t previousMicrosStart; | |
| uint64_t deltaMicrosStop; | |
| uint64_t previousMicrosStop; | |
| } ISR_PWM_Data; | |
| // In nRF52, avoid doing something fancy in ISR, for example Serial.print() | |
| // The pure simple Serial.prints here are just for demonstration and testing. Must be eliminate in working environment | |
| // Or you can get this run-time error / crash | |
| voiddoingSomethingStart(int index); | |
| voiddoingSomethingStop(int index); | |
| #else// #if USE_COMPLEX_STRUCT | |
| volatileuint64_t deltaMicrosStart [] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; | |
| volatileuint64_t previousMicrosStart [] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; | |
| volatileuint64_t deltaMicrosStop [] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; | |
| volatileuint64_t previousMicrosStop [] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; | |
| // You can assign pins here. Be carefull to select good pin to use or crash, e.g pin 6-11 | |
| uint32_t PWM_Pin[] = | |
| { | |
| LED_BUILTIN, LED_BLUE_PIN, LED_GREEN_PIN, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4, | |
| PIN_D5, PIN_D6, PIN_D7, PIN_D8, PIN_D9, PIN_D10, PIN_D11, PIN_D12 | |
| }; | |
| // You can assign any interval for any timer here, in microseconds | |
| uint32_t PWM_Period[] = | |
| { | |
| 1000000L,500000L,333333L,250000L,200000L,166667L,142857L,125000L, | |
| 111111L,100000L,66667L,50000L,40000L,33333L,25000L,20000L | |
| }; | |
| // You can assign any interval for any timer here, in Hz | |
| float PWM_Freq[] = | |
| { | |
| 1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f, | |
| 9.0f,10.0f,15.0f,20.0f,25.0f,30.0f,40.0f,50.0f | |
| }; | |
| // You can assign any interval for any timer here, in milliseconds | |
| float PWM_DutyCycle[] = | |
| { | |
| 5.0,10.0,20.0,30.0,40.0,45.0,50.0,55.0, | |
| 60.0,65.0,70.0,75.0,80.0,85.0,90.0,95.0 | |
| }; | |
| voiddoingSomethingStart(int index) | |
| { | |
| uint64_t currentMicros =micros(); | |
| deltaMicrosStart[index] = currentMicros - previousMicrosStart[index]; | |
| previousMicrosStart[index] = currentMicros; | |
| } | |
| voiddoingSomethingStop(int index) | |
| { | |
| uint64_t currentMicros =micros(); | |
| // Count from start to stop PWM pulse | |
| deltaMicrosStop[index] = currentMicros - previousMicrosStart[index]; | |
| previousMicrosStop[index] = currentMicros; | |
| } | |
| #endif// #if USE_COMPLEX_STRUCT | |
| //////////////////////////////////// | |
| // Shared | |
| //////////////////////////////////// | |
| voiddoingSomethingStart0() | |
| { | |
| doingSomethingStart(0); | |
| } | |
| voiddoingSomethingStart1() | |
| { | |
| doingSomethingStart(1); | |
| } | |
| voiddoingSomethingStart2() | |
| { | |
| doingSomethingStart(2); | |
| } | |
| voiddoingSomethingStart3() | |
| { | |
| doingSomethingStart(3); | |
| } | |
| voiddoingSomethingStart4() | |
| { | |
| doingSomethingStart(4); | |
| } | |
| voiddoingSomethingStart5() | |
| { | |
| doingSomethingStart(5); | |
| } | |
| voiddoingSomethingStart6() | |
| { | |
| doingSomethingStart(6); | |
| } | |
| voiddoingSomethingStart7() | |
| { | |
| doingSomethingStart(7); | |
| } | |
| voiddoingSomethingStart8() | |
| { | |
| doingSomethingStart(8); | |
| } | |
| voiddoingSomethingStart9() | |
| { | |
| doingSomethingStart(9); | |
| } | |
| voiddoingSomethingStart10() | |
| { | |
| doingSomethingStart(10); | |
| } | |
| voiddoingSomethingStart11() | |
| { | |
| doingSomethingStart(11); | |
| } | |
| voiddoingSomethingStart12() | |
| { | |
| doingSomethingStart(12); | |
| } | |
| voiddoingSomethingStart13() | |
| { | |
| doingSomethingStart(13); | |
| } | |
| voiddoingSomethingStart14() | |
| { | |
| doingSomethingStart(14); | |
| } | |
| voiddoingSomethingStart15() | |
| { | |
| doingSomethingStart(15); | |
| } | |
| ////////////////////////////////////////////////////// | |
| voiddoingSomethingStop0() | |
| { | |
| doingSomethingStop(0); | |
| } | |
| voiddoingSomethingStop1() | |
| { | |
| doingSomethingStop(1); | |
| } | |
| voiddoingSomethingStop2() | |
| { | |
| doingSomethingStop(2); | |
| } | |
| voiddoingSomethingStop3() | |
| { | |
| doingSomethingStop(3); | |
| } | |
| voiddoingSomethingStop4() | |
| { | |
| doingSomethingStop(4); | |
| } | |
| voiddoingSomethingStop5() | |
| { | |
| doingSomethingStop(5); | |
| } | |
| voiddoingSomethingStop6() | |
| { | |
| doingSomethingStop(6); | |
| } | |
| voiddoingSomethingStop7() | |
| { | |
| doingSomethingStop(7); | |
| } | |
| voiddoingSomethingStop8() | |
| { | |
| doingSomethingStop(8); | |
| } | |
| voiddoingSomethingStop9() | |
| { | |
| doingSomethingStop(9); | |
| } | |
| voiddoingSomethingStop10() | |
| { | |
| doingSomethingStop(10); | |
| } | |
| voiddoingSomethingStop11() | |
| { | |
| doingSomethingStop(11); | |
| } | |
| voiddoingSomethingStop12() | |
| { | |
| doingSomethingStop(12); | |
| } | |
| voiddoingSomethingStop13() | |
| { | |
| doingSomethingStop(13); | |
| } | |
| voiddoingSomethingStop14() | |
| { | |
| doingSomethingStop(14); | |
| } | |
| voiddoingSomethingStop15() | |
| { | |
| doingSomethingStop(15); | |
| } | |
| ////////////////////////////////////////////////////// | |
| #if USE_COMPLEX_STRUCT | |
| #if USING_PWM_FREQUENCY | |
| ISR_PWM_Data curISR_PWM_Data[] = | |
| { | |
| // pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Freq, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop | |
| { LED_BUILTIN, doingSomethingStart0, doingSomethingStop0,1,5,0,0,0,0 }, | |
| { LED_BLUE_PIN, doingSomethingStart1, doingSomethingStop1,2,10,0,0,0,0 }, | |
| { LED_GREEN_PIN, doingSomethingStart2, doingSomethingStop2,3,20,0,0,0,0 }, | |
| { PIN_D0, doingSomethingStart3, doingSomethingStop3,4,30,0,0,0,0 }, | |
| { PIN_D1, doingSomethingStart4, doingSomethingStop4,5,40,0,0,0,0 }, | |
| { PIN_D2, doingSomethingStart5, doingSomethingStop5,6,45,0,0,0,0 }, | |
| { PIN_D3, doingSomethingStart6, doingSomethingStop6,7,50,0,0,0,0 }, | |
| { PIN_D4, doingSomethingStart7, doingSomethingStop7,8,55,0,0,0,0 }, | |
| { PIN_D5, doingSomethingStart8, doingSomethingStop8,9,60,0,0,0,0 }, | |
| { PIN_D6, doingSomethingStart9, doingSomethingStop9,10,65,0,0,0,0 }, | |
| { PIN_D7, doingSomethingStart10, doingSomethingStop10,15,70,0,0,0,0 }, | |
| { PIN_D8, doingSomethingStart11, doingSomethingStop11,20,75,0,0,0,0 }, | |
| { PIN_D9, doingSomethingStart12, doingSomethingStop12,25,80,0,0,0,0 }, | |
| { PIN_D10, doingSomethingStart13, doingSomethingStop13,30,85,0,0,0,0 }, | |
| { PIN_D11, doingSomethingStart14, doingSomethingStop14,40,90,0,0,0,0 }, | |
| { PIN_D12, doingSomethingStart15, doingSomethingStop15,50,95,0,0,0,0 } | |
| }; | |
| #else// #if USING_PWM_FREQUENCY | |
| ISR_PWM_Data curISR_PWM_Data[] = | |
| { | |
| // pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Period, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop | |
| { LED_BUILTIN, doingSomethingStart0, doingSomethingStop0,1000000L,5,0,0,0,0 }, | |
| { LED_BLUE_PIN, doingSomethingStart1, doingSomethingStop1,500000L,10,0,0,0,0 }, | |
| { LED_GREEN_PIN, doingSomethingStart2, doingSomethingStop2,333333L,20,0,0,0,0 }, | |
| { PIN_D0, doingSomethingStart3, doingSomethingStop3,250000L,30,0,0,0,0 }, | |
| { PIN_D1, doingSomethingStart4, doingSomethingStop4,200000L,40,0,0,0,0 }, | |
| { PIN_D2, doingSomethingStart5, doingSomethingStop5,166667L,45,0,0,0,0 }, | |
| { PIN_D3, doingSomethingStart6, doingSomethingStop6,142857L,50,0,0,0,0 }, | |
| { PIN_D4, doingSomethingStart7, doingSomethingStop7,125000L,55,0,0,0,0 }, | |
| { PIN_D5, doingSomethingStart8, doingSomethingStop8,111111L,60,0,0,0,0 }, | |
| { PIN_D6, doingSomethingStart9, doingSomethingStop9,100000L,65,0,0,0,0 }, | |
| { PIN_D7, doingSomethingStart10, doingSomethingStop10,66667L,70,0,0,0,0 }, | |
| { PIN_D8, doingSomethingStart11, doingSomethingStop11,50000L,75,0,0,0,0 }, | |
| { PIN_D9, doingSomethingStart12, doingSomethingStop12,40000L,80,0,0,0,0 }, | |
| { PIN_D10, doingSomethingStart13, doingSomethingStop13,33333L,85,0,0,0,0 }, | |
| { PIN_D11, doingSomethingStart14, doingSomethingStop14,25000L,90,0,0,0,0 }, | |
| { PIN_D12, doingSomethingStart15, doingSomethingStop15,20000L,95,0,0,0,0 } | |
| }; | |
| #endif// #if USING_PWM_FREQUENCY | |
| voiddoingSomethingStart(int index) | |
| { | |
| uint64_t currentMicros =micros(); | |
| curISR_PWM_Data[index].deltaMicrosStart = currentMicros - curISR_PWM_Data[index].previousMicrosStart; | |
| curISR_PWM_Data[index].previousMicrosStart = currentMicros; | |
| } | |
| voiddoingSomethingStop(int index) | |
| { | |
| uint64_t currentMicros =micros(); | |
| //curISR_PWM_Data[index].deltaMicrosStop = currentMicros - curISR_PWM_Data[index].previousMicrosStop; | |
| // Count from start to stop PWM pulse | |
| curISR_PWM_Data[index].deltaMicrosStop = currentMicros - curISR_PWM_Data[index].previousMicrosStart; | |
| curISR_PWM_Data[index].previousMicrosStop = currentMicros; | |
| } | |
| #else// #if USE_COMPLEX_STRUCT | |
| irqCallback irqCallbackStartFunc[] = | |
| { | |
| doingSomethingStart0, doingSomethingStart1, doingSomethingStart2, doingSomethingStart3, | |
| doingSomethingStart4, doingSomethingStart5, doingSomethingStart6, doingSomethingStart7, | |
| doingSomethingStart8, doingSomethingStart9, doingSomethingStart10, doingSomethingStart11, | |
| doingSomethingStart12, doingSomethingStart13, doingSomethingStart14, doingSomethingStart15 | |
| }; | |
| irqCallback irqCallbackStopFunc[] = | |
| { | |
| doingSomethingStop0, doingSomethingStop1, doingSomethingStop2, doingSomethingStop3, | |
| doingSomethingStop4, doingSomethingStop5, doingSomethingStop6, doingSomethingStop7, | |
| doingSomethingStop8, doingSomethingStop9, doingSomethingStop10, doingSomethingStop11, | |
| doingSomethingStop12, doingSomethingStop13, doingSomethingStop14, doingSomethingStop15 | |
| }; | |
| #endif// #if USE_COMPLEX_STRUCT | |
| ////////////////////////////////////////////////////// | |
| #defineSIMPLE_TIMER_MS2000L | |
| // Init SimpleTimer | |
| SimpleTimer simpleTimer; | |
| // Here is software Timer, you can do somewhat fancy stuffs without many issues. | |
| // But always avoid | |
| // 1. Long delay() it just doing nothing and pain-without-gain wasting CPU power.Plan and design your code / strategy ahead | |
| // 2. Very long "do", "while", "for" loops without predetermined exit time. | |
| voidsimpleTimerDoingSomething2s() | |
| { | |
| staticuint64_t previousMicrosStart = startMicros; | |
| uint64_t currMicros =micros(); | |
| Serial.print(F("SimpleTimer (ms):")); | |
| Serial.print(SIMPLE_TIMER_MS); | |
| Serial.print(F(", us :")); | |
| Serial.print(currMicros); | |
| Serial.print(F(", Dus :")); | |
| Serial.println(currMicros - previousMicrosStart); | |
| for (uint16_t i =0; i < NUMBER_ISR_PWMS; i++) | |
| { | |
| #if USE_COMPLEX_STRUCT | |
| Serial.print(F("PWM Channel :")); | |
| Serial.print(i); | |
| Serial.print(F(", programmed Period (us):")); | |
| #if USING_PWM_FREQUENCY | |
| Serial.print(1000000 / curISR_PWM_Data[i].PWM_Freq); | |
| #else | |
| Serial.print(curISR_PWM_Data[i].PWM_Period); | |
| #endif | |
| Serial.print(F(", actual :")); | |
| Serial.print(curISR_PWM_Data[i].deltaMicrosStart); | |
| Serial.print(F(", programmed DutyCycle :")); | |
| Serial.print(curISR_PWM_Data[i].PWM_DutyCycle); | |
| Serial.print(F(", actual :")); | |
| Serial.println((float) curISR_PWM_Data[i].deltaMicrosStop *100.0f / curISR_PWM_Data[i].deltaMicrosStart); | |
| #else | |
| Serial.print(F("PWM Channel :")); | |
| Serial.print(i); | |
| #if USING_PWM_FREQUENCY | |
| Serial.print(1000000 / PWM_Freq[i]); | |
| #else | |
| Serial.print(PWM_Period[i]); | |
| #endif | |
| Serial.print(F(", programmed Period (us):")); | |
| Serial.print(PWM_Period[i]); | |
| Serial.print(F(", actual :")); | |
| Serial.print(deltaMicrosStart[i]); | |
| Serial.print(F(", programmed DutyCycle :")); | |
| Serial.print(PWM_DutyCycle[i]); | |
| Serial.print(F(", actual :")); | |
| Serial.println( (float) deltaMicrosStop[i] *100.0f / deltaMicrosStart[i]); | |
| #endif | |
| } | |
| previousMicrosStart = currMicros; | |
| } | |
| voidsetup() | |
| { | |
| Serial.begin(115200); | |
| while (!Serial &&millis() <5000); | |
| delay(2000); | |
| Serial.print(F("\nStarting ISR_16_PWMs_Array_Complex on")); | |
| Serial.println(BOARD_NAME); | |
| Serial.println(NRF52_SLOW_PWM_VERSION); | |
| // Interval in microsecs | |
| if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US, TimerHandler)) | |
| { | |
| Serial.print(F("Starting ITimer OK, micros() =")); | |
| Serial.println(startMicros); | |
| } | |
| else | |
| Serial.println(F("Can't set ITimer. Select another freq. or timer")); | |
| startMicros =micros(); | |
| // Just to demonstrate, don't use too many ISR Timers if not absolutely necessary | |
| // You can use up to 16 timer for each ISR_PWM | |
| for (uint16_t i =0; i < NUMBER_ISR_PWMS; i++) | |
| { | |
| #if USE_COMPLEX_STRUCT | |
| curISR_PWM_Data[i].previousMicrosStart = startMicros; | |
| //ISR_PWM.setInterval(curISR_PWM_Data[i].PWM_Period, curISR_PWM_Data[i].irqCallbackStartFunc); | |
| //void setPWM(uint32_t pin, float frequency, float dutycycle | |
| // , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr) | |
| #if USING_PWM_FREQUENCY | |
| // You can use this with PWM_Freq in Hz | |
| ISR_PWM.setPWM(curISR_PWM_Data[i].PWM_Pin, curISR_PWM_Data[i].PWM_Freq, curISR_PWM_Data[i].PWM_DutyCycle, | |
| curISR_PWM_Data[i].irqCallbackStartFunc, curISR_PWM_Data[i].irqCallbackStopFunc); | |
| #else | |
| // Or You can use this with PWM_Period in us | |
| ISR_PWM.setPWM_Period(curISR_PWM_Data[i].PWM_Pin, curISR_PWM_Data[i].PWM_Period, curISR_PWM_Data[i].PWM_DutyCycle, | |
| curISR_PWM_Data[i].irqCallbackStartFunc, curISR_PWM_Data[i].irqCallbackStopFunc); | |
| #endif | |
| #else | |
| previousMicrosStart[i] =micros(); | |
| #if USING_PWM_FREQUENCY | |
| // You can use this with PWM_Freq in Hz | |
| ISR_PWM.setPWM(PWM_Pin[i], PWM_Freq[i], PWM_DutyCycle[i], irqCallbackStartFunc[i], irqCallbackStopFunc[i]); | |
| #else | |
| // Or You can use this with PWM_Period in us | |
| ISR_PWM.setPWM_Period(PWM_Pin[i], PWM_Period[i], PWM_DutyCycle[i], irqCallbackStartFunc[i], irqCallbackStopFunc[i]); | |
| #endif | |
| #endif | |
| } | |
| // You need this timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary. | |
| simpleTimer.setInterval(SIMPLE_TIMER_MS, simpleTimerDoingSomething2s); | |
| } | |
| #defineBLOCKING_TIME_MS10000L | |
| voidloop() | |
| { | |
| // This unadvised blocking task is used to demonstrate the blocking effects onto the execution and accuracy to Software timer | |
| // You see the time elapse of ISR_PWM still accurate, whereas very unaccurate for Software Timer | |
| // The time elapse for 2000ms software timer now becomes 3000ms (BLOCKING_TIME_MS) | |
| // While that of ISR_PWM is still prefect. | |
| delay(BLOCKING_TIME_MS); | |
| // You need this Software timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary | |
| // You don't need to and never call ISR_PWM.run() here in the loop(). It's already handled by ISR timer. | |
| simpleTimer.run(); | |
| } |
The following is the sample terminal output when running exampleISR_16_PWMs_Array_Complex to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels,especially when system is very busy. The ISR PWM-channels isrunning exactly according to corresponding programmed periods and duty-cycles
Starting ISR_16_PWMs_Array_Complex on NRF52840_ITSYBITSYNRF52_Slow_PWM v1.2.2[PWM] NRF52TimerInterrupt: Timer = NRF_TIMER3 , Timer Clock (Hz) = 16000000.00[PWM] Frequency = 200000.00 , _count = 80Starting ITimer OK, micros() = Channel : 0 Period : 1000000OnTime : 49999Start_Time : 2647460Channel : 1 Period : 500000OnTime : 49999Start_Time : 2648437Channel : 2 Period : 333333OnTime : 66666Start_Time : 2649414Channel : 3 Period : 250000OnTime : 74999Start_Time : 2650390Channel : 4 Period : 200000OnTime : 79999Start_Time : 2651367Channel : 5 Period : 166666OnTime : 74999Start_Time : 2652343Channel : 6 Period : 142857OnTime : 71428Start_Time : 2653320Channel : 7 Period : 125000OnTime : 68750Start_Time : 2654296Channel : 8 Period : 111111OnTime : 66666Start_Time : 2655273Channel : 9 Period : 100000OnTime : 64999Start_Time : 2656250Channel : 10 Period : 66666OnTime : 46666Start_Time : 2657226Channel : 11 Period : 50000OnTime : 37500Start_Time : 2658203Channel : 12 Period : 40000OnTime : 31999Start_Time : 2659179Channel : 13 Period : 33333OnTime : 28333Start_Time : 2660156Channel : 14 Period : 25000OnTime : 22500Start_Time : 2661132Channel : 15 Period : 20000OnTime : 19000Start_Time : 2663085SimpleTimer (ms): 2000, us : 12805664, Dus : 10159180PWM Channel : 0, programmed Period (us): 1000000.00, actual : 1000000, programmed DutyCycle : 5.00, actual : 5.18PWM Channel : 1, programmed Period (us): 500000.00, actual : 496094, programmed DutyCycle : 10.00, actual : 10.24PWM Channel : 2, programmed Period (us): 333333.34, actual : 340820, programmed DutyCycle : 20.00, actual : 19.20PWM Channel : 3, programmed Period (us): 250000.00, actual : 250000, programmed DutyCycle : 30.00, actual : 31.25PWM Channel : 4, programmed Period (us): 200000.00, actual : 205078, programmed DutyCycle : 40.00, actual : 37.14PWM Channel : 5, programmed Period (us): 166666.67, actual : 171875, programmed DutyCycle : 45.00, actual : 42.05PWM Channel : 6, programmed Period (us): 142857.14, actual : 147461, programmed DutyCycle : 50.00, actual : 47.02PWM Channel : 7, programmed Period (us): 125000.00, actual : 122070, programmed DutyCycle : 55.00, actual : 56.80PWM Channel : 8, programmed Period (us): 111111.11, actual : 107422, programmed DutyCycle : 60.00, actual : 60.91PWM Channel : 9, programmed Period (us): 100000.00, actual : 106446, programmed DutyCycle : 65.00, actual : 58.72PWM Channel : 10, programmed Period (us): 66666.66, actual : 64453, programmed DutyCycle : 70.00, actual : 69.70PWM Channel : 11, programmed Period (us): 50000.00, actual : 47851, programmed DutyCycle : 75.00, actual : 73.47PWM Channel : 12, programmed Period (us): 40000.00, actual : 37110, programmed DutyCycle : 80.00, actual : 78.95PWM Channel : 13, programmed Period (us): 33333.33, actual : 30273, programmed DutyCycle : 85.00, actual : 96.78PWM Channel : 14, programmed Period (us): 25000.00, actual : 25390, programmed DutyCycle : 90.00, actual : 92.31PWM Channel : 15, programmed Period (us): 20000.00, actual : 20508, programmed DutyCycle : 95.00, actual : 95.24SimpleTimer (ms): 2000, us : 22888671, Dus : 10083007PWM Channel : 0, programmed Period (us): 1000000.00, actual : 1002929, programmed DutyCycle : 5.00, actual : 4.77PWM Channel : 1, programmed Period (us): 500000.00, actual : 505859, programmed DutyCycle : 10.00, actual : 9.46PWM Channel : 2, programmed Period (us): 333333.34, actual : 333985, programmed DutyCycle : 20.00, actual : 20.18PWM Channel : 3, programmed Period (us): 250000.00, actual : 254883, programmed DutyCycle : 30.00, actual : 28.35PWM Channel : 4, programmed Period (us): 200000.00, actual : 200195, programmed DutyCycle : 40.00, actual : 40.00PWM Channel : 5, programmed Period (us): 166666.67, actual : 166992, programmed DutyCycle : 45.00, actual : 45.03PWM Channel : 6, programmed Period (us): 142857.14, actual : 140625, programmed DutyCycle : 50.00, actual : 52.08PWM Channel : 7, programmed Period (us): 125000.00, actual : 130859, programmed DutyCycle : 55.00, actual : 52.99PWM Channel : 8, programmed Period (us): 111111.11, actual : 116211, programmed DutyCycle : 60.00, actual : 57.98PWM Channel : 9, programmed Period (us): 100000.00, actual : 100586, programmed DutyCycle : 65.00, actual : 65.05PWM Channel : 10, programmed Period (us): 66666.66, actual : 71289, programmed DutyCycle : 70.00, actual : 60.27PWM Channel : 11, programmed Period (us): 50000.00, actual : 47851, programmed DutyCycle : 75.00, actual : 77.55PWM Channel : 12, programmed Period (us): 40000.00, actual : 36133, programmed DutyCycle : 80.00, actual : 81.08PWM Channel : 13, programmed Period (us): 33333.33, actual : 31250, programmed DutyCycle : 85.00, actual : 84.37PWM Channel : 14, programmed Period (us): 25000.00, actual : 76172, programmed DutyCycle : 90.00, actual : 97.43PWM Channel : 15, programmed Period (us): 20000.00, actual : 20508, programmed DutyCycle : 95.00, actual : 95.24SimpleTimer (ms): 2000, us : 32927734, Dus : 10039063PWM Channel : 0, programmed Period (us): 1000000.00, actual : 1000000, programmed DutyCycle : 5.00, actual : 5.08PWM Channel : 1, programmed Period (us): 500000.00, actual : 496094, programmed DutyCycle : 10.00, actual : 10.24PWM Channel : 2, programmed Period (us): 333333.34, actual : 337891, programmed DutyCycle : 20.00, actual : 18.79PWM Channel : 3, programmed Period (us): 250000.00, actual : 250000, programmed DutyCycle : 30.00, actual : 30.47PWM Channel : 4, programmed Period (us): 200000.00, actual : 196289, programmed DutyCycle : 40.00, actual : 39.80PWM Channel : 5, programmed Period (us): 166666.67, actual : 171875, programmed DutyCycle : 45.00, actual : 42.05PWM Channel : 6, programmed Period (us): 142857.14, actual : 148438, programmed DutyCycle : 50.00, actual : 46.71PWM Channel : 7, programmed Period (us): 125000.00, actual : 125000, programmed DutyCycle : 55.00, actual : 53.12PWM Channel : 8, programmed Period (us): 111111.11, actual : 107422, programmed DutyCycle : 60.00, actual : 59.09PWM Channel : 9, programmed Period (us): 100000.00, actual : 97656, programmed DutyCycle : 65.00, actual : 64.00PWM Channel : 10, programmed Period (us): 66666.66, actual : 63477, programmed DutyCycle : 70.00, actual : 69.23PWM Channel : 11, programmed Period (us): 50000.00, actual : 46875, programmed DutyCycle : 75.00, actual : 72.92PWM Channel : 12, programmed Period (us): 40000.00, actual : 40039, programmed DutyCycle : 80.00, actual : 80.49PWM Channel : 13, programmed Period (us): 33333.33, actual : 33204, programmed DutyCycle : 85.00, actual : 88.23PWM Channel : 14, programmed Period (us): 25000.00, actual : 25391, programmed DutyCycle : 90.00, actual : 92.31PWM Channel : 15, programmed Period (us): 20000.00, actual : 20507, programmed DutyCycle : 95.00, actual : 95.24The following is the sample terminal output when running exampleISR_16_PWMs_Array onnRF52-based NRF52840_ITSYBITSY to demonstrate how to use multiple PWM channels with simple callback functions.
Starting ISR_16_PWMs_Array on NRF52840_ITSYBITSYNRF52_Slow_PWM v1.2.2[PWM] NRF52TimerInterrupt: Timer = NRF_TIMER2 , Timer Clock (Hz) = 16000000.00[PWM] Frequency = 50000.00 , _count = 320Starting ITimer OK, micros() = 2889648Channel : 0 Period : 1000000OnTime : 49999Start_Time : 2890625Channel : 1 Period : 500000OnTime : 49999Start_Time : 2890625Channel : 2 Period : 333333OnTime : 66666Start_Time : 2891601Channel : 3 Period : 250000OnTime : 74999Start_Time : 2891601Channel : 4 Period : 200000OnTime : 79999Start_Time : 2892578Channel : 5 Period : 166666OnTime : 74999Start_Time : 2893554Channel : 6 Period : 142857OnTime : 71428Start_Time : 2893554Channel : 7 Period : 125000OnTime : 68750Start_Time : 2894531Channel : 8 Period : 111111OnTime : 66666Start_Time : 2894531Channel : 9 Period : 100000OnTime : 64999Start_Time : 2895507Channel : 10 Period : 66666OnTime : 46666Start_Time : 2895507Channel : 11 Period : 50000OnTime : 37500Start_Time : 2896484Channel : 12 Period : 40000OnTime : 31999Start_Time : 2897460Channel : 13 Period : 33333OnTime : 28333Start_Time : 2897460Channel : 14 Period : 25000OnTime : 22500Start_Time : 2898437Channel : 15 Period : 20000OnTime : 19000Start_Time : 2898437The following is the sample terminal output when running exampleISR_16_PWMs_Array_Simple onnRF52-based NRF52840_ITSYBITSY to demonstrate how to use multiple PWM channels.
Starting ISR_16_PWMs_Array_Simple on NRF52840_ITSYBITSYNRF52_Slow_PWM v1.2.2[PWM] NRF52TimerInterrupt: Timer = NRF_TIMER2 , Timer Clock (Hz) = 16000000.00[PWM] Frequency = 50000.00 , _count = 320Starting ITimer OK, micros() = 2924804Channel : 0 Period : 1000000OnTime : 49999Start_Time : 2925781Channel : 1 Period : 500000OnTime : 49999Start_Time : 2925781Channel : 2 Period : 333333OnTime : 66666Start_Time : 2926757Channel : 3 Period : 250000OnTime : 74999Start_Time : 2927734Channel : 4 Period : 200000OnTime : 79999Start_Time : 2927734Channel : 5 Period : 166666OnTime : 74999Start_Time : 2928710Channel : 6 Period : 142857OnTime : 71428Start_Time : 2928710Channel : 7 Period : 125000OnTime : 68750Start_Time : 2929687Channel : 8 Period : 111111OnTime : 66666Start_Time : 2929687Channel : 9 Period : 100000OnTime : 64999Start_Time : 2930664Channel : 10 Period : 66666OnTime : 46666Start_Time : 2930664Channel : 11 Period : 50000OnTime : 37500Start_Time : 2931640Channel : 12 Period : 40000OnTime : 31999Start_Time : 2931640Channel : 13 Period : 33333OnTime : 28333Start_Time : 2932617Channel : 14 Period : 25000OnTime : 22500Start_Time : 2933593Channel : 15 Period : 20000OnTime : 19000Start_Time : 2933593The following is the sample terminal output when running exampleISR_Modify_PWM onnRF52-based NRF52840_ITSYBITSY to demonstrate how to modify PWM settings on-the-fly without deleting the PWM channel
Starting ISR_Modify_PWM on NRF52840_ITSYBITSYNRF52_Slow_PWM v1.2.2[PWM] NRF52TimerInterrupt: Timer = NRF_TIMER2 , Timer Clock (Hz) = 16000000.00[PWM] Frequency = 50000.00 , _count = 320Starting ITimer OK, micros() = 3310546Using PWM Freq = 200.00, PWM DutyCycle = 1.00Channel : 0 Period : 5000OnTime : 50Start_Time : 3311523Channel : 0 Period : 10000OnTime : 555Start_Time : 13313476Channel : 0 Period : 5000OnTime : 50Start_Time : 23309570Channel : 0 Period : 10000OnTime : 555Start_Time : 33310546Channel : 0 Period : 5000OnTime : 50Start_Time : 43306640Channel : 0 Period : 10000OnTime : 555Start_Time : 53313476Channel : 0 Period : 5000OnTime : 50Start_Time : 63309570Channel : 0 Period : 10000OnTime : 555Start_Time : 73316406Channel : 0 Period : 5000OnTime : 50Start_Time : 83312500Channel : 0 Period : 10000OnTime : 555Start_Time : 93319335Channel : 0 Period : 5000OnTime : 50Start_Time : 103315429Channel : 0 Period : 10000OnTime : 555Start_Time : 113322265Channel : 0 Period : 5000OnTime : 50Start_Time : 123318359Channel : 0 Period : 10000OnTime : 555Start_Time : 133325195Channel : 0 Period : 5000OnTime : 50Start_Time : 143326171Channel : 0 Period : 10000OnTime : 555Start_Time : 153322265Channel : 0 Period : 5000OnTime : 50Start_Time : 163318359Channel : 0 Period : 10000OnTime : 555Start_Time : 173325195Channel : 0 Period : 5000OnTime : 50Start_Time : 183321289Channel : 0 Period : 10000OnTime : 555Start_Time : 193328125Channel : 0 Period : 5000OnTime : 50Start_Time : 203324218Channel : 0 Period : 10000OnTime : 555Start_Time : 213331054Channel : 0 Period : 5000OnTime : 50Start_Time : 223327148Channel : 0 Period : 10000OnTime : 555Start_Time : 233333984The following is the sample terminal output when running exampleISR_Changing_PWM onnRF52-based NRF52840_ITSYBITSY to demonstrate how to modify PWM settings on-the-fly by deleting the PWM channel and reinit the PWM channel
Starting ISR_Changing_PWM on NRF52840_ITSYBITSYNRF52_Slow_PWM v1.2.2[PWM] NRF52TimerInterrupt: Timer = NRF_TIMER2 , Timer Clock (Hz) = 16000000.00[PWM] Frequency = 50000.00 , _count = 320Starting ITimer OK, micros() = 2925781Using PWM Freq = 1.00, PWM DutyCycle = 50.00Channel : 0 Period : 1000000OnTime : 500000Start_Time : 2926757Using PWM Freq = 2.00, PWM DutyCycle = 90.00Channel : 0 Period : 500000OnTime : 450000Start_Time : 18140625Using PWM Freq = 1.00, PWM DutyCycle = 50.00Channel : 0 Period : 1000000OnTime : 500000Start_Time : 33396484Using PWM Freq = 2.00, PWM DutyCycle = 90.00Channel : 0 Period : 500000OnTime : 450000Start_Time : 48607421Using PWM Freq = 1.00, PWM DutyCycle = 50.00Channel : 0 Period : 1000000OnTime : 500000Start_Time : 63864257Using PWM Freq = 2.00, PWM DutyCycle = 90.00Channel : 0 Period : 500000OnTime : 450000Start_Time : 79079101Using PWM Freq = 1.00, PWM DutyCycle = 50.00Channel : 0 Period : 1000000OnTime : 500000Start_Time : 94331054Using PWM Freq = 2.00, PWM DutyCycle = 90.00Channel : 0 Period : 500000OnTime : 450000Start_Time : 109539062Debug is enabled by default on Serial.
You can also change the debugging level_PWM_LOGLEVEL_ from 0 to 4
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.#define_PWM_LOGLEVEL_0
If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.
Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.
Submit issues to:nRF52_Slow_PWM issues
- Search for bug and improvement.
- Similar features for remaining Arduino boards
- Basic hardware multi-channel PWM fornRF52-based AdaFruit Itsy-Bitsy nRF52840, Feather nRF52840 Express, etc. using
Adafruit nRF52 core - Add Table of Contents
- Add functions to modify PWM settings on-the-fly
- Fix
multiple-definitionslinker error - Optimize library code by using
reference-passinginstead ofvalue-passing - Improve accuracy by using
float, instead ofuint32_tfordutycycle - DutyCycle to be optionally updated at the end current PWM period instead of immediately.
- Display informational warning only when
_PWM_LOGLEVEL_> 3 - Add support to
Sparkfun Pro nRF52840 Mini - Add support to Seeeduino nRF52840-based boards such asSEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE, etc. using Seeeduino
nRF52core - Add astyle using
allmanstyle. Restyle the library - Add
Packages' Patchesto add SeeeduinonRF52core
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed underMIT
Copyright 2021- Khoi Hoang
About
This library enables you to use ISR-based PWM channels on an nRF52-based board using Adafruit_nRF52_Arduino core such as Itsy-Bitsy nRF52840 to create and output PWM any GPIO pin. It now supports 16 ISR-based PWM channels, while consuming only 1 Hardware Timer. PWM channel interval can be very long (ulong microsecs / millisecs). The most importa…
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
