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

Commit

Permalink
v1.0.3 to add PWM_StepperControl example
Browse files Browse the repository at this point in the history
### Releases v1.0.3

1. Add example [PWM_StepperControl](https://github.com/khoih-prog/nRF52_MBED_PWM/tree/main/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM
  • Loading branch information
khoih-prog authored Jan 22, 2023
1 parent baddaab commit 8c30f65
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 22 deletions.
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
* [Examples](#examples)
* [ 1. PWM_Multi](examples/PWM_Multi)
* [ 2. PWM_Single](examples/PWM_Single)
* [ 3. multiFileProject](examples/multiFileProject). **New**
* [ 3. multiFileProject](examples/multiFileProject)
* [ 4. PWM_StepperControl](examples/PWM_StepperControl) **New**
* [Example PWM_Multi](#example-PWM_Multi)
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
* [1. PWM_Single on Nano_33_BLE](#1-PWM_Single-on-Nano_33_BLE)
Expand Down Expand Up @@ -101,7 +102,7 @@ This non-being-blocked important feature is absolutely necessary for mission-cri

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. [`Arduino mbed_nano core 3.4.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) MBED nRF52840-based boards such as **Nano_33_BLE, Nano_33_BLE_Sense**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
3. `Seeeduino mbed core 2.7.2+` for Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**
3. [`Seeeduino mbed core 2.9.0+`](https://github.com/Seeed-Studio/ArduinoCore-mbed) for Seeed nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**. [![GitHub release](https://img.shields.io/github/release/Seeed-Studio/ArduinoCore-mbed.svg)](https://github.com/Seeed-Studio/ArduinoCore-mbed/releases/latest)

---
---
Expand Down Expand Up @@ -238,7 +239,8 @@ if (pwm)

1. [PWM_Multi](examples/PWM_Multi)
2. [PWM_Single](examples/PWM_Single)
3. [**multiFileProject**](examples/multiFileProject) **New**
3. [multiFileProject](examples/multiFileProject)
4. [**PWM_StepperControl**](examples/PWM_StepperControl) **New**


---
Expand All @@ -261,7 +263,7 @@ The following is the sample terminal output when running example [PWM_Single](ex

```cpp
Starting PWM_Single on Nano_33_BLE
nRF52_MBED_PWM v1.0.2
nRF52_MBED_PWM v1.0.3
[PWM] Freq = 5000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 2

============================================
Expand Down Expand Up @@ -293,7 +295,7 @@ The following is the sample terminal output when running example [**PWM_Multi**]
```cpp
Starting PWM_Multi on Nano_33_BLE
nRF52_MBED_PWM v1.0.2
nRF52_MBED_PWM v1.0.3
[PWM] Freq = 1000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 2
[PWM] Freq = 2500.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 3
[PWM] Freq = 4000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 4
Expand Down Expand Up @@ -366,14 +368,16 @@ Submit issues to: [nRF52_MBED_PWM issues](https://github.com/khoih-prog/nRF52_MB

## DONE

1. Basic hardware multi-channel PWM for **Nano_33_BLE**.
2. Add Table of Contents
3. Permit to start, stop, modify, restore PWM settings on-the-fly
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Use `h-only` style
6. Add functions to read PWM parameters.
7. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
8. Add astyle using `allman` style. Restyle the library
1. Basic hardware multi-channel PWM for **Nano_33_BLE**.
2. Add Table of Contents
3. Permit to start, stop, modify, restore PWM settings on-the-fly
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Use `h-only` style
6. Add functions to read PWM parameters.
7. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
8. Add astyle using `allman` style. Restyle the library
9. Add example [PWM_StepperControl](https://github.com/khoih-prog/nRF52_MBED_PWM/tree/main/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM


---
---
Expand All @@ -382,6 +386,15 @@ Submit issues to: [nRF52_MBED_PWM issues](https://github.com/khoih-prog/nRF52_MB

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
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
<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.3](#Releases-v103)
* [Releases v1.0.2](#Releases-v102)
* [Releases v1.0.1](#Releases-v101)
* [Initial Releases v1.0.0](#Initial-Releases-v100)
Expand All @@ -26,6 +28,10 @@

## Changelog

### Releases v1.0.3

1. Add example [PWM_StepperControl](https://github.com/khoih-prog/nRF52_MBED_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)

### Releases v1.0.2

1. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
Expand Down
76 changes: 76 additions & 0 deletions examples/PWM_StepperControl/PWM_StepperControl.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/****************************************************************************************************************************
PWM_StepperControl.ino
For Nano_33_BLE or Nano_33_BLE_Sense boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_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

#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
#error This code is designed to run on nRF52-based Nano-33-BLE boards using mbed-RTOS platform! Please check your Tools->Board setting.
#endif

#define _PWM_LOGLEVEL_ 1

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "nRF52_MBED_PWM.h"

// All the digital pins on Arduino Nano 33 BLE sense are PWM-enabled pins which are numbered from D0 to D13

#define STEP_PIN D2
#define DIR_PIN D9

mbed::PwmOut* stepper = nullptr;

void setSpeed(int speed)
{
if (speed == 0)
{
// Use DC = 0 to stop stepper
setPWM(stepper, STEP_PIN, 500, 0);
}
else
{
// Set the frequency of the PWM output and a duty cycle of 50%
digitalWrite(DIR_PIN, (speed < 0));
setPWM(stepper, 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_MBED_PWM_VERSION);
}

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_MBED_PWM",
"version": "1.0.2",
"version": "1.0.3",
"keywords": "timing, device, control, timer, pwm, interrupt, isr, isr-based, hardware-timer, mission-critical, accuracy, non-blocking, mbed, mbed-nano, nrf52840, nano-33-ble, nano-33-ble-sense, precise, hardware",
"description": "This library enables you to use Hardware-based PWM to create and output PWM to pins on an nRF52840-based Nano_33_BLE board. These PWM channels, using nRF52840 Hardware PWM, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software ir ISR-based PWM, using millis(), micros() or Timer Interrupt. This important feature is absolutely necessary for mission-critical tasks. You can start, stop, change and restore the settings of any PWM channel on-the-fly.",
"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_MBED_PWM
version=1.0.2
version=1.0.3
author=Khoi Hoang <khoih.prog@gmail.com>
maintainer=Khoi Hoang <khoih.prog@gmail.com>
sentence=This library enables you to use Hardware-based PWM to create and output PWM to pins on an nRF52840-based Nano_33_BLE board.
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 @@ -6,13 +6,14 @@
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
Licensed under MIT license
Version: 1.0.2
Version: 1.0.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/nRF52_MBED_PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
Licensed under MIT license
Version: 1.0.2
Version: 1.0.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
*****************************************************************************************************************************/

#pragma once
Expand Down
9 changes: 5 additions & 4 deletions src/nRF52_MBED_PWM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
Licensed under MIT license
Version: 1.0.2
Version: 1.0.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
*****************************************************************************************************************************/

#pragma once
Expand All @@ -25,13 +26,13 @@
#endif

#ifndef nRF52_MBED_PWM_VERSION
#define nRF52_MBED_PWM_VERSION "nRF52_MBED_PWM v1.0.2"
#define nRF52_MBED_PWM_VERSION "nRF52_MBED_PWM v1.0.3"

#define nRF52_MBED_PWM_VERSION_MAJOR 1
#define nRF52_MBED_PWM_VERSION_MINOR 0
#define nRF52_MBED_PWM_VERSION_PATCH 2
#define nRF52_MBED_PWM_VERSION_PATCH 3

#define nRF52_MBED_PWM_VERSION_INT 1000002
#define nRF52_MBED_PWM_VERSION_INT 1000003
#endif


Expand Down
3 changes: 2 additions & 1 deletion src/nRF52_MBED_PWM_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
Licensed under MIT license
Version: 1.0.2
Version: 1.0.3
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
*****************************************************************************************************************************/

#ifndef nRF52_MBED_PWM_IMPL_H
Expand Down

0 comments on commit 8c30f65

Please sign in to comment.