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

Commit

Permalink
v1.4.1 to add PWM_StepperControl example
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
khoih-prog authored Jan 22, 2023
1 parent 72d89da commit 6699d9a
Show file tree
Hide file tree
Showing 16 changed files with 608 additions and 551 deletions.
11 changes: 8 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,33 @@ 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/RP2040_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
* `RP2040` Core Version (e.g. Arduino-mbed RP2040 v3.4.1 or arduino-pico core v2.6.3)
* `RP2040` Core Version (e.g. Arduino-mbed RP2040 v3.5.4 or arduino-pico core v2.7.1)
* `RP2040` Board type (e.g. NANO_RP2040_CONNECT, RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
* 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

```
Arduino IDE version: 1.8.19
Arduino-mbed mbed_nano v3.4.1
Arduino-mbed mbed_nano v3.5.4
NANO_RP2040_CONNECT Module
OS: Ubuntu 21.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
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
* [ 5. PWM_Waveform](examples/PWM_Waveform)
* [ 6. PWM_Waveform_Fast](examples/PWM_Waveform_Fast)
* [ 7. PWM_DynamicDutyCycle_Int](examples/PWM_DynamicDutyCycle_Int)
* [ 8. PWM_Basic](examples/PWM_Basic). **New**
* [ 8. PWM_Basic](examples/PWM_Basic)
* [ 9. PWM_StepperControl](examples/PWM_StepperControl). **New**
* [Example PWM_Multi](#example-PWM_Multi)
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
* [1. PWM_Multi on MBED RaspberryPi Pico](#1-PWM_Multi-on-MBED-RaspberryPi-Pico)
Expand Down Expand Up @@ -137,8 +138,8 @@ Functions using normal software-based PWMs, relying on loop() and calling millis
## Prerequisites

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.
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)
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)
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)
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)


---
Expand Down Expand Up @@ -335,7 +336,8 @@ PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);
5. [PWM_Waveform](examples/PWM_Waveform)
6. [PWM_Waveform_Fast](examples/PWM_Waveform_Fast)
7. [PWM_DynamicDutyCycle_Int](examples/PWM_DynamicDutyCycle_Int)
7. [PWM_Basic](examples/PWM_Basic). **New**
8. [PWM_Basic](examples/PWM_Basic)
9. [PWM_StepperControl](examples/PWM_StepperControl). **New**


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

```cpp
Starting PWM_Multi on RaspberryPi Pico
RP2040_PWM v1.4.0
RP2040_PWM v1.4.1
=============================================================
Index Pin PWM_freq DutyCycle Actual Freq
=============================================================
Expand All @@ -382,7 +384,7 @@ The following is the sample terminal output when running example [**PWM_Multi**]

```cpp
Starting PWM_Multi on RASPBERRY_PI_PICO
RP2040_PWM v1.4.0
RP2040_PWM v1.4.1
=============================================================
Index Pin PWM_freq DutyCycle Actual Freq
=============================================================
Expand All @@ -406,7 +408,7 @@ The following is the sample terminal output when running example [**PWM_DynamicF

```cpp
Starting PWM_DynamicFreq on Nano RP2040 Connect
RP2040_PWM v1.4.0
RP2040_PWM v1.4.1
[PWM] _PWM_config.top = 12499 , _actualFrequency = 1000.00
[PWM] PWM enabled, frequency = 1000.00
=============================================================
Expand Down Expand Up @@ -451,7 +453,7 @@ The following is the sample terminal output when running example [**PWM_DynamicD

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

```cpp
Starting PWM_MultiChannel on RASPBERRY_PI_PICO
RP2040_PWM v1.4.0
RP2040_PWM v1.4.1
=============================================================
Index Pin PWM_freq DutyCycle Actual Freq
=============================================================
Expand All @@ -526,7 +528,7 @@ The following is the sample terminal output when running example [**PWM_Waveform

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

```cpp
Starting PWM_Waveform_Fast on RASPBERRY_PI_PICO
RP2040_PWM v1.4.0
RP2040_PWM v1.4.1
[PWM] _PWM_config.top = 12499 , _actualFrequency = 1000.00
[PWM] pin = 10 , PWM_CHAN = 0
[PWM] PWM enabled, slice = 5 , top = 1000 , div = 10 , level = 0
Expand Down Expand Up @@ -802,7 +804,7 @@ Submit issues to: [RP2040_PWM issues](https://github.com/khoih-prog/RP2040_PWM/i
14. Add `minimal` example [PWM_Basic](https://github.com/khoih-prog/RP2040_PWM/tree/main/examples/PWM_Basic)
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)
16. Adjust `MIN_PWM_FREQUENCY` and `MAX_PWM_FREQUENCY` dynamically according to actual `F_CPU`

17. Add example [PWM_StepperControl](examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM

---
---
Expand All @@ -822,6 +824,8 @@ Many thanks for everyone for bug reporting, new feature suggesting, testing and
4. Thanks to [Dr. Benjamin Bird](https://github.com/Chick92) to make PR
- [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
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
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


<table>
<tr>
Expand All @@ -830,6 +834,7 @@ Many thanks for everyone for bug reporting, new feature suggesting, testing and
<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>
<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>
<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>
<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>

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

## Changelog

### 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](https://github.com/khoih-prog/RP2040_PWM/issues/16)

### Releases v1.4.0

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)
Expand Down
2 changes: 1 addition & 1 deletion examples/PWM_Basic/PWM_Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ void loop()

delay(1000);
dutyCycle = 10;

PWM_Instance->setPWM(pinToUse, frequency, dutyCycle);
}
32 changes: 19 additions & 13 deletions examples/PWM_DynamicDutyCycle/PWM_DynamicDutyCycle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)

#if(_PWM_LOGLEVEL_>3)
#warning USING_MBED_RP2040_PWM
#endif
#if(_PWM_LOGLEVEL_>3)
#warning USING_MBED_RP2040_PWM
#endif

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

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

#include "RP2040_PWM.h"
Expand All @@ -52,10 +52,13 @@ char dashLine[] = "=============================================================
void setup()
{
Serial.begin(115200);

while (!Serial);

delay(100);

Serial.print(F("\nStarting PWM_DynamicDutyCycle on ")); Serial.println(BOARD_NAME);
Serial.print(F("\nStarting PWM_DynamicDutyCycle on "));
Serial.println(BOARD_NAME);
Serial.println(RP2040_PWM_VERSION);

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

Serial.print("Actual PWM Frequency = "); Serial.println(PWM_Instance->getActualFreq());
Serial.print("Actual PWM Frequency = ");
Serial.println(PWM_Instance->getActualFreq());

PWM_LOGDEBUG5("TOP =", top, ", DIV =", div, ", CPU_freq =", PWM_Instance->get_freq_CPU());
}
Expand All @@ -84,16 +88,18 @@ void loop()
delay(5000);
frequency = 2000.0f;
dutyCycle = 50.0f;

Serial.print(F("Change PWM DutyCycle to ")); Serial.println(dutyCycle);

Serial.print(F("Change PWM DutyCycle to "));
Serial.println(dutyCycle);
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle);

printPWMInfo(PWM_Instance);

delay(5000);
dutyCycle = 10.0f;

Serial.print(F("Change PWM DutyCycle to ")); Serial.println(dutyCycle);

Serial.print(F("Change PWM DutyCycle to "));
Serial.println(dutyCycle);
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle);
printPWMInfo(PWM_Instance);
}
34 changes: 20 additions & 14 deletions examples/PWM_DynamicDutyCycle_Int/PWM_DynamicDutyCycle_Int.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)

#if(_PWM_LOGLEVEL_>3)
#warning USING_MBED_RP2040_PWM
#endif
#if(_PWM_LOGLEVEL_>3)
#warning USING_MBED_RP2040_PWM
#endif

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

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

#include "RP2040_PWM.h"
Expand All @@ -52,14 +52,17 @@ char dashLine[] = "=============================================================
void setup()
{
Serial.begin(115200);

while (!Serial);

delay(100);

Serial.print(F("\nStarting PWM_DynamicDutyCycle_Int on ")); Serial.println(BOARD_NAME);
Serial.print(F("\nStarting PWM_DynamicDutyCycle_Int on "));
Serial.println(BOARD_NAME);
Serial.println(RP2040_PWM_VERSION);

frequency = 1000;

PWM_Instance = new RP2040_PWM(pinToUse, frequency, 50);

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

Serial.print("Actual PWM Frequency = "); Serial.println(PWM_Instance->getActualFreq());
Serial.print("Actual PWM Frequency = ");
Serial.println(PWM_Instance->getActualFreq());

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

// dutyCycle = real_dutyCycle * 1000
dutyCycle = 50000;

Serial.print(F("Change PWM DutyCycle to ")); Serial.println((float) dutyCycle / 1000);

Serial.print(F("Change PWM DutyCycle to "));
Serial.println((float) dutyCycle / 1000);
PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);

printPWMInfo(PWM_Instance);
Expand All @@ -98,8 +103,9 @@ void loop()

// dutyCycle = real_dutyCycle * 1000
dutyCycle = 20000;

Serial.print(F("Change PWM DutyCycle to ")); Serial.println((float) dutyCycle / 1000);

Serial.print(F("Change PWM DutyCycle to "));
Serial.println((float) dutyCycle / 1000);
PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);
printPWMInfo(PWM_Instance);
}
Loading

0 comments on commit 6699d9a

Please sign in to comment.