From 3090d0e474c3ea2e7fff0d5aa9311e9f263904b7 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Fri, 30 Dec 2022 19:26:50 -0500 Subject: [PATCH] v1.1.0 for `AVRDD and core 1.5.1` ### Release v1.1.0 1. Add support to AVRDD (AVR64DD, AVR32DDx, AVR16DD, etc.) 2. Modify to use either breaking DxCore v1.5.1+ or v1.4.10- --- CONTRIBUTING.md | 8 ++--- changelog.md | 6 ++++ examples/PWM_Basic/PWM_Basic.ino | 6 +++- .../PWM_DynamicDutyCycle.ino | 6 +++- .../PWM_DynamicDutyCycle_Int.ino | 6 +++- examples/PWM_DynamicFreq/PWM_DynamicFreq.ino | 6 +++- examples/PWM_Multi/PWM_Multi.ino | 9 +++-- .../PWM_MultiChannel/PWM_MultiChannel.ino | 9 +++-- examples/PWM_Waveform/PWM_Waveform.ino | 6 +++- library.json | 2 +- library.properties | 4 +-- src/Dx_PWM.h | 35 ++++++++++++++----- src/PWM_Generic_Debug.h | 3 +- 13 files changed, 80 insertions(+), 26 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e876962..363a1f4 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 -* `DxCore` Core Version (e.g. Arduino DxCore core v1.4.10) +* `DxCore` Core Version (e.g. Arduino DxCore core v1.5.1) * Board (e.g. AVR128DA64, AVR128DB48, AVR64DB32, etc.) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce @@ -23,15 +23,15 @@ Please ensure to specify the following: * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` * Network configuration +Please be educated, civilized and constructive. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted. ### Example ``` Arduino IDE version: 1.8.19 -Arduino DxCore core v1.4.10 -OS: Ubuntu 20.04 LTS +Arduino DxCore core v1.5.1 Board: Curiosity AVR128DB48 -Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.15.0-56-generic #62~20.04.1-Ubuntu SMP Tue Nov 22 21:24:20 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Context: I encountered a crash while trying to use this library diff --git a/changelog.md b/changelog.md index d7d210b..16bdcfb 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Release v1.1.0](#release-v110) * [Initial Release v1.0.0](#initial-release-v100) --- @@ -26,6 +27,11 @@ ## Changelog +### Release v1.1.0 + +1. Add support to AVRDD (AVR64DD, AVR32DDx, AVR16DD, etc.) +2. Modify to use either breaking DxCore v1.5.1+ or v1.4.10- + ### Initial Release v1.0.0 1. Initial release to support Arduino **AVRDx-based boards (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore** diff --git a/examples/PWM_Basic/PWM_Basic.ino b/examples/PWM_Basic/PWM_Basic.ino index e63b598..738fb5f 100644 --- a/examples/PWM_Basic/PWM_Basic.ino +++ b/examples/PWM_Basic/PWM_Basic.ino @@ -51,7 +51,11 @@ // PF0-3: Not PWM // PF4-5: TCB -#define pinToUse PIN_PC3 //PIN_PF5 +#if defined(PIN_PF5) + #define pinToUse PIN_PF5 +#else + #define pinToUse PIN_PC0 +#endif //creates pwm instance Dx_PWM* PWM_Instance; diff --git a/examples/PWM_DynamicDutyCycle/PWM_DynamicDutyCycle.ino b/examples/PWM_DynamicDutyCycle/PWM_DynamicDutyCycle.ino index 90c2e61..51dfdcd 100644 --- a/examples/PWM_DynamicDutyCycle/PWM_DynamicDutyCycle.ino +++ b/examples/PWM_DynamicDutyCycle/PWM_DynamicDutyCycle.ino @@ -51,7 +51,11 @@ // PF0-3: Not PWM // PF4-5: TCB -#define pinToUse PIN_PF5 +#if defined(PIN_PF5) + #define pinToUse PIN_PF5 +#else + #define pinToUse PIN_PC0 +#endif //creates pwm instance Dx_PWM* PWM_Instance; diff --git a/examples/PWM_DynamicDutyCycle_Int/PWM_DynamicDutyCycle_Int.ino b/examples/PWM_DynamicDutyCycle_Int/PWM_DynamicDutyCycle_Int.ino index fe12815..fe57f44 100644 --- a/examples/PWM_DynamicDutyCycle_Int/PWM_DynamicDutyCycle_Int.ino +++ b/examples/PWM_DynamicDutyCycle_Int/PWM_DynamicDutyCycle_Int.ino @@ -51,7 +51,11 @@ // PF0-3: Not PWM // PF4-5: TCB -#define pinToUse PIN_PF5 +#if defined(PIN_PF5) + #define pinToUse PIN_PF5 +#else + #define pinToUse PIN_PC0 +#endif //creates pwm instance Dx_PWM* PWM_Instance; diff --git a/examples/PWM_DynamicFreq/PWM_DynamicFreq.ino b/examples/PWM_DynamicFreq/PWM_DynamicFreq.ino index 1453170..255441a 100644 --- a/examples/PWM_DynamicFreq/PWM_DynamicFreq.ino +++ b/examples/PWM_DynamicFreq/PWM_DynamicFreq.ino @@ -51,7 +51,11 @@ // PF0-3: Not PWM // PF4-5: TCB -#define pinToUse PIN_PF5 +#if defined(PIN_PF5) + #define pinToUse PIN_PF5 +#else + #define pinToUse PIN_PC0 +#endif //creates pwm instance Dx_PWM* PWM_Instance; diff --git a/examples/PWM_Multi/PWM_Multi.ino b/examples/PWM_Multi/PWM_Multi.ino index 2dfc35e..fc07811 100644 --- a/examples/PWM_Multi/PWM_Multi.ino +++ b/examples/PWM_Multi/PWM_Multi.ino @@ -50,8 +50,13 @@ // PF0-3: Not PWM // PF4-5: TCB -// Be careful to select pins for different frequencies -uint32_t PWM_Pins[] = { PIN_PB2, PIN_PC0, PIN_PF4, PIN_PF5 }; +#if defined(PIN_PF5) + // Be careful to select pins for different frequencies + uint32_t PWM_Pins[] = { PIN_PC0, PIN_PF4, PIN_PF5 }; +#else + // Be careful to select pins for different frequencies + uint32_t PWM_Pins[] = { PIN_PC0 }; +#endif float frequency[] = { 2000.0f, 3000.0f, 4000.0f, 8000.0f }; float dutyCycle[] = { 20.0f, 30.0f, 40.0f, 80.0f }; diff --git a/examples/PWM_MultiChannel/PWM_MultiChannel.ino b/examples/PWM_MultiChannel/PWM_MultiChannel.ino index e909070..7f49af6 100644 --- a/examples/PWM_MultiChannel/PWM_MultiChannel.ino +++ b/examples/PWM_MultiChannel/PWM_MultiChannel.ino @@ -50,8 +50,13 @@ // PF0-3: Not PWM // PF4-5: TCB -// Be careful to select pins for different frequencies -uint32_t PWM_Pins[] = { PIN_PB2, PIN_PC0, PIN_PF4, PIN_PF5 }; +#if defined(PIN_PF5) + // Be careful to select pins for different frequencies + uint32_t PWM_Pins[] = { PIN_PC0, PIN_PF4, PIN_PF5 }; +#else + // Be careful to select pins for different frequencies + uint32_t PWM_Pins[] = { PIN_PC0 }; +#endif float dutyCycle[] = { 20.0f, 30.0f, 40.0f, 80.0f }; diff --git a/examples/PWM_Waveform/PWM_Waveform.ino b/examples/PWM_Waveform/PWM_Waveform.ino index c0d1ad3..696ef44 100644 --- a/examples/PWM_Waveform/PWM_Waveform.ino +++ b/examples/PWM_Waveform/PWM_Waveform.ino @@ -51,7 +51,11 @@ // PF0-3: Not PWM // PF4-5: TCB -#define pinToUse PIN_PF5 +#if defined(PIN_PF5) + #define pinToUse PIN_PF5 +#else + #define pinToUse PIN_PC0 +#endif //creates pwm instance Dx_PWM* PWM_Instance; diff --git a/library.json b/library.json index 2b494c6..3950e1b 100644 --- a/library.json +++ b/library.json @@ -2,7 +2,7 @@ "name": "Dx_PWM", "version": "1.0.0", "keywords": "timing, device, control, timer, pwm, pwm-driver, pwm-frequency, dynamic-pwm, duty-cycle, hardware-based-pwm, multi-channel-pwm, waveform-generator, mission-critical, accuracy, non-blocking, megaavr, avr-da, avr-db, avr-dd, dxcore, avr128dx, avr64dx, avr32dx, megatinycore, dx-timerinterrupt, tcb-timers", - "description": "This library enables you to use Hardware-based PWM channels on Arduino AVRDx-based boards (AVR128Dx, AVR64Dx, AVR32Dx, etc.), using DxCore, to create and output PWM. The most important feature is they're purely hardware-based PWM channels, supporting very high PWM frequencies. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware-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 ISR, millis() or micros(). That's necessary if you need to control devices requiring high precision. New efficient setPWM_manual function to facilitate waveform creation using PWM.", + "description": "This library enables you to use Hardware-based PWM channels on Arduino AVRDx-based boards (AVR128Dx, AVR64Dx, AVR32Dx, etc.), using DxCore, to create and output PWM. The most important feature is they're purely hardware-based PWM channels, supporting very high PWM frequencies. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware-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 ISR, millis() or micros(). That's necessary if you need to control devices requiring high precision. New efficient setPWM_manual function to facilitate waveform creation using PWM. Now supporting AVRDD and DxCore v1.5.1", "authors": { "name": "Khoi Hoang", diff --git a/library.properties b/library.properties index 147561b..ac04b61 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=Dx_PWM -version=1.0.0 +version=1.1.0 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Hardware-based PWM channels on Arduino AVRDx-based boards (AVR128Dx, AVR64Dx, AVR32Dx, etc.), using DxCore, to create and output PWM. -paragraph=The most important feature is they're purely hardware-based PWM channels, supporting very high PWM frequencies. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware-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 ISR, millis() or micros(). That's necessary if you need to control devices requiring high precision. New efficient setPWM_manual function to facilitate waveform creation using PWM. +paragraph=The most important feature is they're purely hardware-based PWM channels, supporting very high PWM frequencies. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware-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 ISR, millis() or micros(). That's necessary if you need to control devices requiring high precision. New efficient setPWM_manual function to facilitate waveform creation using PWM. Now supporting AVRDD and DxCore v1.5.1 category=Device Control url=https://github.com/khoih-prog/Dx_PWM architectures=megaavr diff --git a/src/Dx_PWM.h b/src/Dx_PWM.h index 0290a40..6ccf22c 100644 --- a/src/Dx_PWM.h +++ b/src/Dx_PWM.h @@ -9,11 +9,12 @@ This is pure hardware-based PWM - Version: 1.0.0 + Version: 1.1.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 09/11/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore + 1.1.0 K.Hoang 30/12/2022 Add support to AVR DD (AVR64DD, AVR32DDx, AVR16DD, etc.) using breaking DxCore v1.5.1+ *****************************************************************************************************************************/ #pragma once @@ -57,13 +58,22 @@ #elif ( defined(__AVR_AVR64DD32__) || defined(__AVR_AVR64DD28__) || defined(__AVR_AVR64DD20__) || defined(__AVR_AVR64DD14__) ) #define BOARD_NAME F("AVR64DD") - #error AVR64DD not supported yet by the DxCore + #if ( (DXCORE_MAJOR == 1) && (DXCORE_MINOR < 5) ) + #error AVR64DD not supported yet + #endif #elif ( defined(__AVR_AVR32DD32__) || defined(__AVR_AVR32DD28__) || defined(__AVR_AVR32DD20__) || defined(__AVR_AVR32DD14__) ) #define BOARD_NAME F("AVR32DD") - #error AVR32DD not supported yet by the DxCore + + #if ( (DXCORE_MAJOR == 1) && (DXCORE_MINOR < 5) ) + #error AVR32DD not supported yet + #endif + #elif ( defined(__AVR_AVR16DD32__) || defined(__AVR_AVR16DD28__) || defined(__AVR_AVR16DD20__) || defined(__AVR_AVR16DD14__) ) #define BOARD_NAME F("AVR16DD") - #error AVR16DD not supported yet by the DxCore + + #if ( (DXCORE_MAJOR == 1) && (DXCORE_MINOR < 5) ) + #error AVR16DD not supported yet + #endif ////////////////////////// __AVR_DU__ ////////////////////////// @@ -100,13 +110,13 @@ //////////////////////////////////////// #ifndef DX_PWM_VERSION - #define DX_PWM_VERSION F("Dx_PWM v1.0.0") + #define DX_PWM_VERSION F("Dx_PWM v1.1.0") #define DX_PWM_VERSION_MAJOR 1 - #define DX_PWM_VERSION_MINOR 0 + #define DX_PWM_VERSION_MINOR 1 #define DX_PWM_VERSION_PATCH 0 - #define DX_PWM_VERSION_INT 1000000 + #define DX_PWM_VERSION_INT 1001000 #endif //////////////////////////////////////// @@ -142,6 +152,11 @@ //////////////////////////////////////// //////////////////////////////////////// +// From DxCore v1.5.1, must use __PeripheralControl instead of PeripheralControl +#if ( (DXCORE_MAJOR == 1) && (DXCORE_MINOR >= 5) ) + #define PeripheralControl __PeripheralControl +#endif + extern uint8_t PeripheralControl; //////////////////////////////////////// @@ -260,6 +275,8 @@ class Dx_PWM /////////////////////////////////////////// +#if defined(TCA1) + void setPeriod_TimerA1(uint32_t microseconds) __attribute__((always_inline)) { // TCA Clock is F_CPU / 64, 375.0KHz for 24MHz @@ -320,7 +337,7 @@ class Dx_PWM PWM_LOGDEBUG3("setPeriod_TimerA1: pwmPeriod =", pwmPeriod, ", _actualFrequency =", _actualFrequency); } - +#endif /////////////////////////////////////////// void setPeriod_TimerB(unsigned long microseconds) __attribute__((always_inline)) @@ -511,7 +528,7 @@ class Dx_PWM /////////////////////////////////////////// -#ifdef TCA1 +#if defined(TCA1) /* case TIMERA1: */ tcaroute &= (0x18); diff --git a/src/PWM_Generic_Debug.h b/src/PWM_Generic_Debug.h index 28f690f..d5de5d4 100644 --- a/src/PWM_Generic_Debug.h +++ b/src/PWM_Generic_Debug.h @@ -9,11 +9,12 @@ This is pure hardware-based PWM - Version: 1.0.0 + Version: 1.1.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 09/11/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore + 1.1.0 K.Hoang 30/12/2022 Add support to AVR DD (AVR64DD, AVR32DDx, AVR16DD, etc.) using breaking DxCore v1.5.1+ *****************************************************************************************************************************/ #pragma once