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

Commit 5a5c209

Browse files
authored
v1.1.0 for new PWM_manual example, etc.
### Releases v1.1.0 1. Add example [PWM_manual](https://github.com/khoih-prog/ESP32_FastPWM/tree/main/examples/PWM_manual) to demo how to correctly use PWM to generate waveform. Check [About DCValue in setPWM_manual #2](khoih-prog/AVR_PWM#2) 2. Add function `setPWM_DCPercentage_manual()` to facilitate the setting PWM DC manually by using `DCPercentage`, instead of `absolute DCValue` depending on varying resolution 3. Fix glitch when changing PWM frequency. Check [Frequency change on cycle end. #1](#1)
1 parent 60f34f9 commit 5a5c209

File tree

8 files changed

+346
-20
lines changed

8 files changed

+346
-20
lines changed

README.md

Lines changed: 149 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* [ 6. PWM_MultiChannel](examples/PWM_MultiChannel)
4646
* [ 7. PWM_Waveform](examples/PWM_Waveform)
4747
* [ 8. PWM_StepperControl](examples/PWM_StepperControl) **New**
48+
* [ 9. PWM_manual](examples/PWM_manual) **New**
4849
* [Example PWM_Multi](#example-PWM_Multi)
4950
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
5051
* [1. PWM_DynamicDutyCycle on ESP32_DEV](#1-PWM_DynamicDutyCycle-on-ESP32_DEV)
@@ -53,6 +54,7 @@
5354
* [4. PWM_Waveform on ESP32S2_DEV](#4-PWM_Waveform-on-ESP32S2_DEV)
5455
* [5. PWM_Waveform on ESP32C3_DEV](#5-PWM_Waveform-on-ESP32C3_DEV)
5556
* [6. PWM_Waveform on ESP32S3_DEV](#6-PWM_Waveform-on-ESP32S3_DEV)
57+
* [7. PWM_manual on ESP32_DEV](#7-PWM_manual-on-ESP32_DEV)
5658
* [Debug](#debug)
5759
* [Troubleshooting](#troubleshooting)
5860
* [Issues](#issues)
@@ -105,7 +107,7 @@ The most important feature is they're purely hardware-based PWM channels. Theref
105107

106108
This important feature is absolutely necessary for mission-critical tasks. These hardware PWM-channels, still work even if other software functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to control external systems (Servo, etc.) requiring better accuracy.
107109

108-
New efficient `setPWM_manual()` function enables waveform creation using PWM.
110+
New efficient `setPWM_manual()` and `setPWM_DCPercentage_manual()` functions enable waveform creation using PWM.
109111

110112
The [**PWM_Multi**](examples/PWM_Multi) example will demonstrate the usage of multichannel PWM using multiple Hardware-PWM blocks (slices). The 4 independent Hardware-PWM channels are used **to control 4 different PWM outputs**, with totally independent frequencies and dutycycles on `ESP32`.
111113

@@ -323,6 +325,7 @@ Function prototype
323325
324326
```cpp
325327
bool setPWM_manual(const uint8_t& pin, const uint16_t& DCValue);
328+
bool setPWM_DCPercentage_manual(const uint8_t& pin, const float& DCPercentage);
326329
```
327330

328331
Need to call only once for each pin
@@ -335,9 +338,17 @@ PWM_Instance->setPWM(PWM_Pins, frequency, dutyCycle);
335338
after that, if just changing `dutyCycle` / `level`, use
336339
337340
```cpp
341+
// For 50.0f dutycycle
342+
new_level = 50.0f * ( 1 << PWM_Instance->getResolution() ) / 100.0f ;
338343
PWM_Instance->setPWM_manual(PWM_Pins, new_level);
339344
```
340345

346+
or better and much easier to use
347+
348+
```cpp
349+
new_DCPercentage = 50.0f;
350+
PWM_Instance->setPWM_DCPercentage_manual(PWM_Pins, new_DCPercentage);
351+
```
341352
342353
---
343354
---
@@ -352,6 +363,7 @@ PWM_Instance->setPWM_manual(PWM_Pins, new_level);
352363
6. [PWM_MultiChannel](examples/PWM_MultiChannel)
353364
7. [PWM_Waveform](examples/PWM_Waveform)
354365
8. [PWM_StepperControl](examples/PWM_StepperControl) **New**
366+
9. [PWM_manual](examples/PWM_manual) **New**
355367
356368
357369
---
@@ -374,7 +386,7 @@ The following is the sample terminal output when running example [PWM_DynamicDut
374386
375387
```cpp
376388
Starting PWM_DynamicDutyCycle on ESP32_DEV
377-
ESP32_FastPWM v1.0.1
389+
ESP32_FastPWM v1.1.0
378390
[PWM] ESP32_FastPWM: SOC_LEDC_CHANNEL_NUM = 8 , LEDC_CHANNELS = 16 , LEDC_MAX_BIT_WIDTH = 20
379391
[PWM] ESP32_FastPWM: _dutycycle = 32768
380392
[PWM] setPWM_Int: _dutycycle = 128 , DC % = 50.00
@@ -407,7 +419,7 @@ The following is the sample terminal output when running example [**PWM_Multi**]
407419

408420
```cpp
409421
Starting PWM_Multi on ESP32_DEV
410-
ESP32_FastPWM v1.0.1
422+
ESP32_FastPWM v1.1.0
411423
[PWM] ESP32_FastPWM: new _channel = 0
412424
[PWM] ESP32_FastPWM: SOC_LEDC_CHANNEL_NUM = 8 , LEDC_CHANNELS = 16 , LEDC_MAX_BIT_WIDTH = 20
413425
[PWM] ESP32_FastPWM: _dutycycle = 6553
@@ -453,7 +465,7 @@ The following is the sample terminal output when running example [**PWM_DynamicF
453465
454466
```cpp
455467
Starting PWM_DynamicFreq on ESP32S3_DEV
456-
ESP32_FastPWM v1.0.1
468+
ESP32_FastPWM v1.1.0
457469
[PWM] ESP32_FastPWM: SOC_LEDC_CHANNEL_NUM = 8 , LEDC_CHANNELS = 8 , LEDC_MAX_BIT_WIDTH = 14
458470
[PWM] ESP32_FastPWM: _dutycycle = 32768
459471
[PWM] setPWM_Int: _dutycycle = 128 , DC % = 50.00
@@ -498,7 +510,7 @@ The following is the sample terminal output when running example [**PWM_Waveform
498510

499511
```cpp
500512
Starting PWM_Waveform on ESP32S2_DEV
501-
ESP32_FastPWM v1.0.1
513+
ESP32_FastPWM v1.1.0
502514
[PWM] ESP32_FastPWM: new _channel = 0
503515
[PWM] ESP32_FastPWM: SOC_LEDC_CHANNEL_NUM = 8 , LEDC_CHANNELS = 8 , LEDC_MAX_BIT_WIDTH = 14
504516
[PWM] ESP32_FastPWM: _dutycycle = 0
@@ -559,7 +571,7 @@ The following is the sample terminal output when running example [**PWM_Waveform
559571
560572
```cpp
561573
Starting PWM_Waveform on ESP32C3_DEV
562-
ESP32_FastPWM v1.0.1
574+
ESP32_FastPWM v1.1.0
563575
[PWM] ESP32_FastPWM: new _channel = 0
564576
[PWM] ESP32_FastPWM: SOC_LEDC_CHANNEL_NUM = 6 , LEDC_CHANNELS = 6 , LEDC_MAX_BIT_WIDTH = 14
565577
[PWM] ESP32_FastPWM: _dutycycle = 0
@@ -620,7 +632,7 @@ The following is the sample terminal output when running example [**PWM_Waveform
620632

621633
```cpp
622634
Starting PWM_Waveform on ESP32S3_DEV
623-
ESP32_FastPWM v1.0.1
635+
ESP32_FastPWM v1.1.0
624636
[PWM] ESP32_FastPWM: new _channel = 0
625637
[PWM] ESP32_FastPWM: SOC_LEDC_CHANNEL_NUM = 8 , LEDC_CHANNELS = 8 , LEDC_MAX_BIT_WIDTH = 14
626638
[PWM] ESP32_FastPWM: _dutycycle = 0
@@ -672,6 +684,131 @@ Actual data: pin = 16, PWM DutyCycle = 0.00, PWMPeriod = 1000.00, PWM Freq (Hz)
672684
[PWM] setPWM_manual: DCValue = 0 , _frequency = 1000.00
673685
```
674686
687+
688+
---
689+
690+
### 7. PWM_Waveform on ESP32_DEV
691+
692+
The following is the sample terminal output when running example [**PWM_manual**](examples/PWM_manual) on **ESP32_DEV**, to demonstrate how to use the `setPWM_manual()` and `setPWM_DCPercentage_manual()` functions in wafeform creation
693+
694+
695+
```cpp
696+
Starting PWM_manual on ESP32_DEV
697+
ESP32_FastPWM v1.1.0
698+
[PWM] ESP32_FastPWM: new _channel = 0
699+
[PWM] ESP32_FastPWM: SOC_LEDC_CHANNEL_NUM = 8 , LEDC_CHANNELS = 16 , LEDC_MAX_BIT_WIDTH = 20
700+
[PWM] ESP32_FastPWM: _dutycycle = 0
701+
[PWM] setPWM_Int: _dutycycle = 0 , DC % = 0.00
702+
=================================================================================================
703+
Actual data: pin = 16, PWM DC = 0.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
704+
=================================================================================================
705+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 0.00 , new_dc = 0
706+
[PWM] setPWM_manual: DCValue = 0 , _frequency = 1000.00
707+
=================================================================================================
708+
Actual data: pin = 16, PWM DC = 0.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
709+
=================================================================================================
710+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 5.00 , new_dc = 3276
711+
[PWM] setPWM_manual: DCValue = 3276 , _frequency = 1000.00
712+
=================================================================================================
713+
Actual data: pin = 16, PWM DC = 5.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
714+
=================================================================================================
715+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 10.00 , new_dc = 6553
716+
[PWM] setPWM_manual: DCValue = 6553 , _frequency = 1000.00
717+
=================================================================================================
718+
Actual data: pin = 16, PWM DC = 10.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
719+
=================================================================================================
720+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 15.00 , new_dc = 9830
721+
[PWM] setPWM_manual: DCValue = 9830 , _frequency = 1000.00
722+
=================================================================================================
723+
Actual data: pin = 16, PWM DC = 15.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
724+
=================================================================================================
725+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 20.00 , new_dc = 13107
726+
[PWM] setPWM_manual: DCValue = 13107 , _frequency = 1000.00
727+
=================================================================================================
728+
Actual data: pin = 16, PWM DC = 20.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
729+
=================================================================================================
730+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 25.00 , new_dc = 16384
731+
[PWM] setPWM_manual: DCValue = 16384 , _frequency = 1000.00
732+
=================================================================================================
733+
Actual data: pin = 16, PWM DC = 25.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
734+
=================================================================================================
735+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 30.00 , new_dc = 19660
736+
[PWM] setPWM_manual: DCValue = 19660 , _frequency = 1000.00
737+
=================================================================================================
738+
Actual data: pin = 16, PWM DC = 30.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
739+
=================================================================================================
740+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 35.00 , new_dc = 22937
741+
[PWM] setPWM_manual: DCValue = 22937 , _frequency = 1000.00
742+
=================================================================================================
743+
Actual data: pin = 16, PWM DC = 35.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
744+
=================================================================================================
745+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 40.00 , new_dc = 26214
746+
[PWM] setPWM_manual: DCValue = 26214 , _frequency = 1000.00
747+
=================================================================================================
748+
Actual data: pin = 16, PWM DC = 40.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
749+
=================================================================================================
750+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 45.00 , new_dc = 29491
751+
[PWM] setPWM_manual: DCValue = 29491 , _frequency = 1000.00
752+
=================================================================================================
753+
Actual data: pin = 16, PWM DC = 45.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
754+
=================================================================================================
755+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 50.00 , new_dc = 32768
756+
[PWM] setPWM_manual: DCValue = 32768 , _frequency = 1000.00
757+
=================================================================================================
758+
Actual data: pin = 16, PWM DC = 50.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
759+
=================================================================================================
760+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 55.00 , new_dc = 36044
761+
[PWM] setPWM_manual: DCValue = 36044 , _frequency = 1000.00
762+
=================================================================================================
763+
Actual data: pin = 16, PWM DC = 55.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
764+
=================================================================================================
765+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 60.00 , new_dc = 39321
766+
[PWM] setPWM_manual: DCValue = 39321 , _frequency = 1000.00
767+
=================================================================================================
768+
Actual data: pin = 16, PWM DC = 60.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
769+
=================================================================================================
770+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 65.00 , new_dc = 42598
771+
[PWM] setPWM_manual: DCValue = 42598 , _frequency = 1000.00
772+
=================================================================================================
773+
Actual data: pin = 16, PWM DC = 65.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
774+
=================================================================================================
775+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 70.00 , new_dc = 45875
776+
[PWM] setPWM_manual: DCValue = 45875 , _frequency = 1000.00
777+
=================================================================================================
778+
Actual data: pin = 16, PWM DC = 70.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
779+
=================================================================================================
780+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 75.00 , new_dc = 49152
781+
[PWM] setPWM_manual: DCValue = 49152 , _frequency = 1000.00
782+
=================================================================================================
783+
Actual data: pin = 16, PWM DC = 75.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
784+
=================================================================================================
785+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 80.00 , new_dc = 52428
786+
[PWM] setPWM_manual: DCValue = 52428 , _frequency = 1000.00
787+
=================================================================================================
788+
Actual data: pin = 16, PWM DC = 80.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
789+
=================================================================================================
790+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 85.00 , new_dc = 55705
791+
[PWM] setPWM_manual: DCValue = 55705 , _frequency = 1000.00
792+
=================================================================================================
793+
Actual data: pin = 16, PWM DC = 85.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
794+
=================================================================================================
795+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 90.00 , new_dc = 58982
796+
[PWM] setPWM_manual: DCValue = 58982 , _frequency = 1000.00
797+
=================================================================================================
798+
Actual data: pin = 16, PWM DC = 90.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
799+
=================================================================================================
800+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 95.00 , new_dc = 62259
801+
[PWM] setPWM_manual: DCValue = 62259 , _frequency = 1000.00
802+
=================================================================================================
803+
Actual data: pin = 16, PWM DC = 95.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
804+
=================================================================================================
805+
[PWM] setPWM_DCPercentage_manual: DCPercentage = 100.00 , new_dc = 0
806+
[PWM] setPWM_manual: DCValue = 0 , _frequency = 1000.00
807+
=================================================================================================
808+
Actual data: pin = 16, PWM DC = 0.00, PWMPeriod = 1000.00, PWM Freq (Hz) = 1000.0000
809+
=================================================================================================
810+
```
811+
675812
---
676813
---
677814

@@ -715,8 +852,11 @@ Submit issues to: [ESP32_FastPWM issues](https://github.com/khoih-prog/ESP32_Fas
715852
## DONE
716853

717854
1. Basic hardware PWM-channels for `ESP32, ESP32_S2, ESP32_S3 and ESP32_C3` using [ESP32 core](https://github.com/espressif/arduino-esp32)
718-
2. Add example [PWM_StepperControl](https://github.com/khoih-prog/ESP32_FastPWM/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM
719-
855+
2. Add example [PWM_StepperControl](https://github.com/khoih-prog/ESP32_FastPWM/tree/main/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM
856+
3. Add example [PWM_manual](https://github.com/khoih-prog/ESP32_FastPWM/tree/main/examples/PWM_manual) to demo how to correctly use PWM to generate waveform
857+
4. Add function `setPWM_DCPercentage_manual()` to facilitate the setting PWM DC manually by using DCPercentage, instead of absolute DCValue depending on varying PWMPeriod
858+
859+
720860
---
721861
---
722862

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@
1717
## Table of Contents
1818

1919
* [Changelog](#changelog)
20-
* [Releases v1.0.1](#releases-v101)
20+
* [Releases v1.1.0](#Releases-v110)
21+
* [Releases v1.0.1](#Releases-v101)
2122
* [Releases v1.0.0](#releases-v100)
2223

2324
---
2425
---
2526

2627
## Changelog
2728

29+
### Releases v1.1.0
30+
31+
1. Add example [PWM_manual](https://github.com/khoih-prog/ESP32_FastPWM/tree/main/examples/PWM_manual) to demo how to correctly use PWM to generate waveform. Check [About DCValue in setPWM_manual #2](https://github.com/khoih-prog/AVR_PWM/discussions/2)
32+
2. Add function `setPWM_DCPercentage_manual()` to facilitate the setting PWM DC manually by using `DCPercentage`, instead of `absolute DCValue` depending on varying resolution
33+
3. Fix glitch when changing PWM frequency. Check [Frequency change on cycle end. #1](https://github.com/khoih-prog/ESP32_FastPWM/discussions/1)
34+
2835
### Releases v1.0.1
2936

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

0 commit comments

Comments
 (0)