Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
v1.0.1 to add PWM_StepperControl example
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
khoih-prog committed Jan 22, 2023
1 parent 7fa4865 commit 3743937
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 15 deletions.
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
```



26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

---
---
Expand Down Expand Up @@ -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**


---
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


---
---
Expand All @@ -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


<table>
<tr>
<td align="center"><a href="https://github.com/dinther"><img src="https://github.com/dinther.png" width="100px;" alt="dinther"/><br /><sub><b>Paul van Dinther</b></sub></a><br /></td>
</tr>
</table>


---

## Contributing

If you want to contribute to this project:

- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>


---
---

## Table of Contents

* [Changelog](#changelog)
* [Releases v1.0.1](#releases-v101)
* [Initial Releases v1.0.0](#Initial-Releases-v100)

---
---

## 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)
Expand Down
79 changes: 79 additions & 0 deletions examples/PWM_StepperControl/PWM_StepperControl.ino
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=nRF52_PWM
version=1.0.0
version=1.0.1
author=Khoi Hoang <khoih.prog@gmail.com>
maintainer=Khoi Hoang <khoih.prog@gmail.com>
sentence=This library enables you to use Hardware-based PWM channels on nRF52-based boards to create and output PWM to pins.
Expand Down
3 changes: 2 additions & 1 deletion src/PWM_Generic_Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/nRF52_PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

////////////////////////////////////////
Expand Down

0 comments on commit 3743937

Please sign in to comment.