From ff4b702147be432df1c507b4748871847a8ca9d6 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 7 Mar 2025 12:20:33 -0800 Subject: [PATCH 1/3] Added support for Adafruit QtPy M0 board. --- README.md | 11 ++++++----- src/SAMD21turboPWM.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index af5460e..0fc73dc 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,15 @@ Set input clock divider and Turbo Mode (which uses a 96MHz instead of a 48Mhz in ```pwm.setClockDivider([1-255], [true, false]);``` -**Initialise timer x, with prescaler, with steps (resolution), with fast aka single-slope PWM (or not -> double-slope PWM):** +**Initialize timer x, with prescaler, with steps (resolution), with fast aka single-slope PWM (or not -> double-slope PWM):** ```pwm.timer([0, 1, 2], [1, 2, 4, 8, 16, 64, 256, 1024], [2-MaxSteps], [true, false]);``` -* For the Arduino Nano 33 IoT, you need to initialise timer 1 for pins 4 and 7, timer 0 for pins 5, 6, 8, and 12, and timer 2 for pins 11 and 13; -* For the Arduino Zero (untested), Adafruit Feather M0 (untested), and Adafruit Itsy Bitsy M0 you need to initialise timer 0 for pins 3, 4, 10 and 12, timer 1 for pins 8 and 9, and timer 2 for pins 11 and 13; -* For the Arduino MKR series (untested), you need to initialise timer 1 for pins 2 and 3, timer 0 for pins 4, 5, 6 and 7, and timer 2 for pins 8 and 9; -* For the Adafruit Trinket M0, you need to initialise timer 0 for pins 0 and 2, and timer 1 for pins 3 and 4. +* For the Arduino Nano 33 IoT, you need to initialize timer 1 for pins 4 and 7, timer 0 for pins 5, 6, 8, and 12, and timer 2 for pins 11 and 13; +* For the Arduino Zero (untested), Adafruit Feather M0 (untested), and Adafruit Itsy Bitsy M0 you need to initialize timer 0 for pins 3, 4, 10 and 12, timer 1 for pins 8 and 9, and timer 2 for pins 11 and 13; +* For the Arduino MKR series (untested), you need to initialize timer 1 for pins 2 and 3, timer 0 for pins 4, 5, 6 and 7, and timer 2 for pins 8 and 9; +* For the Adafruit Trinket M0, you need to initialize timer 0 for pins 0 and 2, and timer 1 for pins 3 and 4. +* For the Adafruit QtPy M0, you need to initialize timer 0 for pins 2, 3, 8, and 10. Timer 1 for pins 6, 7, and 9. Timer 2 for pins 4 and 5. MaxSteps is 0xFFFFFF for (24-bits) timers 0 and 1, and 0xFFFF for (16 bits) timer 2. diff --git a/src/SAMD21turboPWM.h b/src/SAMD21turboPWM.h index 528b782..1f40e68 100644 --- a/src/SAMD21turboPWM.h +++ b/src/SAMD21turboPWM.h @@ -116,6 +116,21 @@ static const PinLookup pinTable[] = { { 4, PORTA, 6, 1, ®_TCC1_CCB0, PORT_PMUX_PMUXE_E} //Table end +#elif defined (ADAFRUIT_QTPY_M0) +//Table begin +{-1, 0, 0, 0, 0, 0}, +{-1, 0, 0, 0, 0, 0}, +{ 2, PORTA, 4, 0, ®_TCC0_CCB0, PORT_PMUX_PMUXE_E}, +{ 3, PORTA, 5, 0, ®_TCC0_CCB1, PORT_PMUX_PMUXO_E}, +{ 4, PORTA, 16, 2, ®_TCC2_CCB0, PORT_PMUX_PMUXE_E}, +{ 5, PORTA, 17, 2, ®_TCC2_CCB1, PORT_PMUX_PMUXO_E}, +{ 6, PORTA, 6, 1, ®_TCC1_CCB0, PORT_PMUX_PMUXE_E}, +{ 7, PORTA, 7, 1, ®_TCC1_CCB1, PORT_PMUX_PMUXO_E}, +{ 8, PORTA, 11, 0, ®_TCC0_CCB3, PORT_PMUX_PMUXO_F}, // alt timer +{ 9, PORTA, 9, 1, ®_TCC1_CCB3, PORT_PMUX_PMUXO_F}, // alt timer +{10, PORTA, 10, 0, ®_TCC0_CCB2, PORT_PMUX_PMUXE_F} // alt timer +//Table end + #else #error Board not supported by Turbo PWM Library #endif From c8cc53832f692372bdf3a2a9112585dc1db3082c Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 7 Mar 2025 14:58:50 -0800 Subject: [PATCH 2/3] Fixed incorrect CCB register value --- src/SAMD21turboPWM.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SAMD21turboPWM.h b/src/SAMD21turboPWM.h index 1f40e68..2f6996c 100644 --- a/src/SAMD21turboPWM.h +++ b/src/SAMD21turboPWM.h @@ -127,7 +127,7 @@ static const PinLookup pinTable[] = { { 6, PORTA, 6, 1, ®_TCC1_CCB0, PORT_PMUX_PMUXE_E}, { 7, PORTA, 7, 1, ®_TCC1_CCB1, PORT_PMUX_PMUXO_E}, { 8, PORTA, 11, 0, ®_TCC0_CCB3, PORT_PMUX_PMUXO_F}, // alt timer -{ 9, PORTA, 9, 1, ®_TCC1_CCB3, PORT_PMUX_PMUXO_F}, // alt timer +{ 9, PORTA, 9, 1, ®_TCC1_CCB1, PORT_PMUX_PMUXO_F}, // alt timer {10, PORTA, 10, 0, ®_TCC0_CCB2, PORT_PMUX_PMUXE_F} // alt timer //Table end From 9613b32e018c39ffd9bc8137e1b769c1bb3bf0a7 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 7 Mar 2025 15:42:22 -0800 Subject: [PATCH 3/3] Updated readme with note about pinout for Adafruit QtPy --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fc73dc..4cec916 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Set input clock divider and Turbo Mode (which uses a 96MHz instead of a 48Mhz in * For the Arduino Zero (untested), Adafruit Feather M0 (untested), and Adafruit Itsy Bitsy M0 you need to initialize timer 0 for pins 3, 4, 10 and 12, timer 1 for pins 8 and 9, and timer 2 for pins 11 and 13; * For the Arduino MKR series (untested), you need to initialize timer 1 for pins 2 and 3, timer 0 for pins 4, 5, 6 and 7, and timer 2 for pins 8 and 9; * For the Adafruit Trinket M0, you need to initialize timer 0 for pins 0 and 2, and timer 1 for pins 3 and 4. -* For the Adafruit QtPy M0, you need to initialize timer 0 for pins 2, 3, 8, and 10. Timer 1 for pins 6, 7, and 9. Timer 2 for pins 4 and 5. +* For the Adafruit QtPy M0, you need to initialize timer 0 for pins 2, 3, 8, and 10. Timer 1 for pins 6, 7, and 9. Timer 2 for pins 4 and 5. **Note** that pins 7 & 9 share a capture and compare buffer (CCB1) so you can't get different PWM duty cycles from them at the same time. MaxSteps is 0xFFFFFF for (24-bits) timers 0 and 1, and 0xFFFF for (16 bits) timer 2.