diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9a62029..e328734 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
-* Arduino / Adafruit / Sparkfun `AVR` Core Version (e.g. Arduino AVR core v1.8.3)
+* Arduino / Adafruit / Sparkfun `AVR` Core Version (e.g. Arduino AVR core v1.8.5)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
@@ -27,9 +27,9 @@ Please ensure to specify the following:
```
Arduino IDE version: 1.8.19
-Arduino AVR core v1.8.3
+Arduino AVR core v1.8.5
OS: Ubuntu 20.04 LTS
-Linux xy-Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
+Linux xy-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while trying to use the Timer Interrupt.
diff --git a/README.md b/README.md
index 285d97a..8015b4a 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,9 @@
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AVR_Slow_PWM.svg)](http://github.com/khoih-prog/AVR_Slow_PWM/issues)
+
+
+
---
---
@@ -132,7 +135,7 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
## Prerequisites
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest)
- 2. [`Arduino AVR core 1.8.3+`](https://github.com/arduino/ArduinoCore-avr) for Arduino AVR boards. Use Arduino Board Manager to install. [![Latest release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest/)
+ 2. [`Arduino AVR core 1.8.5+`](https://github.com/arduino/ArduinoCore-avr) for Arduino AVR boards. Use Arduino Board Manager to install. [![Latest release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest/)
3. [`Adafruit AVR core 1.4.14+`](https://github.com/adafruit/Adafruit_Arduino_Boards) for Adafruit AVR boards. Use Arduino Board Manager to install.
4. [`Sparkfun AVR core 1.1.13+`](https://github.com/sparkfun/Arduino_Boards) for Sparkfun AVR boards. Use Arduino Board Manager to install.
@@ -163,7 +166,7 @@ Another way to install is to:
1. Install [VS Code](https://code.visualstudio.com/)
2. Install [PlatformIO](https://platformio.org/platformio-ide)
-3. Install [**AVR_Slow_PWM** library](https://platformio.org/lib/show/12885/AVR_Slow_PWM) by using [Library Manager](https://platformio.org/lib/show/12885/AVR_Slow_PWM/installation). Search for **AVR_Slow_PWM** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
+3. Install [**AVR_Slow_PWM** library](https://registry.platformio.org/libraries/khoih-prog/AVR_Slow_PWM) by using [Library Manager](https://registry.platformio.org/libraries/khoih-prog/AVR_Slow_PWM/installation). Search for **AVR_Slow_PWM** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html)
@@ -298,489 +301,8 @@ void setup()
### Example [ISR_8_PWMs_Array_Complex](examples/ISR_8_PWMs_Array_Complex)
-```
-#if ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \
- defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \
- defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \
- defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) || defined(ARDUINO_AVR_FEATHER328P) || \
- defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || defined(ARDUINO_AVR_PROTRINKET5FTDI) || \
- defined(ARDUINO_AVR_PROTRINKET3FTDI) )
- #define USE_TIMER_1 true
- #warning Using Timer1
-#else
- #define USE_TIMER_3 true
- #warning Using Timer3
-#endif
-
-// 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
-
-#define USING_MICROS_RESOLUTION true //false
-
-// Default is true, uncomment to false
-//#define CHANGING_PWM_END_OF_CYCLE false
-
-// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
-#include "AVR_Slow_PWM.h"
-
-#include // https://github.com/jfturcot/SimpleTimer
-
-#define LED_OFF HIGH
-#define LED_ON LOW
-
-#ifndef LED_BUILTIN
- #define LED_BUILTIN 13
-#endif
-
-#ifndef LED_BLUE
- #define LED_BLUE 10
-#endif
-
-#ifndef LED_RED
- #define LED_RED 11
-#endif
-
-#define USING_HW_TIMER_INTERVAL_MS false //true
-
-// Don't change these numbers to make higher Timer freq. System can hang
-#define HW_TIMER_INTERVAL_MS 0.1f
-#define HW_TIMER_INTERVAL_FREQ 10000L
-
-volatile uint32_t startMicros = 0;
-
-// Init AVR_Slow_PWM, each can service 16 different ISR-based PWM channels
-AVR_Slow_PWM ISR_PWM;
-
-//////////////////////////////////////////////////////
-
-void TimerHandler()
-{
- ISR_PWM.run();
-}
-
-/////////////////////////////////////////////////
-
-#define PIN_D0 0
-#define PIN_D1 1
-#define PIN_D2 2
-#define PIN_D3 3
-#define PIN_D4 4
-#define PIN_D5 5
-#define PIN_D6 6
-
-// You can assign pins here. Be careful to select good pin to use or crash, e.g pin 6-11
-uint32_t PWM_Pin[] =
-{
- LED_BUILTIN, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4, PIN_D5, PIN_D6
-};
-
-#define NUMBER_ISR_PWMS ( sizeof(PWM_Pin) / sizeof(uint32_t) )
-
-typedef void (*irqCallback) ();
-
-//////////////////////////////////////////////////////
-
-#define USE_COMPLEX_STRUCT true
-
-//////////////////////////////////////////////////////
-
-#if USE_COMPLEX_STRUCT
-
-typedef struct
-{
- uint32_t PWM_Pin;
- irqCallback irqCallbackStartFunc;
- irqCallback irqCallbackStopFunc;
-
- float PWM_Freq;
-
- float PWM_DutyCycle;
-
- uint32_t deltaMicrosStart;
- uint32_t previousMicrosStart;
-
- uint32_t deltaMicrosStop;
- uint32_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
-
-void doingSomethingStart(int index);
-
-void doingSomethingStop(int index);
-
-#else // #if USE_COMPLEX_STRUCT
-
-volatile unsigned long deltaMicrosStart [] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-volatile unsigned long previousMicrosStart [] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-
-volatile unsigned long deltaMicrosStop [] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-volatile unsigned long previousMicrosStop [] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-
-
-// You can assign any interval for any timer here, in Microseconds
-uint32_t PWM_Period[] =
-{
- 1000, 500, 333, 250, 200, 167, 143, 125
-};
-
-// 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,
-};
-
-// You can assign any interval for any timer here, in Microseconds
-float PWM_DutyCycle[] =
-{
- 5.0, 10.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0
-};
-
-void doingSomethingStart(int index)
-{
- unsigned long currentMicros = micros();
-
- deltaMicrosStart[index] = currentMicros - previousMicrosStart[index];
- previousMicrosStart[index] = currentMicros;
-}
-
-void doingSomethingStop(int index)
-{
- unsigned long currentMicros = micros();
-
- // Count from start to stop PWM pulse
- deltaMicrosStop[index] = currentMicros - previousMicrosStart[index];
- previousMicrosStop[index] = currentMicros;
-}
-
-#endif // #if USE_COMPLEX_STRUCT
-
-////////////////////////////////////
-// Shared
-////////////////////////////////////
-
-void doingSomethingStart0()
-{
- doingSomethingStart(0);
-}
-
-void doingSomethingStart1()
-{
- doingSomethingStart(1);
-}
-
-void doingSomethingStart2()
-{
- doingSomethingStart(2);
-}
-
-void doingSomethingStart3()
-{
- doingSomethingStart(3);
-}
-
-void doingSomethingStart4()
-{
- doingSomethingStart(4);
-}
-
-void doingSomethingStart5()
-{
- doingSomethingStart(5);
-}
-
-void doingSomethingStart6()
-{
- doingSomethingStart(6);
-}
-
-void doingSomethingStart7()
-{
- doingSomethingStart(7);
-}
-
-
-//////////////////////////////////////////////////////
-
-void doingSomethingStop0()
-{
- doingSomethingStop(0);
-}
-
-void doingSomethingStop1()
-{
- doingSomethingStop(1);
-}
+https://github.com/khoih-prog/AVR_Slow_PWM/blob/e52cd46014064efa2b30c895ce14c7cd5c850e27/examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino#L22-L508
-void doingSomethingStop2()
-{
- doingSomethingStop(2);
-}
-
-void doingSomethingStop3()
-{
- doingSomethingStop(3);
-}
-
-void doingSomethingStop4()
-{
- doingSomethingStop(4);
-}
-
-void doingSomethingStop5()
-{
- doingSomethingStop(5);
-}
-
-void doingSomethingStop6()
-{
- doingSomethingStop(6);
-}
-
-void doingSomethingStop7()
-{
- doingSomethingStop(7);
-}
-
-
-//////////////////////////////////////////////////////
-
-#if USE_COMPLEX_STRUCT
-
-ISR_PWM_Data curISR_PWM_Data[] =
-{
- // pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Freq, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
- { LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1.0, 5.0, 0, 0, 0, 0 },
- { PIN_D0, doingSomethingStart1, doingSomethingStop1, 2.0, 10.0, 0, 0, 0, 0 },
- { PIN_D1, doingSomethingStart2, doingSomethingStop2, 3.0, 20.0, 0, 0, 0, 0 },
- { PIN_D2, doingSomethingStart3, doingSomethingStop3, 4.0, 25.0, 0, 0, 0, 0 },
- { PIN_D3, doingSomethingStart4, doingSomethingStop4, 5.0, 30.0, 0, 0, 0, 0 },
- { PIN_D4, doingSomethingStart5, doingSomethingStop5, 6.0, 35.0, 0, 0, 0, 0 },
- { PIN_D5, doingSomethingStart6, doingSomethingStop6, 7.0, 40.0, 0, 0, 0, 0 },
- { PIN_D6, doingSomethingStart7, doingSomethingStop7, 8.0, 45.0, 0, 0, 0, 0 },
-};
-
-
-void doingSomethingStart(int index)
-{
- unsigned long currentMicros = micros();
-
- curISR_PWM_Data[index].deltaMicrosStart = currentMicros - curISR_PWM_Data[index].previousMicrosStart;
- curISR_PWM_Data[index].previousMicrosStart = currentMicros;
-}
-
-void doingSomethingStop(int index)
-{
- unsigned long 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
-};
-
-irqCallback irqCallbackStopFunc[] =
-{
- doingSomethingStop0, doingSomethingStop1, doingSomethingStop2, doingSomethingStop3,
- doingSomethingStop4, doingSomethingStop5, doingSomethingStop6, doingSomethingStop7
-};
-
-#endif // #if USE_COMPLEX_STRUCT
-
-//////////////////////////////////////////////////////
-
-#define SIMPLE_TIMER_MS 2000L
-
-// 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.
-void simpleTimerDoingSomething2s()
-{
- static unsigned long previousMicrosStart = startMicros;
-
- unsigned long currMicros = micros();
-
- Serial.print(F("SimpleTimer (us): ")); 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(", prog Period (ms): "));
-
- Serial.print(1000.0f / curISR_PWM_Data[i].PWM_Freq);
-
- Serial.print(F(", actual (uS) : ")); Serial.print(curISR_PWM_Data[i].deltaMicrosStart);
-
- Serial.print(F(", prog 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);
- //Serial.print(F(", actual deltaMicrosStop : ")); Serial.println(curISR_PWM_Data[i].deltaMicrosStop);
- //Serial.print(F(", actual deltaMicrosStart : ")); Serial.println(curISR_PWM_Data[i].deltaMicrosStart);
-
-#else
-
- Serial.print(F("PWM Channel : ")); Serial.print(i);
-
- Serial.print(1000.0f / PWM_Freq[i]);
-
- Serial.print(F(", prog. Period (us): ")); Serial.print(PWM_Period[i]);
- Serial.print(F(", actual : ")); Serial.print(deltaMicrosStart[i]);
-
- Serial.print(F(", prog DutyCycle : "));
-
- Serial.print(PWM_DutyCycle[i]);
-
- Serial.print(F(", actual : ")); Serial.println( (float) deltaMicrosStop[i] * 100.0f / deltaMicrosStart[i]);
- //Serial.print(F(", actual deltaMicrosStop : ")); Serial.println(deltaMicrosStop[i]);
- //Serial.print(F(", actual deltaMicrosStart : ")); Serial.println(deltaMicrosStart[i]);
-#endif
- }
-
- previousMicrosStart = currMicros;
-}
-
-void setup()
-{
- Serial.begin(115200);
- while (!Serial);
-
- delay(2000);
-
- Serial.print(F("\nStarting ISR_8_PWMs_Array_Complex on ")); Serial.println(BOARD_NAME);
- Serial.println(AVR_SLOW_PWM_VERSION);
- Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
-
- // Timer0 is used for micros(), micros(), delay(), etc and can't be used
- // Select Timer 1-2 for UNO, 1-5 for MEGA, 1,3,4 for 16u4/32u4
- // Timer 2 is 8-bit timer, only for higher frequency
- // Timer 4 of 16u4 and 32u4 is 8/10-bit timer, only for higher frequency
-
-#if USING_HW_TIMER_INTERVAL_MS
-
-#if USE_TIMER_1
-
- ITimer1.init();
-
- // Using ATmega328 used in UNO => 16MHz CPU clock ,
-
- if (ITimer1.attachInterruptInterval(HW_TIMER_INTERVAL_MS, TimerHandler))
- {
- Serial.print(F("Starting ITimer1 OK, micros() = ")); Serial.println(micros());
- }
- else
- Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
-
-#elif USE_TIMER_3
-
- ITimer3.init();
-
- if (ITimer3.attachInterruptInterval(HW_TIMER_INTERVAL_MS, TimerHandler))
- {
- Serial.print(F("Starting ITimer3 OK, micros() = ")); Serial.println(micros());
- }
- else
- Serial.println(F("Can't set ITimer3. Select another freq. or timer"));
-
-#endif
-
-#else
-
-#if USE_TIMER_1
-
- ITimer1.init();
-
- // Using ATmega328 used in UNO => 16MHz CPU clock ,
-
- if (ITimer1.attachInterrupt(HW_TIMER_INTERVAL_FREQ, TimerHandler))
- {
- Serial.print(F("Starting ITimer1 OK, micros() = ")); Serial.println(micros());
- }
- else
- Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
-
-#elif USE_TIMER_3
-
- ITimer3.init();
-
- if (ITimer3.attachInterrupt(HW_TIMER_INTERVAL_FREQ, TimerHandler))
- {
- Serial.print(F("Starting ITimer3 OK, micros() = ")); Serial.println(micros());
- }
- else
- Serial.println(F("Can't set ITimer3. Select another freq. or timer"));
-
-#endif
-
-#endif
-
- 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)
-
- // 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
- previousMicrosStart[i] = micros();
-
- // 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]);
-
-#endif
- }
-
- // You need this timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary.
- simpleTimer.setInterval(SIMPLE_TIMER_MS, simpleTimerDoingSomething2s);
-}
-
-#define BLOCKING_TIME_MS 10000L
-
-void loop()
-{
- // 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();
-}
-```
---
---
@@ -793,7 +315,7 @@ The following is the sample terminal output when running example [ISR_8_PWMs_Arr
```
Starting ISR_8_PWMs_Array_Complex on Arduino AVR ATMega32U4
-AVR_Slow_PWM v1.2.2
+AVR_Slow_PWM v1.2.3
CPU Frequency = 16 MHz
[PWM] T3
[PWM] Freq * 1000 = 10000000.00
@@ -838,7 +360,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A
```
Starting ISR_8_PWMs_Array on Arduino AVR Mega2560/ADK
-AVR_Slow_PWM v1.2.2
+AVR_Slow_PWM v1.2.3
CPU Frequency = 16 MHz
[PWM] T3
[PWM] Freq * 1000 = 10000000.00
@@ -865,7 +387,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A
```
Starting ISR_8_PWMs_Array_Complex on Arduino AVR UNO, Nano, etc.
-AVR_Slow_PWM v1.2.2
+AVR_Slow_PWM v1.2.3
CPU Frequency = 16 MHz
[PWM] T1
[PWM] Freq * 1000 = 10000000.00
@@ -911,7 +433,7 @@ The following is the sample terminal output when running example [ISR_Modify_PWM
```
Starting ISR_Modify_PWM on Arduino AVR Mega2560/ADK
-AVR_Slow_PWM v1.2.2
+AVR_Slow_PWM v1.2.3
CPU Frequency = 16 MHz
[PWM] T3
[PWM] Freq * 1000 = 10000000.00
@@ -920,7 +442,23 @@ CPU Frequency = 16 MHz
[PWM] OK in loop => _OCR = 1599
[PWM] _preScalerIndex = 1 , preScalerDiv = 1
Starting ITimer3 OK, micros() = 2023764
-Using PWM Freq = 1.00, PWM DutyCycle = 50.00
+Using PWM Freq = 200.00, PWM DutyCycle = 1.00
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 2038456
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 12052172
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 22052172
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 32052172
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 42057172
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 52057180
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 62057372
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 72057372
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 82057376
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 92057572
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 102062572
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 112062572
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 122062572
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 132062572
+Channel : 0 Period : 5000 OnTime : 50 Start_Time : 142067572
+Channel : 0 Period : 10000 OnTime : 555 Start_Time : 152062572
```
---
@@ -931,7 +469,7 @@ The following is the sample terminal output when running example [ISR_Changing_P
```
Starting ISR_Changing_PWM on Arduino AVR Mega2560/ADK
-AVR_Slow_PWM v1.2.2
+AVR_Slow_PWM v1.2.3
CPU Frequency = 16 MHz
[PWM] T3
[PWM] Freq * 1000 = 10000000.00
@@ -997,7 +535,7 @@ Submit issues to: [AVR_Slow_PWM issues](https://github.com/khoih-prog/AVR_Slow_P
6. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`
7. Optimize library code by using `reference-passing` instead of `value-passing`
8. DutyCycle to be optionally updated at the end current PWM period instead of immediately.
-
+9. Display informational warning only when `_PWM_LOGLEVEL_` > 3
---
---
diff --git a/changelog.md b/changelog.md
index fc51ebe..221486e 100644
--- a/changelog.md
+++ b/changelog.md
@@ -12,6 +12,7 @@
## Table of Contents
* [Changelog](#changelog)
+ * [Releases v1.2.3](#releases-v123)
* [Releases v1.2.2](#releases-v122)
* [Releases v1.2.1](#releases-v121)
* [Releases v1.2.0](#releases-v120)
@@ -23,6 +24,13 @@
## Changelog
+### Releases v1.2.3
+
+1. Fix `DutyCycle` bug. Check [float precisison of DutyCycle only sometimes working #3](https://github.com/khoih-prog/SAMD_Slow_PWM/issues/3)
+2. Fix `New Period` display bug. Check [random dropouts #4](https://github.com/khoih-prog/SAMD_Slow_PWM/issues/4)
+3. Update examples
+
+
### Releases v1.2.2
1. Use `float` for `DutyCycle` and `Freq`, `uint32_t` for `period`.
diff --git a/library.json b/library.json
index e189972..d026a30 100644
--- a/library.json
+++ b/library.json
@@ -1,6 +1,6 @@
{
"name": "AVR_Slow_PWM",
- "version": "1.2.2",
+ "version": "1.2.3",
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, precise, non-blocking, avr, mega-2560, nano, uno, leonardo, 32u4, 16u4, at-mega",
"description": "This library enables you to use ISR-based PWM channels on AVR-based boards, such as Mega-2560, UNO,Nano, Leonardo, etc., 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 important feature is they're ISR-based PWM channels, supporting lower PWM frequencies with suitable accuracy. Their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These ISR-based PWMs, still work even if other software functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software-based PWM using millis() or micros(). That's necessary if you need to control devices requiring high precision. Now you can change the PWM settings on-the-fly",
"authors":
diff --git a/library.properties b/library.properties
index 98c553d..51adc51 100644
--- a/library.properties
+++ b/library.properties
@@ -1,5 +1,5 @@
name=AVR_Slow_PWM
-version=1.2.2
+version=1.2.3
author=Khoi Hoang
maintainer=Khoi Hoang
sentence=This library enables you to use ISR-based PWM channels on AVR-based boards, such as Mega-2560, UNO,Nano, Leonardo, etc., to create and output PWM any GPIO pin.
diff --git a/src/AVR_Slow_PWM.h b/src/AVR_Slow_PWM.h
index 667cfa9..7b6b68f 100644
--- a/src/AVR_Slow_PWM.h
+++ b/src/AVR_Slow_PWM.h
@@ -18,7 +18,7 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
- Version: 1.2.2
+ Version: 1.2.3
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -27,6 +27,7 @@
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
1.2.2 K Hoang 01/02/2022 Use float for DutyCycle and Freq, uint32_t for period. Optimize code
+ 1.2.3 K Hoang 04/03/2022 Fix `DutyCycle` and `New Period` display bugs. Display warning only when debug level > 3
*****************************************************************************************************************************/
#pragma once
diff --git a/src/AVR_Slow_PWM.hpp b/src/AVR_Slow_PWM.hpp
index 2ca432b..45d0d6d 100644
--- a/src/AVR_Slow_PWM.hpp
+++ b/src/AVR_Slow_PWM.hpp
@@ -18,7 +18,7 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
- Version: 1.2.2
+ Version: 1.2.3
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -27,6 +27,7 @@
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
1.2.2 K Hoang 01/02/2022 Use float for DutyCycle and Freq, uint32_t for period. Optimize code
+ 1.2.3 K Hoang 04/03/2022 Fix `DutyCycle` and `New Period` display bugs. Display warning only when debug level > 3
*****************************************************************************************************************************/
#pragma once
@@ -38,6 +39,10 @@
#undef BOARD_NAME
#endif
+#ifndef _PWM_LOGLEVEL_
+ #define _PWM_LOGLEVEL_ 1
+#endif
+
#if ( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \
defined(__AVR_ATmega640__) || defined(__AVR_ATmega641__))
#if defined(TIMER_INTERRUPT_USING_ATMEGA2560)
@@ -45,19 +50,28 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA2560 true
#define BOARD_NAME F("Arduino AVR Mega2560/ADK")
- #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. Timer1-5 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. Timer1-5 available
+ #endif
#elif ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \
defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \
defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \
defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) )
#define BOARD_NAME "Arduino AVR UNO, Nano, etc."
- #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. Only Timer1,2 available
-
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. Only Timer1,2 available
+ #endif
+
#elif ( defined(ARDUINO_AVR_FEATHER328P) || defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || \
defined(ARDUINO_AVR_PROTRINKET5FTDI) || defined(ARDUINO_AVR_PROTRINKET3FTDI) )
#define BOARD_NAME F("Adafruit AVR ATMega328(P)")
- #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. Only Timer1,2 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. Only Timer1,2 available
+ #endif
#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \
defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \
@@ -67,8 +81,11 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
#define BOARD_NAME F("Arduino AVR ATMega32U4")
- #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. Only Timer1,3,4 available
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. Only Timer1,3,4 available
+ #endif
+
#elif ( defined(ARDUINO_AVR_FLORA8 ) || defined(ARDUINO_AVR_FEATHER32U4) || defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_ITSYBITSY32U4_5V) || \
defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || defined(ARDUINO_AVR_BLUEFRUITMICRO) || defined(ARDUINO_AVR_ADAFRUIT32U4) )
#if defined(TIMER_INTERRUPT_USING_ATMEGA_32U4)
@@ -76,7 +93,10 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
#define BOARD_NAME F("Adafruit AVR ATMega32U4")
- #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc.. Only Timer1,3,4 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc.. Only Timer1,3,4 available
+ #endif
#elif ( defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_MAKEYMAKEY ) || defined(ARDUINO_AVR_PROMICRO) || defined(ARDUINO_AVR_FIOV3) || \
defined(ARDUINO_AVR_QDUINOMINI) || defined(ARDUINO_AVR_LILYPAD_ARDUINO_USB_PLUS_BOARD ) )
@@ -85,15 +105,24 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
#define BOARD_NAME F("Generic or Sparkfun AVR ATMega32U4")
- #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. Only Timer1,3,4 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. Only Timer1,3,4 available
+ #endif
#elif ( defined(__AVR_ATmega328P__) || defined(ARDUINO_AVR_DIGITAL_SANDBOX ) || defined(ARDUINO_REDBOT) || defined(ARDUINO_AVR_SERIAL_7_SEGMENT) )
#define BOARD_NAME F("Generic or Sparkfun AVR ATMega328P")
- #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc.
-
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc.
+ #endif
+
#elif ( defined(__AVR_ATmega128RFA1__) || defined(ARDUINO_ATMEGA128RFA1_DEV_BOARD) )
#define BOARD_NAME F("Generic or Sparkfun AVR ATMega128RFA1")
- #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc.
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc.
+ #endif
#elif ( defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_TRINKET3) || defined(ARDUINO_AVR_TRINKET5) )
#error These AVR boards are not supported! Please check your Tools->Board setting.
@@ -103,17 +132,13 @@
#endif
#ifndef AVR_SLOW_PWM_VERSION
- #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.2")
+ #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.3")
#define AVR_SLOW_PWM_VERSION_MAJOR 1
#define AVR_SLOW_PWM_VERSION_MINOR 2
- #define AVR_SLOW_PWM_VERSION_PATCH 2
+ #define AVR_SLOW_PWM_VERSION_PATCH 3
- #define AVR_SLOW_PWM_VERSION_INT 1002002
-#endif
-
-#ifndef _PWM_LOGLEVEL_
- #define _PWM_LOGLEVEL_ 1
+ #define AVR_SLOW_PWM_VERSION_INT 1002003
#endif
#include
@@ -447,7 +472,11 @@ class TimerInterrupt
#if !defined(USE_TIMER_3)
#define USE_TIMER_3 false
#elif ( USE_TIMER_3 && ( TIMER_INTERRUPT_USING_ATMEGA_32U4 || TIMER_INTERRUPT_USING_ATMEGA2560 ) )
- #warning Timer3 (16-bit) is OK to use for ATMEGA_32U4 and Mega
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Timer3 (16-bit) is OK to use for ATMEGA_32U4 and Mega
+ #endif
+
#elif USE_TIMER_3
#error Timer3 is only available for ATMEGA_32U4 and Mega
#endif
@@ -455,7 +484,11 @@ class TimerInterrupt
#if !defined(USE_TIMER_4)
#define USE_TIMER_4 false
#elif ( USE_TIMER_4 && ( TIMER_INTERRUPT_USING_ATMEGA_32U4 || TIMER_INTERRUPT_USING_ATMEGA2560 ) )
- #warning Timer4 is OK to use for ATMEGA_32U4 (10-bit but using as 8-bit) and Mega (16-bit)
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Timer4 is OK to use for ATMEGA_32U4 (10-bit but using as 8-bit) and Mega (16-bit)
+ #endif
+
#elif USE_TIMER_4
#error Timer4 is only available for ATMEGA_32U4 and Mega
#endif
@@ -463,7 +496,11 @@ class TimerInterrupt
#if !defined(USE_TIMER_5)
#define USE_TIMER_5 false
#elif ( USE_TIMER_5 && TIMER_INTERRUPT_USING_ATMEGA2560 )
- #warning Timer5 is OK to use for Mega
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Timer5 is OK to use for Mega
+ #endif
+
#elif USE_TIMER_5
#error Timer5 is only available for Mega
#endif
diff --git a/src/AVR_Slow_PWM_ISR.h b/src/AVR_Slow_PWM_ISR.h
index 7484830..5f018f0 100644
--- a/src/AVR_Slow_PWM_ISR.h
+++ b/src/AVR_Slow_PWM_ISR.h
@@ -18,7 +18,7 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
- Version: 1.2.2
+ Version: 1.2.3
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -27,6 +27,7 @@
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
1.2.2 K Hoang 01/02/2022 Use float for DutyCycle and Freq, uint32_t for period. Optimize code
+ 1.2.3 K Hoang 04/03/2022 Fix `DutyCycle` and `New Period` display bugs. Display warning only when debug level > 3
*****************************************************************************************************************************/
#pragma once
diff --git a/src/AVR_Slow_PWM_ISR.hpp b/src/AVR_Slow_PWM_ISR.hpp
index cd25e8a..7d25b71 100644
--- a/src/AVR_Slow_PWM_ISR.hpp
+++ b/src/AVR_Slow_PWM_ISR.hpp
@@ -18,7 +18,7 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
- Version: 1.2.2
+ Version: 1.2.3
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -27,6 +27,7 @@
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
1.2.2 K Hoang 01/02/2022 Use float for DutyCycle and Freq, uint32_t for period. Optimize code
+ 1.2.3 K Hoang 04/03/2022 Fix `DutyCycle` and `New Period` display bugs. Display warning only when debug level > 3
*****************************************************************************************************************************/
#pragma once
@@ -38,6 +39,10 @@
#undef BOARD_NAME
#endif
+#ifndef _PWM_LOGLEVEL_
+ #define _PWM_LOGLEVEL_ 1
+#endif
+
#if ( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \
defined(__AVR_ATmega640__) || defined(__AVR_ATmega641__))
#if defined(TIMER_INTERRUPT_USING_ATMEGA2560)
@@ -45,19 +50,28 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA2560 true
#define BOARD_NAME F("Arduino AVR Mega2560/ADK")
- #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. Timer1-5 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. Timer1-5 available
+ #endif
#elif ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \
defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \
defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \
defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) )
#define BOARD_NAME "Arduino AVR UNO, Nano, etc."
- #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. Only Timer1,2 available
-
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. Only Timer1,2 available
+ #endif
+
#elif ( defined(ARDUINO_AVR_FEATHER328P) || defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || \
defined(ARDUINO_AVR_PROTRINKET5FTDI) || defined(ARDUINO_AVR_PROTRINKET3FTDI) )
#define BOARD_NAME F("Adafruit AVR ATMega328(P)")
- #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. Only Timer1,2 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. Only Timer1,2 available
+ #endif
#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \
defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \
@@ -67,8 +81,11 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
#define BOARD_NAME F("Arduino AVR ATMega32U4")
- #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. Only Timer1,3,4 available
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. Only Timer1,3,4 available
+ #endif
+
#elif ( defined(ARDUINO_AVR_FLORA8 ) || defined(ARDUINO_AVR_FEATHER32U4) || defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_ITSYBITSY32U4_5V) || \
defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || defined(ARDUINO_AVR_BLUEFRUITMICRO) || defined(ARDUINO_AVR_ADAFRUIT32U4) )
#if defined(TIMER_INTERRUPT_USING_ATMEGA_32U4)
@@ -76,7 +93,10 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
#define BOARD_NAME F("Adafruit AVR ATMega32U4")
- #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc.. Only Timer1,3,4 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc.. Only Timer1,3,4 available
+ #endif
#elif ( defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_MAKEYMAKEY ) || defined(ARDUINO_AVR_PROMICRO) || defined(ARDUINO_AVR_FIOV3) || \
defined(ARDUINO_AVR_QDUINOMINI) || defined(ARDUINO_AVR_LILYPAD_ARDUINO_USB_PLUS_BOARD ) )
@@ -85,15 +105,24 @@
#endif
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
#define BOARD_NAME F("Generic or Sparkfun AVR ATMega32U4")
- #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. Only Timer1,3,4 available
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. Only Timer1,3,4 available
+ #endif
#elif ( defined(__AVR_ATmega328P__) || defined(ARDUINO_AVR_DIGITAL_SANDBOX ) || defined(ARDUINO_REDBOT) || defined(ARDUINO_AVR_SERIAL_7_SEGMENT) )
#define BOARD_NAME F("Generic or Sparkfun AVR ATMega328P")
- #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc.
-
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc.
+ #endif
+
#elif ( defined(__AVR_ATmega128RFA1__) || defined(ARDUINO_ATMEGA128RFA1_DEV_BOARD) )
#define BOARD_NAME F("Generic or Sparkfun AVR ATMega128RFA1")
- #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc.
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc.
+ #endif
#elif ( defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_TRINKET3) || defined(ARDUINO_AVR_TRINKET5) )
#error These AVR boards are not supported! Please check your Tools->Board setting.
@@ -103,17 +132,13 @@
#endif
#ifndef AVR_SLOW_PWM_VERSION
- #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.2")
+ #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.3")
#define AVR_SLOW_PWM_VERSION_MAJOR 1
#define AVR_SLOW_PWM_VERSION_MINOR 2
- #define AVR_SLOW_PWM_VERSION_PATCH 2
-
- #define AVR_SLOW_PWM_VERSION_INT 1002002
-#endif
+ #define AVR_SLOW_PWM_VERSION_PATCH 3
-#ifndef _PWM_LOGLEVEL_
- #define _PWM_LOGLEVEL_ 1
+ #define AVR_SLOW_PWM_VERSION_INT 1002003
#endif
#include "PWM_Generic_Debug.h"
@@ -136,12 +161,19 @@ typedef void (*timer_callback)();
typedef void (*timer_callback_p)(void *);
#if !defined(USING_MICROS_RESOLUTION)
- #warning Not USING_MICROS_RESOLUTION, using millis resolution
+
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Not USING_MICROS_RESOLUTION, using millis resolution
+ #endif
+
#define USING_MICROS_RESOLUTION false
#endif
#if !defined(CHANGING_PWM_END_OF_CYCLE)
- #warning Using default CHANGING_PWM_END_OF_CYCLE == true
+ #if (_PWM_LOGLEVEL_ > 3)
+ #warning Using default CHANGING_PWM_END_OF_CYCLE == true
+ #endif
+
#define CHANGING_PWM_END_OF_CYCLE true
#endif
diff --git a/src/AVR_Slow_PWM_ISR_Impl.h b/src/AVR_Slow_PWM_ISR_Impl.h
index fbf4bde..1b17209 100644
--- a/src/AVR_Slow_PWM_ISR_Impl.h
+++ b/src/AVR_Slow_PWM_ISR_Impl.h
@@ -18,7 +18,7 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
- Version: 1.2.2
+ Version: 1.2.3
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -27,6 +27,7 @@
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
1.2.2 K Hoang 01/02/2022 Use float for DutyCycle and Freq, uint32_t for period. Optimize code
+ 1.2.3 K Hoang 04/03/2022 Fix `DutyCycle` and `New Period` display bugs. Display warning only when debug level > 3
*****************************************************************************************************************************/
#pragma once
@@ -245,7 +246,7 @@ bool AVR_Slow_PWM_ISR::modifyPWMChannel_Period(const uint8_t& channelNum, const
PWM[channelNum].newOnTime = ( period * dutycycle ) / 100;
PWM_LOGINFO0("Channel : "); PWM_LOGINFO0(channelNum);
- PWM_LOGINFO0("\tNew Period : "); PWM_LOGINFO0(PWM[channelNum].newPeriod);
+ PWM_LOGINFO0("\t Period : "); PWM_LOGINFO0(period);
PWM_LOGINFO0("\t\tOnTime : "); PWM_LOGINFO0(PWM[channelNum].newOnTime);
PWM_LOGINFO0("\tStart_Time : "); PWM_LOGINFOLN0(PWM[channelNum].prevTime);
diff --git a/src/AVR_Slow_PWM_Impl.h b/src/AVR_Slow_PWM_Impl.h
index 90a7b3f..966518b 100644
--- a/src/AVR_Slow_PWM_Impl.h
+++ b/src/AVR_Slow_PWM_Impl.h
@@ -18,7 +18,7 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
- Version: 1.2.2
+ Version: 1.2.3
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -27,6 +27,7 @@
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
1.2.2 K Hoang 01/02/2022 Use float for DutyCycle and Freq, uint32_t for period. Optimize code
+ 1.2.3 K Hoang 04/03/2022 Fix `DutyCycle` and `New Period` display bugs. Display warning only when debug level > 3
****************************************************************************************************************************/
#pragma once
diff --git a/src/PWM_Generic_Debug.h b/src/PWM_Generic_Debug.h
index 5da16ad..c80a0f2 100644
--- a/src/PWM_Generic_Debug.h
+++ b/src/PWM_Generic_Debug.h
@@ -18,7 +18,7 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
- Version: 1.2.2
+ Version: 1.2.3
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -27,6 +27,7 @@
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
1.2.2 K Hoang 01/02/2022 Use float for DutyCycle and Freq, uint32_t for period. Optimize code
+ 1.2.3 K Hoang 04/03/2022 Fix `DutyCycle` and `New Period` display bugs. Display warning only when debug level > 3
*****************************************************************************************************************************/
#pragma once