diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 169a8df..3e6e419 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,18 +10,23 @@ However, before reporting a bug please check through the following: If you don't find anything, please [open a new issue](https://github.com/khoih-prog/nRF52_PWM/issues/new). +--- + ### How to submit a bug report Please ensure to specify the following: * Arduino IDE version (e.g. 1.8.19) or Platform.io version -* `NRF52` Core Version (e.g. Adafruit NRF52 core v1.3.0, Seeed nRF52 core v1.0.0) +* `NRF52` Core Version (e.g. Adafruit NRF52 core v1.3.0, Seeed nRF52 core v1.1.0) * 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: * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` * Network configuration +Please be educated, civilized and constructive as you've always been. 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 @@ -30,7 +35,7 @@ Arduino IDE version: 1.8.19 Adafruit NRF52 Core Version 1.3.0 NRF52840_ITSYBITSY OS: Ubuntu 20.04 LTS -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-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Context: I encountered a crash while using this library @@ -71,3 +76,5 @@ xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_PWM_GitHub$ xy@xy-Inspiron-3593:~/Arduino/xy/nRF52_PWM_GitHub$ bash utils/restyle.sh ``` + + diff --git a/README.md b/README.md index 516148c..9bb15a7 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ * [ 5. PWM_Multi](examples/PWM_Multi) * [ 6. PWM_MultiChannel](examples/PWM_MultiChannel) * [ 7. PWM_Waveform](examples/PWM_Waveform) + * [ 8. PWM_StepperControl](examples/PWM_StepperControl) **New** * [Example PWM_Multi](#example-PWM_Multi) * [Debug Terminal Output Samples](#debug-terminal-output-samples) * [1. PWM_DynamicDutyCycle on NRF52840_FEATHER](#1-PWM_DynamicDutyCycle-on-NRF52840_FEATHER) @@ -132,7 +133,7 @@ Functions using normal software-based PWMs, relying on `loop()` and calling `mil 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. [`Adafruit nRF52 v1.3.0+`](https://github.com/adafruit/Adafruit_nRF52_Arduino) 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. [![GitHub release](https://img.shields.io/github/release/adafruit/Adafruit_nRF52_Arduino.svg)](https://github.com/adafruit/Adafruit_nRF52_Arduino/releases/latest) - 3. [`Seeeduino nRF52 core 1.0.0+`](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino) for Seeeduino nRF52840-based boards such as **Seeed_XIAO_NRF52840 and Seeed_XIAO_NRF52840_SENSE**. [![GitHub release](https://img.shields.io/github/release/Seeed-Studio/Adafruit_nRF52_Arduino.svg)](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino/releases/latest) + 3. [`Seeeduino nRF52 core 1.1.0+`](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino) for Seeeduino nRF52840-based boards such as **Seeed_XIAO_NRF52840 and Seeed_XIAO_NRF52840_SENSE**. [![GitHub release](https://img.shields.io/github/release/Seeed-Studio/Adafruit_nRF52_Arduino.svg)](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino/releases/latest) --- --- @@ -324,6 +325,7 @@ PWM_Instance->setPWM_manual(PWM_Pins, new_level); 5. [PWM_Multi](examples/PWM_Multi) 6. [PWM_MultiChannel](examples/PWM_MultiChannel) 7. [PWM_Waveform](examples/PWM_Waveform) + 8. [PWM_StepperControl](examples/PWM_StepperControl) **New** --- @@ -346,7 +348,7 @@ The following is the sample terminal output when running example [PWM_DynamicDut ```cpp Starting PWM_DynamicDutyCycle on NRF52840_FEATHER -nRF52_PWM v1.0.0 +nRF52_PWM v1.0.1 [PWM] nRF52_PWM: NRF52_PWM_TOKEN = 0x345CD8 [PWM] calcPrescaler: OK period = 200 , _prescaler = 1 , countTOP = 3200 [PWM] calcPrescaler: _dutycycle = 0 , frequency = 5000.00 , _prescalerConfigBits = 0 , _compareValue = 3199 @@ -387,7 +389,7 @@ The following is the sample terminal output when running example [**PWM_Multi**] ```cpp Starting PWM_Multi on NRF52840_FEATHER -nRF52_PWM v1.0.0 +nRF52_PWM v1.0.1 [PWM] nRF52_PWM: NRF52_PWM_TOKEN = 0x389838 [PWM] calcPrescaler: OK period = 500 , _prescaler = 1 , countTOP = 8000 [PWM] calcPrescaler: _dutycycle = 6553 , frequency = 2000.00 , _prescalerConfigBits = 0 , _compareValue = 7999 @@ -449,7 +451,7 @@ The following is the sample terminal output when running example [**PWM_DynamicF ```cpp Starting PWM_DynamicFreq on NRF52840_FEATHER -nRF52_PWM v1.0.0 +nRF52_PWM v1.0.1 [PWM] nRF52_PWM: NRF52_PWM_TOKEN = 0x2B8A8B [PWM] calcPrescaler: OK period = 100 , _prescaler = 1 , countTOP = 1600 [PWM] calcPrescaler: _dutycycle = 32768 , frequency = 10000.00 , _prescalerConfigBits = 0 , _compareValue = 1599 @@ -488,7 +490,7 @@ The following is the sample terminal output when running example [**PWM_Waveform ```cpp Starting PWM_Waveform on NRF52840_FEATHER -nRF52_PWM v1.0.0 +nRF52_PWM v1.0.1 [PWM] setPWM_Int: dutycycle = 0 , frequency = 2000.00 ============================================================================================ Actual data: pin = 6, PWM DutyCycle = 0.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000 @@ -546,7 +548,7 @@ The following is the sample terminal output when running example [**PWM_Waveform ```cpp Starting PWM_Waveform on NRF52840_ITSYBITSY -nRF52_PWM v1.0.0 +nRF52_PWM v1.0.1 [PWM] setPWM_Int: dutycycle = 0 , frequency = 2000.00 ============================================================================================ Actual data: pin = 7, PWM DutyCycle = 0.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000 @@ -639,6 +641,8 @@ Submit issues to: [nRF52_PWM issues](https://github.com/khoih-prog/nRF52_PWM/iss 1. Basic hardware PWM-channels for **nRF52-based boards, such as AdaFruit Itsy-Bitsy nRF52840, Feather nRF52840 Express, Seeed XIAO nRF52840, Seeed XIAO nRF52840 Sense**, etc. using - [`Adafruit nRF52 core`](https://github.com/adafruit/Adafruit_nRF52_Arduino) or - [`Seeeduino nRF52 core`](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino) + 2. Add example [PWM_StepperControl](https://github.com/khoih-prog/nRF52_PWM/tree/main/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM + --- --- @@ -647,12 +651,22 @@ Submit issues to: [nRF52_PWM issues](https://github.com/khoih-prog/nRF52_PWM/iss Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library. +1. Thanks to [Paul van Dinther](https://github.com/dinther) for proposing new way to use PWM to drive Stepper-Motor in [Using PWM to step a stepper driver #16](https://github.com/khoih-prog/RP2040_PWM/issues/16), leading to v2.0.3 + + + + + + +
dinther
Paul van Dinther

+ --- ## Contributing If you want to contribute to this project: + - Report bugs and errors - Ask for enhancements - Create issues and pull requests diff --git a/changelog.md b/changelog.md index 2818d21..36b5b08 100644 --- a/changelog.md +++ b/changelog.md @@ -10,12 +10,14 @@ Donate to my libraries using BuyMeACoffee + --- --- ## Table of Contents * [Changelog](#changelog) + * [Releases v1.0.1](#releases-v101) * [Initial Releases v1.0.0](#Initial-Releases-v100) --- @@ -23,6 +25,10 @@ ## Changelog +### Releases v1.0.1 + +1. Add example [PWM_StepperControl](https://github.com/khoih-prog/nRF52_PWM/tree/main/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM. Check [Using PWM to step a stepper driver #16](https://github.com/khoih-prog/RP2040_PWM/issues/16) + ### Initial Releases v1.0.0 1. Initial coding to support **nRF52-based boards, such as AdaFruit Itsy-Bitsy nRF52840, Feather nRF52840 Express, Seeed XIAO nRF52840, Seeed XIAO nRF52840 Sense**, etc. using [`Adafruit nRF52 core`](https://github.com/adafruit/Adafruit_nRF52_Arduino) or [`Seeeduino nRF52 core`](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino) diff --git a/examples/PWM_StepperControl/PWM_StepperControl.ino b/examples/PWM_StepperControl/PWM_StepperControl.ino new file mode 100644 index 0000000..e7ebbf7 --- /dev/null +++ b/examples/PWM_StepperControl/PWM_StepperControl.ino @@ -0,0 +1,79 @@ +/**************************************************************************************************************************** + PWM_StepperControl.ino + For nRF52-based boards usinghardware-based PWM with Adafruit_nRF52_Arduino core + Written by Khoi Hoang + + Built by Khoi Hoang https://github.com/khoih-prog/nRF52_PWM + Licensed under MIT license + + Credits of Paul van Dinther (https://github.com/dinther). Check https://github.com/khoih-prog/RP2040_PWM/issues/16 +*****************************************************************************************************************************/ + +// Use with Stepper-Motor driver, such as TMC2209 + +#define _PWM_LOGLEVEL_ 4 + +// Select false to use PWM +#define USING_TIMER false //true + +#include "nRF52_PWM.h" + +// OK for Feather_nRF52840_Express (5, 6, 9-13, 14-21/A0-A7, etc.) +// OK for ItsyBitsy_nRF52840_Express (5, 7, 9-13, 14-20/A0-A6, etc.) + +#define STEP_PIN 5 +#define DIR_PIN 9 + +nRF52_PWM* stepper; + +void setSpeed(int speed) +{ + if (speed == 0) + { + // Use DC = 0 to stop stepper + stepper->setPWM(STEP_PIN, 500, 0); + } + else + { + // Set the frequency of the PWM output and a duty cycle of 50% + digitalWrite(DIR_PIN, (speed < 0)); + stepper->setPWM(STEP_PIN, abs(speed), 50); + } +} + +void setup() +{ + pinMode(DIR_PIN, OUTPUT); + + Serial.begin(115200); + + while (!Serial && millis() < 5000); + + delay(100); + + Serial.print(F("\nStarting PWM_StepperControl on ")); + Serial.println(BOARD_NAME); + Serial.println(NRF52_PWM_VERSION); + + // Create PWM object and passed just a random frequency of 500 + // The duty cycle is how you turn the motor on and off + stepper = new nRF52_PWM(STEP_PIN, 500, 0); +} + +void loop() +{ + setSpeed(1000); + delay(3000); + + // Stop before reversing + setSpeed(0); + delay(3000); + + // Reversing + setSpeed(-500); + delay(3000); + + // Stop before reversing + setSpeed(0); + delay(3000); +} diff --git a/library.json b/library.json index d834098..482d091 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "nRF52_PWM", - "version": "1.0.0", + "version": "1.0.1", "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, nrf52, nrf52840, nrf52832, itsy-bitsy-nrf52840, feather-nrf52840", "description": "This library enables you to use Hardware-based PWM channels on nRF52-based boards to create and output PWM to pins. 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", "authors": diff --git a/library.properties b/library.properties index 6eb8671..78961e3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=nRF52_PWM -version=1.0.0 +version=1.0.1 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Hardware-based PWM channels on nRF52-based boards to create and output PWM to pins. diff --git a/src/PWM_Generic_Debug.h b/src/PWM_Generic_Debug.h index d8cb237..8fd0d03 100644 --- a/src/PWM_Generic_Debug.h +++ b/src/PWM_Generic_Debug.h @@ -7,11 +7,12 @@ Built by Khoi Hoang https://github.com/khoih-prog/nRF52_PWM Licensed under MIT license - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 05/11/2022 Initial coding for nRF52-based boards + 1.0.1 K Hoang 22/01/2023 Add `PWM_StepperControl` example *****************************************************************************************************************************/ #pragma once diff --git a/src/nRF52_PWM.h b/src/nRF52_PWM.h index dd90bf4..76fe0cb 100644 --- a/src/nRF52_PWM.h +++ b/src/nRF52_PWM.h @@ -7,11 +7,12 @@ Built by Khoi Hoang https://github.com/khoih-prog/nRF52_PWM Licensed under MIT license - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 05/11/2022 Initial coding for nRF52-based boards + 1.0.1 K Hoang 22/01/2023 Add `PWM_StepperControl` example *****************************************************************************************************************************/ #pragma once @@ -48,13 +49,13 @@ //////////////////////////////////////// #ifndef NRF52_PWM_VERSION - #define NRF52_PWM_VERSION "nRF52_PWM v1.0.0" + #define NRF52_PWM_VERSION "nRF52_PWM v1.0.1" #define NRF52_PWM_VERSION_MAJOR 1 #define NRF52_PWM_VERSION_MINOR 0 - #define NRF52_PWM_VERSION_PATCH 0 + #define NRF52_PWM_VERSION_PATCH 1 - #define NRF52_PWM_VERSION_INT 1000000 + #define NRF52_PWM_VERSION_INT 1000001 #endif ////////////////////////////////////////