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

Commit 8c30f65

Browse files
authored
v1.0.3 to add PWM_StepperControl example
### 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
1 parent baddaab commit 8c30f65

File tree

9 files changed

+121
-22
lines changed

9 files changed

+121
-22
lines changed

README.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
* [Examples](#examples)
3333
* [ 1. PWM_Multi](examples/PWM_Multi)
3434
* [ 2. PWM_Single](examples/PWM_Single)
35-
* [ 3. multiFileProject](examples/multiFileProject). **New**
35+
* [ 3. multiFileProject](examples/multiFileProject)
36+
* [ 4. PWM_StepperControl](examples/PWM_StepperControl) **New**
3637
* [Example PWM_Multi](#example-PWM_Multi)
3738
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
3839
* [1. PWM_Single on Nano_33_BLE](#1-PWM_Single-on-Nano_33_BLE)
@@ -101,7 +102,7 @@ This non-being-blocked important feature is absolutely necessary for mission-cri
101102

102103
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)
103104
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)
104-
3. `Seeeduino mbed core 2.7.2+` for Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**
105+
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)
105106

106107
---
107108
---
@@ -238,7 +239,8 @@ if (pwm)
238239

239240
1. [PWM_Multi](examples/PWM_Multi)
240241
2. [PWM_Single](examples/PWM_Single)
241-
3. [**multiFileProject**](examples/multiFileProject) **New**
242+
3. [multiFileProject](examples/multiFileProject)
243+
4. [**PWM_StepperControl**](examples/PWM_StepperControl) **New**
242244

243245

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

262264
```cpp
263265
Starting PWM_Single on Nano_33_BLE
264-
nRF52_MBED_PWM v1.0.2
266+
nRF52_MBED_PWM v1.0.3
265267
[PWM] Freq = 5000.00, DutyCycle % = 50.00, DutyCycle = 0.50, Pin = 2
266268

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

367369
## DONE
368370

369-
1. Basic hardware multi-channel PWM for **Nano_33_BLE**.
370-
2. Add Table of Contents
371-
3. Permit to start, stop, modify, restore PWM settings on-the-fly
372-
4. Optimize library code by using `reference-passing` instead of `value-passing`
373-
5. Use `h-only` style
374-
6. Add functions to read PWM parameters.
375-
7. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
376-
8. Add astyle using `allman` style. Restyle the library
371+
1. Basic hardware multi-channel PWM for **Nano_33_BLE**.
372+
2. Add Table of Contents
373+
3. Permit to start, stop, modify, restore PWM settings on-the-fly
374+
4. Optimize library code by using `reference-passing` instead of `value-passing`
375+
5. Use `h-only` style
376+
6. Add functions to read PWM parameters.
377+
7. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
378+
8. Add astyle using `allman` style. Restyle the library
379+
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
380+
377381

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

383387
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
384388

389+
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
390+
391+
392+
<table>
393+
<tr>
394+
<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>
395+
</tr>
396+
</table>
397+
385398
---
386399

387400
## Contributing

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
<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>
1212
<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>
1313

14+
1415
---
1516
---
1617

1718
## Table of Contents
1819

1920
* [Changelog](#changelog)
21+
* [Releases v1.0.3](#Releases-v103)
2022
* [Releases v1.0.2](#Releases-v102)
2123
* [Releases v1.0.1](#Releases-v101)
2224
* [Initial Releases v1.0.0](#Initial-Releases-v100)
@@ -26,6 +28,10 @@
2628

2729
## Changelog
2830

31+
### Releases v1.0.3
32+
33+
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)
34+
2935
### Releases v1.0.2
3036

3137
1. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeeduino `mbed` core
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/****************************************************************************************************************************
2+
PWM_StepperControl.ino
3+
For Nano_33_BLE or Nano_33_BLE_Sense boards
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
7+
Licensed under MIT license
8+
9+
Credits of Paul van Dinther (https://github.com/dinther). Check https://github.com/khoih-prog/RP2040_PWM/issues/16
10+
*****************************************************************************************************************************/
11+
12+
// Use with Stepper-Motor driver, such as TMC2209
13+
14+
#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
15+
#error This code is designed to run on nRF52-based Nano-33-BLE boards using mbed-RTOS platform! Please check your Tools->Board setting.
16+
#endif
17+
18+
#define _PWM_LOGLEVEL_ 1
19+
20+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
21+
#include "nRF52_MBED_PWM.h"
22+
23+
// All the digital pins on Arduino Nano 33 BLE sense are PWM-enabled pins which are numbered from D0 to D13
24+
25+
#define STEP_PIN D2
26+
#define DIR_PIN D9
27+
28+
mbed::PwmOut* stepper = nullptr;
29+
30+
void setSpeed(int speed)
31+
{
32+
if (speed == 0)
33+
{
34+
// Use DC = 0 to stop stepper
35+
setPWM(stepper, STEP_PIN, 500, 0);
36+
}
37+
else
38+
{
39+
// Set the frequency of the PWM output and a duty cycle of 50%
40+
digitalWrite(DIR_PIN, (speed < 0));
41+
setPWM(stepper, STEP_PIN, abs(speed), 50);
42+
}
43+
}
44+
45+
void setup()
46+
{
47+
pinMode(DIR_PIN, OUTPUT);
48+
49+
Serial.begin(115200);
50+
51+
while (!Serial && millis() < 5000);
52+
53+
delay(100);
54+
55+
Serial.print(F("\nStarting PWM_StepperControl on "));
56+
Serial.println(BOARD_NAME);
57+
Serial.println(nRF52_MBED_PWM_VERSION);
58+
}
59+
60+
void loop()
61+
{
62+
setSpeed(1000);
63+
delay(3000);
64+
65+
// Stop before reversing
66+
setSpeed(0);
67+
delay(3000);
68+
69+
// Reversing
70+
setSpeed(-500);
71+
delay(3000);
72+
73+
// Stop before reversing
74+
setSpeed(0);
75+
delay(3000);
76+
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nRF52_MBED_PWM",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"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",
55
"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.",
66
"authors":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=nRF52_MBED_PWM
2-
version=1.0.2
2+
version=1.0.3
33
author=Khoi Hoang <khoih.prog@gmail.com>
44
maintainer=Khoi Hoang <khoih.prog@gmail.com>
55
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.

src/PWM_Generic_Debug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
77
Licensed under MIT license
88
9-
Version: 1.0.2
9+
Version: 1.0.3
1010
1111
Version Modified By Date Comments
1212
------- ----------- ---------- -----------
1313
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1414
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1515
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
16+
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
1617
*****************************************************************************************************************************/
1718

1819
#pragma once

src/nRF52_MBED_PWM.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
77
Licensed under MIT license
88
9-
Version: 1.0.2
9+
Version: 1.0.3
1010
1111
Version Modified By Date Comments
1212
------- ----------- ---------- -----------
1313
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1414
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1515
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
16+
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
1617
*****************************************************************************************************************************/
1718

1819
#pragma once

src/nRF52_MBED_PWM.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
77
Licensed under MIT license
88
9-
Version: 1.0.2
9+
Version: 1.0.3
1010
1111
Version Modified By Date Comments
1212
------- ----------- ---------- -----------
1313
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1414
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1515
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
16+
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
1617
*****************************************************************************************************************************/
1718

1819
#pragma once
@@ -25,13 +26,13 @@
2526
#endif
2627

2728
#ifndef nRF52_MBED_PWM_VERSION
28-
#define nRF52_MBED_PWM_VERSION "nRF52_MBED_PWM v1.0.2"
29+
#define nRF52_MBED_PWM_VERSION "nRF52_MBED_PWM v1.0.3"
2930

3031
#define nRF52_MBED_PWM_VERSION_MAJOR 1
3132
#define nRF52_MBED_PWM_VERSION_MINOR 0
32-
#define nRF52_MBED_PWM_VERSION_PATCH 2
33+
#define nRF52_MBED_PWM_VERSION_PATCH 3
3334

34-
#define nRF52_MBED_PWM_VERSION_INT 1000002
35+
#define nRF52_MBED_PWM_VERSION_INT 1000003
3536
#endif
3637

3738

src/nRF52_MBED_PWM_Impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_PWM
77
Licensed under MIT license
88
9-
Version: 1.0.2
9+
Version: 1.0.3
1010
1111
Version Modified By Date Comments
1212
------- ----------- ---------- -----------
1313
1.0.0 K.Hoang 09/02/2022 Initial coding for Nano_33_BLE / Nano_33_BLE_Sense using ArduinoCore-mbed mbed_nano core
1414
1.0.1 K.Hoang 09/02/2022 Add functions to read PWM parameters
1515
1.0.2 K.Hoang 26/10/2022 Add support to SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE using mbed
16+
1.0.3 K Hoang 22/01/2023 Add `PWM_StepperControl` example
1617
*****************************************************************************************************************************/
1718

1819
#ifndef nRF52_MBED_PWM_IMPL_H

0 commit comments

Comments
 (0)