From 7b4b1fb06b1c74917fc9d1bbb694c40c63d9886c Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Sun, 30 Jan 2022 17:39:06 -0500 Subject: [PATCH] 1.2.1 to to not update DutyCycle immediately ### Releases v1.2.1 1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](https://github.com/khoih-prog/ESP8266_PWM/issues/2) --- README.md | 17 ++-- changelog.md | 5 ++ .../ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino | 5 +- .../ISR_8_PWMs_Array_Complex.ino | 5 +- .../ISR_8_PWMs_Array_Simple.ino | 5 +- .../ISR_Changing_PWM/ISR_Changing_PWM.ino | 5 +- examples/ISR_Modify_PWM/ISR_Modify_PWM.ino | 5 +- examples/multiFileProject/multiFileProject.h | 5 +- keywords.txt | 3 + library.json | 2 +- library.properties | 2 +- src/AVR_Slow_PWM.h | 4 +- src/AVR_Slow_PWM.hpp | 10 ++- src/AVR_Slow_PWM_ISR.h | 4 +- src/AVR_Slow_PWM_ISR.hpp | 28 +++++-- src/AVR_Slow_PWM_ISR_Impl.h | 54 ++++++++++--- src/AVR_Slow_PWM_Impl.h | 4 +- src/PWM_Generic_Debug.h | 80 ++++++++++++------- 18 files changed, 176 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index d2b8f1b..995de10 100644 --- a/README.md +++ b/README.md @@ -317,7 +317,10 @@ void setup() // 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 +#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" @@ -790,7 +793,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.0 +AVR_Slow_PWM v1.2.1 CPU Frequency = 16 MHz [PWM] T3 [PWM] Freq * 1000 = 10000000.00 @@ -835,7 +838,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A ``` Starting ISR_8_PWMs_Array_Complex on Arduino AVR Mega2560/ADK -AVR_Slow_PWM v1.2.0 +AVR_Slow_PWM v1.2.1 CPU Frequency = 16 MHz [PWM] T3 [PWM] Freq * 1000 = 10000000.00 @@ -880,7 +883,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.0 +AVR_Slow_PWM v1.2.1 CPU Frequency = 16 MHz [PWM] T1 [PWM] Freq * 1000 = 10000000.00 @@ -926,7 +929,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.0 +AVR_Slow_PWM v1.2.1 CPU Frequency = 16 MHz [PWM] T3 [PWM] Freq * 1000 = 10000000.00 @@ -950,7 +953,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.0 +AVR_Slow_PWM v1.2.1 CPU Frequency = 16 MHz [PWM] T3 [PWM] Freq * 1000 = 10000000.00 @@ -1017,6 +1020,8 @@ Submit issues to: [AVR_Slow_PWM issues](https://github.com/khoih-prog/AVR_Slow_P 5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project 6. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period` 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. + --- --- diff --git a/changelog.md b/changelog.md index e42e8e7..dbb8a6e 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Releases v1.2.1](#releases-v121) * [Releases v1.2.0](#releases-v120) * [Releases v1.1.0](#releases-v110) * [Initial Releases v1.0.0](#Initial-Releases-v100) @@ -21,6 +22,10 @@ ## Changelog +### Releases v1.2.1 + +1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](https://github.com/khoih-prog/ESP8266_PWM/issues/2) + ### Releases v1.2.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories diff --git a/examples/ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino b/examples/ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino index 2f7baad..ebf6840 100644 --- a/examples/ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino +++ b/examples/ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino @@ -37,7 +37,10 @@ // 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 +#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" diff --git a/examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino b/examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino index 6e69bbc..1e4b57d 100644 --- a/examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino +++ b/examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino @@ -37,7 +37,10 @@ // 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 +#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" diff --git a/examples/ISR_8_PWMs_Array_Simple/ISR_8_PWMs_Array_Simple.ino b/examples/ISR_8_PWMs_Array_Simple/ISR_8_PWMs_Array_Simple.ino index 6010411..e29c829 100644 --- a/examples/ISR_8_PWMs_Array_Simple/ISR_8_PWMs_Array_Simple.ino +++ b/examples/ISR_8_PWMs_Array_Simple/ISR_8_PWMs_Array_Simple.ino @@ -37,7 +37,10 @@ // 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 +#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" diff --git a/examples/ISR_Changing_PWM/ISR_Changing_PWM.ino b/examples/ISR_Changing_PWM/ISR_Changing_PWM.ino index 015ec91..a5cb645 100644 --- a/examples/ISR_Changing_PWM/ISR_Changing_PWM.ino +++ b/examples/ISR_Changing_PWM/ISR_Changing_PWM.ino @@ -37,7 +37,10 @@ // 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 +#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" diff --git a/examples/ISR_Modify_PWM/ISR_Modify_PWM.ino b/examples/ISR_Modify_PWM/ISR_Modify_PWM.ino index 6999f57..6d3e9ff 100644 --- a/examples/ISR_Modify_PWM/ISR_Modify_PWM.ino +++ b/examples/ISR_Modify_PWM/ISR_Modify_PWM.ino @@ -37,7 +37,10 @@ // 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 +#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" diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h index 066ecfb..98856cb 100644 --- a/examples/multiFileProject/multiFileProject.h +++ b/examples/multiFileProject/multiFileProject.h @@ -12,7 +12,10 @@ #pragma once -#define USING_MICROS_RESOLUTION true //false +#define USING_MICROS_RESOLUTION true //false + +// Default is true, uncomment to false +//#define CHANGING_PWM_END_OF_CYCLE false // Can be included as many times as necessary, without `Multiple Definitions` Linker Error #include "AVR_Slow_PWM.hpp" diff --git a/keywords.txt b/keywords.txt index baab318..6c15671 100644 --- a/keywords.txt +++ b/keywords.txt @@ -57,3 +57,6 @@ AVR_Slow_PWM_VERSION_PATCH LITERAL1 AVR_Slow_PWM_VERSION_INT LITERAL1 INVALID_AVR_PIN LITERAL1 + +USING_MICROS_RESOLUTION LITERAL1 +CHANGING_PWM_END_OF_CYCLE LITERAL1 diff --git a/library.json b/library.json index 9c0cada..1672b1a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "AVR_Slow_PWM", - "version": "1.2.0", + "version": "1.2.1", "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 d5bfbde..48e5c4e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AVR_Slow_PWM -version=1.2.0 +version=1.2.1 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 bfcc648..c8b7793 100644 --- a/src/AVR_Slow_PWM.h +++ b/src/AVR_Slow_PWM.h @@ -18,12 +18,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.0 + Version: 1.2.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. ) 1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly + 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 *****************************************************************************************************************************/ #pragma once diff --git a/src/AVR_Slow_PWM.hpp b/src/AVR_Slow_PWM.hpp index 283118c..bad12b8 100644 --- a/src/AVR_Slow_PWM.hpp +++ b/src/AVR_Slow_PWM.hpp @@ -18,12 +18,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.0 + Version: 1.2.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. ) 1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly + 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 *****************************************************************************************************************************/ #pragma once @@ -100,13 +102,13 @@ #endif #ifndef AVR_SLOW_PWM_VERSION - #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.0") + #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.1") #define AVR_SLOW_PWM_VERSION_MAJOR 1 #define AVR_SLOW_PWM_VERSION_MINOR 2 - #define AVR_SLOW_PWM_VERSION_PATCH 0 + #define AVR_SLOW_PWM_VERSION_PATCH 1 - #define AVR_SLOW_PWM_VERSION_INT 1002000 + #define AVR_SLOW_PWM_VERSION_INT 1002001 #endif #ifndef _PWM_LOGLEVEL_ diff --git a/src/AVR_Slow_PWM_ISR.h b/src/AVR_Slow_PWM_ISR.h index 008e896..b046a68 100644 --- a/src/AVR_Slow_PWM_ISR.h +++ b/src/AVR_Slow_PWM_ISR.h @@ -18,12 +18,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.0 + Version: 1.2.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. ) 1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly + 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 *****************************************************************************************************************************/ #pragma once diff --git a/src/AVR_Slow_PWM_ISR.hpp b/src/AVR_Slow_PWM_ISR.hpp index a66f364..4ba9c4e 100644 --- a/src/AVR_Slow_PWM_ISR.hpp +++ b/src/AVR_Slow_PWM_ISR.hpp @@ -18,12 +18,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.0 + Version: 1.2.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. ) 1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly + 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 *****************************************************************************************************************************/ #pragma once @@ -100,13 +102,13 @@ #endif #ifndef AVR_SLOW_PWM_VERSION - #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.0") + #define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.1") #define AVR_SLOW_PWM_VERSION_MAJOR 1 #define AVR_SLOW_PWM_VERSION_MINOR 2 - #define AVR_SLOW_PWM_VERSION_PATCH 0 + #define AVR_SLOW_PWM_VERSION_PATCH 1 - #define AVR_SLOW_PWM_VERSION_INT 1002000 + #define AVR_SLOW_PWM_VERSION_INT 1002001 #endif #ifndef _PWM_LOGLEVEL_ @@ -137,6 +139,11 @@ typedef void (*timer_callback_p)(void *); #define USING_MICROS_RESOLUTION false #endif +#if !defined(CHANGING_PWM_END_OF_CYCLE) + #warning Using default CHANGING_PWM_END_OF_CYCLE == true + #define CHANGING_PWM_END_OF_CYCLE true +#endif + #define INVALID_AVR_PIN 255 ////////////////////////////////////////////////////////////////// @@ -162,9 +169,9 @@ class AVR_Slow_PWM_ISR int8_t setPWM(const uint32_t& pin, const double& frequency, const double& dutycycle, timer_callback StartCallback = nullptr, timer_callback StopCallback = nullptr) { - double period = 0; + double period = 0.0; - if ( ( frequency != 0 ) && ( frequency <= 1000 ) ) + if ( ( frequency > 0.0 ) && ( frequency <= 1000.0 ) ) { #if USING_MICROS_RESOLUTION // period in us @@ -198,9 +205,9 @@ class AVR_Slow_PWM_ISR // returns the true on success or false on failure bool modifyPWMChannel(const uint8_t& channelNum, const uint32_t& pin, const double& frequency, const double& dutycycle) { - double period = 0; + double period = 0.0; - if ( ( frequency > 0 ) && ( frequency <= 1000 ) ) + if ( ( frequency > 0.0 ) && ( frequency <= 1000.0 ) ) { #if USING_MICROS_RESOLUTION // period in us @@ -290,6 +297,11 @@ class AVR_Slow_PWM_ISR //////////////////////////////////////////////////////////// bool enabled; // true if enabled + + // New from v1.2.1 + double newPeriod; // period value, in us / ms + double newDutyCycle; // from 0.00 to 100.00, double precision + ////// } PWM_t; volatile PWM_t PWM[MAX_NUMBER_CHANNELS]; diff --git a/src/AVR_Slow_PWM_ISR_Impl.h b/src/AVR_Slow_PWM_ISR_Impl.h index 3aeca97..c024145 100644 --- a/src/AVR_Slow_PWM_ISR_Impl.h +++ b/src/AVR_Slow_PWM_ISR_Impl.h @@ -18,12 +18,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.0 + Version: 1.2.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. ) 1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly + 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 *****************************************************************************************************************************/ #pragma once @@ -116,7 +118,18 @@ void AVR_Slow_PWM_ISR::run() else if ( (uint32_t) (currentTime - PWM[channelNum].prevTime) >= PWM[channelNum].period ) { PWM[channelNum].prevTime = currentTime; - } + +#if CHANGING_PWM_END_OF_CYCLE + // Only update whenever having newPeriod + if (PWM[channelNum].newPeriod != 0) + { + PWM[channelNum].period = PWM[channelNum].newPeriod; + PWM[channelNum].newPeriod = 0; + + PWM[channelNum].onTime = ( PWM[channelNum].period * PWM[channelNum].newDutyCycle ) / 100; + } +#endif + } } } } @@ -174,6 +187,10 @@ int8_t AVR_Slow_PWM_ISR::setupPWMChannel(const uint32_t& pin, const double& peri PWM[channelNum].pin = pin; PWM[channelNum].period = period; + + // Must be 0 for new PWM channel + PWM[channelNum].newPeriod = 0; + PWM[channelNum].onTime = ( period * dutycycle ) / 100; pinMode(pin, OUTPUT); @@ -185,10 +202,10 @@ int8_t AVR_Slow_PWM_ISR::setupPWMChannel(const uint32_t& pin, const double& peri PWM[channelNum].callbackStart = cbStartFunc; PWM[channelNum].callbackStop = cbStopFunc; - PWM_LOGINFO0(F("Channel : ")); PWM_LOGINFO0(channelNum); - PWM_LOGINFO0(F("\tPeriod : ")); PWM_LOGINFO0(PWM[channelNum].period); - PWM_LOGINFO0(F("\t\tOnTime : ")); PWM_LOGINFO0(PWM[channelNum].onTime); - PWM_LOGINFO0(F("\tStart_Time : ")); PWM_LOGINFOLN0(PWM[channelNum].prevTime); + PWM_LOGDEBUG0("Channel : "); PWM_LOGDEBUG0(channelNum); + PWM_LOGDEBUG0("\t Period : "); PWM_LOGDEBUG0(PWM[channelNum].period); + PWM_LOGDEBUG0("\t\tOnTime : "); PWM_LOGDEBUG0(PWM[channelNum].onTime); + PWM_LOGDEBUG0("\tStart_Time : "); PWM_LOGDEBUGLN0(PWM[channelNum].prevTime); numChannels++; @@ -220,16 +237,33 @@ bool AVR_Slow_PWM_ISR::modifyPWMChannel_Period(const uint8_t& channelNum, const return false; } - PWM[channelNum].period = period; +#if CHANGING_PWM_END_OF_CYCLE + + PWM[channelNum].newPeriod = period; + PWM[channelNum].newDutyCycle = dutycycle; + + PWM_LOGDEBUG0("Channel : "); PWM_LOGDEBUG0(channelNum); + PWM_LOGDEBUG0("\tNew Period : "); PWM_LOGDEBUG0(PWM[channelNum].newPeriod); + PWM_LOGDEBUG0("\t\tOnTime : "); PWM_LOGDEBUG0(( period * dutycycle ) / 100); + PWM_LOGDEBUG0("\tStart_Time : "); PWM_LOGDEBUGLN0(PWM[channelNum].prevTime); + +#else + + PWM[channelNum].period = period; + PWM[channelNum].onTime = ( period * dutycycle ) / 100; digitalWrite(pin, HIGH); PWM[channelNum].pinHigh = true; PWM[channelNum].prevTime = timeNow(); - - PWM_LOGINFO0("Channel : "); PWM_LOGINFO0(channelNum); PWM_LOGINFO0("\tPeriod : "); PWM_LOGINFO0(PWM[channelNum].period); - PWM_LOGINFO0("\t\tOnTime : "); PWM_LOGINFO0(PWM[channelNum].onTime); PWM_LOGINFO0("\tStart_Time : "); PWM_LOGINFOLN0(PWM[channelNum].prevTime); + + PWM_LOGDEBUG0("Channel : "); PWM_LOGDEBUG0(channelNum); + PWM_LOGDEBUG0("\t Period : "); PWM_LOGDEBUG0(PWM[channelNum].period); + PWM_LOGDEBUG0("\t\tOnTime : "); PWM_LOGDEBUG0(PWM[channelNum].onTime); + PWM_LOGDEBUG0("\tStart_Time : "); PWM_LOGDEBUGLN0(PWM[channelNum].prevTime); + +#endif return true; } diff --git a/src/AVR_Slow_PWM_Impl.h b/src/AVR_Slow_PWM_Impl.h index 3054844..688c306 100644 --- a/src/AVR_Slow_PWM_Impl.h +++ b/src/AVR_Slow_PWM_Impl.h @@ -18,12 +18,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.0 + Version: 1.2.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. ) 1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly + 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 ****************************************************************************************************************************/ #pragma once diff --git a/src/PWM_Generic_Debug.h b/src/PWM_Generic_Debug.h index 2707989..e5b1eb8 100644 --- a/src/PWM_Generic_Debug.h +++ b/src/PWM_Generic_Debug.h @@ -18,12 +18,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.0 + Version: 1.2.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. ) 1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly + 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 *****************************************************************************************************************************/ #pragma once @@ -48,32 +50,54 @@ #define _PWM_LOGLEVEL_ 1 #endif -#define PWM_LOGERROR(x) if(_PWM_LOGLEVEL_>0) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.println(x); } -#define PWM_LOGERROR0(x) if(_PWM_LOGLEVEL_>0) { PWM_DBG_PORT.print(x); } -#define PWM_LOGERRORLN0(x) if(_PWM_LOGLEVEL_>0) { PWM_DBG_PORT.println(x); } -#define PWM_LOGERROR1(x,y) if(_PWM_LOGLEVEL_>0) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(y); } -#define PWM_LOGERROR2(x,y,z) if(_PWM_LOGLEVEL_>0) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(z); } -#define PWM_LOGERROR3(x,y,z,w) if(_PWM_LOGLEVEL_>0) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(z); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(w); } - -#define PWM_LOGWARN(x) if(_PWM_LOGLEVEL_>1) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.println(x); } -#define PWM_LOGWARN0(x) if(_PWM_LOGLEVEL_>1) { PWM_DBG_PORT.print(x); } -#define PWM_LOGWARNLN0(x) if(_PWM_LOGLEVEL_>1) { PWM_DBG_PORT.println(x); } -#define PWM_LOGWARN1(x,y) if(_PWM_LOGLEVEL_>1) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(y); } -#define PWM_LOGWARN2(x,y,z) if(_PWM_LOGLEVEL_>1) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(z); } -#define PWM_LOGWARN3(x,y,z,w) if(_PWM_LOGLEVEL_>1) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(z); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(w); } - -#define PWM_LOGINFO(x) if(_PWM_LOGLEVEL_>2) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.println(x); } -#define PWM_LOGINFO0(x) if(_PWM_LOGLEVEL_>2) { PWM_DBG_PORT.print(x); } -#define PWM_LOGINFOLN0(x) if(_PWM_LOGLEVEL_>2) { PWM_DBG_PORT.println(x); } -#define PWM_LOGINFO1(x,y) if(_PWM_LOGLEVEL_>2) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(y); } -#define PWM_LOGINFO2(x,y,z) if(_PWM_LOGLEVEL_>2) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(z); } -#define PWM_LOGINFO3(x,y,z,w) if(_PWM_LOGLEVEL_>2) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(z); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(w); } - -#define PWM_LOGDEBUG(x) if(_PWM_LOGLEVEL_>3) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.println(x); } -#define PWM_LOGDEBUG0(x) if(_PWM_LOGLEVEL_>3) { PWM_DBG_PORT.print(x); } -#define PWM_LOGDEBUGLN0(x) if(_PWM_LOGLEVEL_>3) { PWM_DBG_PORT.println(x); } -#define PWM_LOGDEBUG1(x,y) if(_PWM_LOGLEVEL_>3) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(y); } -#define PWM_LOGDEBUG2(x,y,z) if(_PWM_LOGLEVEL_>3) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(z); } -#define PWM_LOGDEBUG3(x,y,z,w) if(_PWM_LOGLEVEL_>3) { PWM_DBG_PORT.print("[PWM] "); PWM_DBG_PORT.print(x); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(y); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.print(z); PWM_DBG_PORT.print(" "); PWM_DBG_PORT.println(w); } +/////////////////////////////////////// + +const char PWM_MARK[] = "[PWM] "; +const char PWM_SPACE[] = " "; + +#define PWM_PRINT PWM_DBG_PORT.print +#define PWM_PRINTLN PWM_DBG_PORT.println + +#define PWM_PRINT_MARK PWM_PRINT(PWM_MARK) +#define PWM_PRINT_SP PWM_PRINT(PWM_SPACE) +#define PWM_PRINT_LINE PWM_PRINT(PWM_LINE) + +/////////////////////////////////////// + +#define PWM_LOGERROR(x) if(_PWM_LOGLEVEL_>0) { PWM_PRINT_MARK; PWM_PRINTLN(x); } +#define PWM_LOGERROR0(x) if(_PWM_LOGLEVEL_>0) { PWM_PRINT(x); } +#define PWM_LOGERRORLN0(x) if(_PWM_LOGLEVEL_>0) { PWM_PRINTLN(x); } +#define PWM_LOGERROR1(x,y) if(_PWM_LOGLEVEL_>0) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINTLN(y); } +#define PWM_LOGERROR2(x,y,z) if(_PWM_LOGLEVEL_>0) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINTLN(z); } +#define PWM_LOGERROR3(x,y,z,w) if(_PWM_LOGLEVEL_>0) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINT(z); PWM_PRINT_SP; PWM_PRINTLN(w); } + +/////////////////////////////////////// + +#define PWM_LOGWARN(x) if(_PWM_LOGLEVEL_>1) { PWM_PRINT_MARK; PWM_PRINTLN(x); } +#define PWM_LOGWARN0(x) if(_PWM_LOGLEVEL_>1) { PWM_PRINT(x); } +#define PWM_LOGWARNLN0(x) if(_PWM_LOGLEVEL_>1) { PWM_PRINTLN(x); } +#define PWM_LOGWARN1(x,y) if(_PWM_LOGLEVEL_>1) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINTLN(y); } +#define PWM_LOGWARN2(x,y,z) if(_PWM_LOGLEVEL_>1) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINTLN(z); } +#define PWM_LOGWARN3(x,y,z,w) if(_PWM_LOGLEVEL_>1) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINT(z); PWM_PRINT_SP; PWM_PRINTLN(w); } + +/////////////////////////////////////// + +#define PWM_LOGINFO(x) if(_PWM_LOGLEVEL_>2) { PWM_PRINT_MARK; PWM_PRINTLN(x); } +#define PWM_LOGINFO0(x) if(_PWM_LOGLEVEL_>2) { PWM_PRINT(x); } +#define PWM_LOGINFOLN0(x) if(_PWM_LOGLEVEL_>2) { PWM_PRINTLN(x); } +#define PWM_LOGINFO1(x,y) if(_PWM_LOGLEVEL_>2) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINTLN(y); } +#define PWM_LOGINFO2(x,y,z) if(_PWM_LOGLEVEL_>2) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINTLN(z); } +#define PWM_LOGINFO3(x,y,z,w) if(_PWM_LOGLEVEL_>2) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINT(z); PWM_PRINT_SP; PWM_PRINTLN(w); } + +/////////////////////////////////////// + +#define PWM_LOGDEBUG(x) if(_PWM_LOGLEVEL_>3) { PWM_PRINT_MARK; PWM_PRINTLN(x); } +#define PWM_LOGDEBUG0(x) if(_PWM_LOGLEVEL_>3) { PWM_PRINT(x); } +#define PWM_LOGDEBUGLN0(x) if(_PWM_LOGLEVEL_>3) { PWM_PRINTLN(x); } +#define PWM_LOGDEBUG1(x,y) if(_PWM_LOGLEVEL_>3) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINTLN(y); } +#define PWM_LOGDEBUG2(x,y,z) if(_PWM_LOGLEVEL_>3) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINTLN(z); } +#define PWM_LOGDEBUG3(x,y,z,w) if(_PWM_LOGLEVEL_>3) { PWM_PRINT_MARK; PWM_PRINT(x); PWM_PRINT_SP; PWM_PRINT(y); PWM_PRINT_SP; PWM_PRINT(z); PWM_PRINT_SP; PWM_PRINTLN(w); } + +/////////////////////////////////////// #endif //PWM_GENERIC_DEBUG_H