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

Commit 6699d9a

Browse files
authored
v1.4.1 to add PWM_StepperControl example
### Releases v1.4.1 1. Add example [PWM_StepperControl](https://github.com/khoih-prog/RP2040_PWM/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM. Check [Using PWM to step a stepper driver #16](#16)
1 parent 72d89da commit 6699d9a

File tree

16 files changed

+608
-551
lines changed

16 files changed

+608
-551
lines changed

CONTRIBUTING.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,33 @@ However, before reporting a bug please check through the following:
1010

1111
If you don't find anything, please [open a new issue](https://github.com/khoih-prog/RP2040_PWM/issues/new).
1212

13+
---
14+
1315
### How to submit a bug report
1416

1517
Please ensure to specify the following:
1618

1719
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `RP2040` Core Version (e.g. Arduino-mbed RP2040 v3.4.1 or arduino-pico core v2.6.3)
20+
* `RP2040` Core Version (e.g. Arduino-mbed RP2040 v3.5.4 or arduino-pico core v2.7.1)
1921
* `RP2040` Board type (e.g. NANO_RP2040_CONNECT, RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
2022
* Contextual information (e.g. what you were trying to achieve)
2123
* Simplest possible steps to reproduce
2224
* Anything that might be relevant in your opinion, such as:
2325
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
2426
* Network configuration
2527

28+
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.
29+
30+
---
2631

2732
### Example
2833

2934
```
3035
Arduino IDE version: 1.8.19
31-
Arduino-mbed mbed_nano v3.4.1
36+
Arduino-mbed mbed_nano v3.5.4
3237
NANO_RP2040_CONNECT Module
3338
OS: Ubuntu 21.04 LTS
34-
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
39+
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
3540
3641
Context:
3742
I encountered a crash while using this library

README.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
* [ 5. PWM_Waveform](examples/PWM_Waveform)
4545
* [ 6. PWM_Waveform_Fast](examples/PWM_Waveform_Fast)
4646
* [ 7. PWM_DynamicDutyCycle_Int](examples/PWM_DynamicDutyCycle_Int)
47-
* [ 8. PWM_Basic](examples/PWM_Basic). **New**
47+
* [ 8. PWM_Basic](examples/PWM_Basic)
48+
* [ 9. PWM_StepperControl](examples/PWM_StepperControl). **New**
4849
* [Example PWM_Multi](#example-PWM_Multi)
4950
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
5051
* [1. PWM_Multi on MBED RaspberryPi Pico](#1-PWM_Multi-on-MBED-RaspberryPi-Pico)
@@ -137,8 +138,8 @@ Functions using normal software-based PWMs, relying on loop() and calling millis
137138
## Prerequisites
138139

139140
1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software). Using `Arduino IDE 2.0.0+` at your own risk.
140-
2. [`ArduinoCore-mbed mbed_nano or mbed_rp2040 core 3.4.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino **NANO_RP2040_CONNECT, RASPBERRY_PI_PICO** boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
141-
3. [`Earle Philhower's arduino-pico core v2.6.3+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, ADAFRUIT_ITSYBITSY_RP2040, CYTRON_MAKER_NANO_RP2040, SPARKFUN_PROMICRO_RP2040, CHALLENGER_2040_WIFI_RP2040, ILABS_2040_RPICO32_RP2040, MELOPERO_SHAKE_RP2040, SOLDERPARTY_RP2040_STAMP, UPESY_RP2040_DEVKIT, WIZNET_5100S_EVB_PICO, GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)
141+
2. [`ArduinoCore-mbed mbed_nano or mbed_rp2040 core 3.5.4+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino **NANO_RP2040_CONNECT, RASPBERRY_PI_PICO** boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
142+
3. [`Earle Philhower's arduino-pico core v2.7.1+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, ADAFRUIT_ITSYBITSY_RP2040, CYTRON_MAKER_NANO_RP2040, SPARKFUN_PROMICRO_RP2040, CHALLENGER_2040_WIFI_RP2040, ILABS_2040_RPICO32_RP2040, MELOPERO_SHAKE_RP2040, SOLDERPARTY_RP2040_STAMP, UPESY_RP2040_DEVKIT, WIZNET_5100S_EVB_PICO, GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)
142143

143144

144145
---
@@ -335,7 +336,8 @@ PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);
335336
5. [PWM_Waveform](examples/PWM_Waveform)
336337
6. [PWM_Waveform_Fast](examples/PWM_Waveform_Fast)
337338
7. [PWM_DynamicDutyCycle_Int](examples/PWM_DynamicDutyCycle_Int)
338-
7. [PWM_Basic](examples/PWM_Basic). **New**
339+
8. [PWM_Basic](examples/PWM_Basic)
340+
9. [PWM_StepperControl](examples/PWM_StepperControl). **New**
339341

340342

341343
---
@@ -358,7 +360,7 @@ The following is the sample terminal output when running example [PWM_Multi](exa
358360

359361
```cpp
360362
Starting PWM_Multi on RaspberryPi Pico
361-
RP2040_PWM v1.4.0
363+
RP2040_PWM v1.4.1
362364
=============================================================
363365
Index Pin PWM_freq DutyCycle Actual Freq
364366
=============================================================
@@ -382,7 +384,7 @@ The following is the sample terminal output when running example [**PWM_Multi**]
382384

383385
```cpp
384386
Starting PWM_Multi on RASPBERRY_PI_PICO
385-
RP2040_PWM v1.4.0
387+
RP2040_PWM v1.4.1
386388
=============================================================
387389
Index Pin PWM_freq DutyCycle Actual Freq
388390
=============================================================
@@ -406,7 +408,7 @@ The following is the sample terminal output when running example [**PWM_DynamicF
406408

407409
```cpp
408410
Starting PWM_DynamicFreq on Nano RP2040 Connect
409-
RP2040_PWM v1.4.0
411+
RP2040_PWM v1.4.1
410412
[PWM] _PWM_config.top = 12499 , _actualFrequency = 1000.00
411413
[PWM] PWM enabled, frequency = 1000.00
412414
=============================================================
@@ -451,7 +453,7 @@ The following is the sample terminal output when running example [**PWM_DynamicD
451453

452454
```cpp
453455
Starting PWM_DynamicDutyCycle on RASPBERRY_PI_PICO
454-
RP2040_PWM v1.4.0
456+
RP2040_PWM v1.4.1
455457
[PWM] _PWM_config.top = 13299 , _actualFrequency = 1000.00
456458
[PWM] pin = 25 , PWM_CHAN = 1
457459
[PWM] PWM enabled, slice = 4 , _frequency = 1000.00
@@ -508,7 +510,7 @@ The following is the sample terminal output when running example [**PWM_MultiCha
508510

509511
```cpp
510512
Starting PWM_MultiChannel on RASPBERRY_PI_PICO
511-
RP2040_PWM v1.4.0
513+
RP2040_PWM v1.4.1
512514
=============================================================
513515
Index Pin PWM_freq DutyCycle Actual Freq
514516
=============================================================
@@ -526,7 +528,7 @@ The following is the sample terminal output when running example [**PWM_Waveform
526528

527529
```cpp
528530
Starting PWM_Waveform on RASPBERRY_PI_PICO
529-
RP2040_PWM v1.4.0
531+
RP2040_PWM v1.4.1
530532
[PWM] _PWM_config.top = 12499 , _actualFrequency = 1000.00
531533
[PWM] pin = 10 , PWM_CHAN = 0
532534
[PWM] PWM enabled, slice = 5 , top = 1000 , div = 10 , level = 0
@@ -640,7 +642,7 @@ The following is the sample terminal output when running example [**PWM_Waveform
640642

641643
```cpp
642644
Starting PWM_Waveform_Fast on RASPBERRY_PI_PICO
643-
RP2040_PWM v1.4.0
645+
RP2040_PWM v1.4.1
644646
[PWM] _PWM_config.top = 12499 , _actualFrequency = 1000.00
645647
[PWM] pin = 10 , PWM_CHAN = 0
646648
[PWM] PWM enabled, slice = 5 , top = 1000 , div = 10 , level = 0
@@ -802,7 +804,7 @@ Submit issues to: [RP2040_PWM issues](https://github.com/khoih-prog/RP2040_PWM/i
802804
14. Add `minimal` example [PWM_Basic](https://github.com/khoih-prog/RP2040_PWM/tree/main/examples/PWM_Basic)
803805
15. Fix glitch when dynamically changing dutycycle. Check [Changing Duty Cycle Dynamically Creates Runt PWM pulse #10](https://github.com/khoih-prog/RP2040_PWM/issues/10)
804806
16. Adjust `MIN_PWM_FREQUENCY` and `MAX_PWM_FREQUENCY` dynamically according to actual `F_CPU`
805-
807+
17. Add example [PWM_StepperControl](examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM
806808

807809
---
808810
---
@@ -822,6 +824,8 @@ Many thanks for everyone for bug reporting, new feature suggesting, testing and
822824
4. Thanks to [Dr. Benjamin Bird](https://github.com/Chick92) to make PR
823825
- [added minimal viable program to get the user up and running #9](https://github.com/khoih-prog/RP2040_PWM/pull/9) leading to v1.3.1
824826
5. Thanks to [Rocking Y Productions](https://github.com/RockingYProductions) to request enhancement in [Changing Duty Cycle Dynamically Creates Runt PWM pulse #10](https://github.com/khoih-prog/RP2040_PWM/issues/10), leading to v1.4.0
827+
6. 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 v1.4.1
828+
825829

826830
<table>
827831
<tr>
@@ -830,6 +834,7 @@ Many thanks for everyone for bug reporting, new feature suggesting, testing and
830834
<td align="center"><a href="https://github.com/Laserjones"><img src="https://github.com/Laserjones.png" width="100px;" alt="Laserjones"/><br /><sub><b>⭐️ Joerg Starkmuth</b></sub></a><br /></td>
831835
<td align="center"><a href="https://github.com/Chick92"><img src="https://github.com/Chick92.png" width="100px;" alt="Chick92"/><br /><sub><b>⭐️ Dr. Benjamin Bird</b></sub></a><br /></td>
832836
<td align="center"><a href="https://github.com/RockingYProductions"><img src="https://github.com/RockingYProductions.png" width="100px;" alt="RockingYProductions"/><br /><sub><b>Rocking Y Productions</b></sub></a><br /></td>
837+
<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>
833838
</tr>
834839
</table>
835840

changelog.md

+6
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.4.1](#Releases-v141)
2022
* [Releases v1.4.0](#Releases-v140)
2123
* [Releases v1.3.1](#Releases-v131)
2224
* [Releases v1.3.0](#Releases-v130)
@@ -35,6 +37,10 @@
3537

3638
## Changelog
3739

40+
### Releases v1.4.1
41+
42+
1. Add example [PWM_StepperControl](https://github.com/khoih-prog/RP2040_PWM/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)
43+
3844
### Releases v1.4.0
3945

4046
1. Fix glitch when dynamically changing dutycycle. Check [Changing Duty Cycle Dynamically Creates Runt PWM pulse #10](https://github.com/khoih-prog/RP2040_PWM/issues/10)

examples/PWM_Basic/PWM_Basic.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ void loop()
4040

4141
delay(1000);
4242
dutyCycle = 10;
43-
43+
4444
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle);
4545
}

examples/PWM_DynamicDutyCycle/PWM_DynamicDutyCycle.ino

+19-13
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
1717
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)
1818

19-
#if(_PWM_LOGLEVEL_>3)
20-
#warning USING_MBED_RP2040_PWM
21-
#endif
19+
#if(_PWM_LOGLEVEL_>3)
20+
#warning USING_MBED_RP2040_PWM
21+
#endif
2222

2323
#elif ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
2424
defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED)
2525

26-
#if(_PWM_LOGLEVEL_>3)
27-
#warning USING_RP2040_PWM
28-
#endif
26+
#if(_PWM_LOGLEVEL_>3)
27+
#warning USING_RP2040_PWM
28+
#endif
2929
#else
30-
#error This code is intended to run on the RP2040 mbed_nano, mbed_rp2040 or arduino-pico platform! Please check your Tools->Board setting.
30+
#error This code is intended to run on the RP2040 mbed_nano, mbed_rp2040 or arduino-pico platform! Please check your Tools->Board setting.
3131
#endif
3232

3333
#include "RP2040_PWM.h"
@@ -52,10 +52,13 @@ char dashLine[] = "=============================================================
5252
void setup()
5353
{
5454
Serial.begin(115200);
55+
5556
while (!Serial);
57+
5658
delay(100);
5759

58-
Serial.print(F("\nStarting PWM_DynamicDutyCycle on ")); Serial.println(BOARD_NAME);
60+
Serial.print(F("\nStarting PWM_DynamicDutyCycle on "));
61+
Serial.println(BOARD_NAME);
5962
Serial.println(RP2040_PWM_VERSION);
6063

6164
frequency = 1000;
@@ -74,7 +77,8 @@ void printPWMInfo(RP2040_PWM* PWM_Instance)
7477
uint32_t div = PWM_Instance->get_DIV();
7578
uint32_t top = PWM_Instance->get_TOP();
7679

77-
Serial.print("Actual PWM Frequency = "); Serial.println(PWM_Instance->getActualFreq());
80+
Serial.print("Actual PWM Frequency = ");
81+
Serial.println(PWM_Instance->getActualFreq());
7882

7983
PWM_LOGDEBUG5("TOP =", top, ", DIV =", div, ", CPU_freq =", PWM_Instance->get_freq_CPU());
8084
}
@@ -84,16 +88,18 @@ void loop()
8488
delay(5000);
8589
frequency = 2000.0f;
8690
dutyCycle = 50.0f;
87-
88-
Serial.print(F("Change PWM DutyCycle to ")); Serial.println(dutyCycle);
91+
92+
Serial.print(F("Change PWM DutyCycle to "));
93+
Serial.println(dutyCycle);
8994
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle);
9095

9196
printPWMInfo(PWM_Instance);
9297

9398
delay(5000);
9499
dutyCycle = 10.0f;
95-
96-
Serial.print(F("Change PWM DutyCycle to ")); Serial.println(dutyCycle);
100+
101+
Serial.print(F("Change PWM DutyCycle to "));
102+
Serial.println(dutyCycle);
97103
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle);
98104
printPWMInfo(PWM_Instance);
99105
}

examples/PWM_DynamicDutyCycle_Int/PWM_DynamicDutyCycle_Int.ino

+20-14
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
1717
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)
1818

19-
#if(_PWM_LOGLEVEL_>3)
20-
#warning USING_MBED_RP2040_PWM
21-
#endif
19+
#if(_PWM_LOGLEVEL_>3)
20+
#warning USING_MBED_RP2040_PWM
21+
#endif
2222

2323
#elif ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
2424
defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED)
2525

26-
#if(_PWM_LOGLEVEL_>3)
27-
#warning USING_RP2040_PWM
28-
#endif
26+
#if(_PWM_LOGLEVEL_>3)
27+
#warning USING_RP2040_PWM
28+
#endif
2929
#else
30-
#error This code is intended to run on the RP2040 mbed_nano, mbed_rp2040 or arduino-pico platform! Please check your Tools->Board setting.
30+
#error This code is intended to run on the RP2040 mbed_nano, mbed_rp2040 or arduino-pico platform! Please check your Tools->Board setting.
3131
#endif
3232

3333
#include "RP2040_PWM.h"
@@ -52,14 +52,17 @@ char dashLine[] = "=============================================================
5252
void setup()
5353
{
5454
Serial.begin(115200);
55+
5556
while (!Serial);
57+
5658
delay(100);
5759

58-
Serial.print(F("\nStarting PWM_DynamicDutyCycle_Int on ")); Serial.println(BOARD_NAME);
60+
Serial.print(F("\nStarting PWM_DynamicDutyCycle_Int on "));
61+
Serial.println(BOARD_NAME);
5962
Serial.println(RP2040_PWM_VERSION);
6063

6164
frequency = 1000;
62-
65+
6366
PWM_Instance = new RP2040_PWM(pinToUse, frequency, 50);
6467

6568
if (PWM_Instance)
@@ -75,7 +78,8 @@ void printPWMInfo(RP2040_PWM* PWM_Instance)
7578
uint32_t div = PWM_Instance->get_DIV();
7679
uint32_t top = PWM_Instance->get_TOP();
7780

78-
Serial.print("Actual PWM Frequency = "); Serial.println(PWM_Instance->getActualFreq());
81+
Serial.print("Actual PWM Frequency = ");
82+
Serial.println(PWM_Instance->getActualFreq());
7983

8084
PWM_LOGDEBUG5("TOP =", top, ", DIV =", div, ", CPU_freq =", PWM_Instance->get_freq_CPU());
8185
}
@@ -88,8 +92,9 @@ void loop()
8892

8993
// dutyCycle = real_dutyCycle * 1000
9094
dutyCycle = 50000;
91-
92-
Serial.print(F("Change PWM DutyCycle to ")); Serial.println((float) dutyCycle / 1000);
95+
96+
Serial.print(F("Change PWM DutyCycle to "));
97+
Serial.println((float) dutyCycle / 1000);
9398
PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);
9499

95100
printPWMInfo(PWM_Instance);
@@ -98,8 +103,9 @@ void loop()
98103

99104
// dutyCycle = real_dutyCycle * 1000
100105
dutyCycle = 20000;
101-
102-
Serial.print(F("Change PWM DutyCycle to ")); Serial.println((float) dutyCycle / 1000);
106+
107+
Serial.print(F("Change PWM DutyCycle to "));
108+
Serial.println((float) dutyCycle / 1000);
103109
PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);
104110
printPWMInfo(PWM_Instance);
105111
}

0 commit comments

Comments
 (0)