Skip to content

Commit 8188a62

Browse files
committed
Update
* Fixes issue with integrating previous servo easing update,. * Renames printConfig() function to printDebug() * Updates examples and readme.
1 parent 0d189be commit 8188a62

File tree

11 files changed

+58
-91
lines changed

11 files changed

+58
-91
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ attach(pin, ch, minUs, defUs, maxUs, speed, ke, invert) // as above with invert
325325
326326
[Servo_Sweep_Inverted](https://wokwi.com/projects/351967394028061269)
327327
328-
![image](https://user-images.githubusercontent.com/63488701/209453287-4c1b0ba8-8e0e-42cd-9bef-55a7b2f1e8b4.png)
328+
![image](https://user-images.githubusercontent.com/63488701/229374262-460e878e-81f1-4398-8ea5-60b02026a4cf.png)
329329
330330
##### Returns
331331
@@ -498,7 +498,7 @@ pwm.setResolution(pin, resolution)
498498

499499

500500

501-
### printConfig()
501+
### printDebug()
502502

503503
##### Description
504504

@@ -507,7 +507,7 @@ This function prints the available PWM pins to choose from and a formatted outpu
507507
**Syntax**
508508

509509
```c++
510-
pwm.printConfig()
510+
pwm.printDebug()
511511
```
512512

513513
##### Parameters (optional)
@@ -518,9 +518,7 @@ pwm.printConfig()
518518

519519
- serial report on serial monitor
520520

521-
![image](https://user-images.githubusercontent.com/63488701/207452928-ca44457d-f807-439b-971e-927af4259e16.png)
522-
523-
521+
![![image](https://user-images.githubusercontent.com/63488701/229374511-de75b97d-f91f-44d0-b103-0ca858d16727.png)
524522

525523
```
526524
This Library is licensed under the MIT License

examples/ESP32_3phase_10kHz/ESP32_3phase_10kHz.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ void setup() {
2222
pwm.write(pwmPin[i], (duty - deadtime), frequency, resolution, (phase[i] + shift[i]));
2323
}
2424
pwm.resume();
25-
pwm.printConfig();
25+
pwm.printDebug();
2626
}
2727

2828
void loop() {
29-
}
29+
}

examples/ESP32_3phase_40kHz/ESP32_3phase_40kHz.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void setup() {
2121
pwm.write(pwmPin[i], (duty - deadtime), frequency, resolution, (phase[i] + shift[i]));
2222
}
2323
pwm.resume();
24-
pwm.printConfig();
24+
pwm.printDebug();
2525
}
2626

2727
void loop() {

examples/ESP32_C3_3phase_10kHz/ESP32_C3_3phase_10kHz.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ void setup() {
2222
pwm.write(pwmPin[i], (duty - deadtime), frequency, resolution, (phase[i] + shift[i]));
2323
}
2424
pwm.resume();
25-
pwm.printConfig();
25+
pwm.printDebug();
2626
}
2727

2828
void loop() {
29-
}
29+
}

examples/ESP32_S2_3phase_10kHz/ESP32_S2_3phase_10kHz.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ void setup() {
2222
pwm.write(pwmPin[i], (duty - deadtime), frequency, resolution, (phase[i] + shift[i]));
2323
}
2424
pwm.resume();
25-
pwm.printConfig();
25+
pwm.printDebug();
2626
}
2727

2828
void loop() {
29-
}
29+
}

examples/ESP32_Sync2_300kHz/ESP32_Sync2_300kHz.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void setup() {
1414
pwm.write(pwm21, 64, 300000);
1515
pwm.write(pwm19, 128, 300000);
1616
pwm.resume();
17-
pwm.printConfig();
17+
pwm.printDebug();
1818
}
1919

2020
void loop() {

examples/ESP32_Sync8_20kHz/ESP32_Sync8_20kHz.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void setup() {
1919
pwm.write(pwmPin[i], duty[i], frequency, resolution, phase[i]);
2020
}
2121
pwm.resume();
22-
pwm.printConfig();
22+
pwm.printDebug();
2323
}
2424

2525
void loop() {

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"keywords": "pwm, servo, tone, esp32, analogWrite, esp32-s2, esp32-s3, esp32-c3, ledc",
44
"description": "ESP32 PWM, Servo, Easing and Tone. Smart GPIO pin management and advanced control features.",
55
"license": "MIT",
6-
"version": "4.3.2",
6+
"version": "4.3.3",
77
"frameworks": "arduino",
88
"platforms": "espressif32",
99
"repository": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ESP32 ESP32S2 AnalogWrite
2-
version=4.3.2
2+
version=4.3.3
33
author=David Lloyd
44
maintainer=David Lloyd <[email protected]>
55
sentence=ESP32 PWM, Servo, Easing and Tone.

src/pwmWrite.cpp

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************
2-
ESP32 PWM, SERVO and TONE Library, Version 4.3.2
2+
ESP32 PWM, SERVO and TONE Library, Version 4.3.3
33
by dlloydev https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite
44
This Library is licensed under the MIT License
55
*******************************************************************/
@@ -47,36 +47,28 @@ float Pwm::write(uint8_t pin, uint32_t duty, uint32_t frequency, uint8_t resolut
4747

4848
float Pwm::writeServo(uint8_t pin, float value, float speed, float ke) {
4949
uint8_t ch = attached(pin);
50-
bool ms = millis() >> 3 & 1;
51-
if (ms && !mem[ch].pms) {
52-
wr_servo(pin, value, speed, ke);
53-
}
54-
mem[ch].pms = ms;
50+
wr_servo(pin, value, speed, ke);
5551
return (ke < 1.0) ? mem[ch].ye : value; // normalized easing duty (0.0 - 1.0)
5652
}
5753

5854
float Pwm::writeServo(uint8_t pin, float value) {
5955
uint8_t ch = attached(pin);
60-
bool ms = millis() >> 3 & 1;
61-
if (ms && !mem[ch].pms) {
62-
if (ch == 253) { // free channels exist
63-
for (uint8_t c = 0; c < chMax; c++) {
64-
if (mem[c].pin == 255 && ch == 253) { //first free ch
65-
mem[c].pin = pin;
66-
ch = c;
67-
if (mem[ch].frequency < 40 || mem[ch].frequency > 900) mem[ch].frequency = 50;
68-
if (mem[ch].resolution > widthMax) mem[ch].resolution = widthMax;
69-
else if (mem[ch].resolution < 14 && widthMax == 20) mem[ch].resolution = 16;
70-
else if (mem[ch].resolution < 14) mem[ch].resolution = 14;
71-
ledcSetup(ch, mem[ch].frequency, mem[ch].resolution);
72-
if (sync) pause(ch);
73-
ledcAttachPin(pin, ch);
74-
}
56+
if (ch == 253) { // free channels exist
57+
for (uint8_t c = 0; c < chMax; c++) {
58+
if (mem[c].pin == 255 && ch == 253) { //first free ch
59+
mem[c].pin = pin;
60+
ch = c;
61+
if (mem[ch].frequency < 40 || mem[ch].frequency > 900) mem[ch].frequency = 50;
62+
if (mem[ch].resolution > widthMax) mem[ch].resolution = widthMax;
63+
else if (mem[ch].resolution < 14 && widthMax == 20) mem[ch].resolution = 16;
64+
else if (mem[ch].resolution < 14) mem[ch].resolution = 14;
65+
ledcSetup(ch, mem[ch].frequency, mem[ch].resolution);
66+
if (sync) pause(ch);
67+
ledcAttachPin(pin, ch);
7568
}
7669
}
77-
wr_servo(pin, value, mem[ch].speed, mem[ch].ke);
7870
}
79-
mem[ch].pms = ms;
71+
wr_servo(pin, value, mem[ch].speed, mem[ch].ke);
8072
return (mem[ch].ke < 1.0) ? mem[ch].ye : value; // normalized easing duty (0.0 - 1.0)
8173
}
8274

@@ -248,43 +240,19 @@ uint8_t Pwm::setResolution(uint8_t pin, uint8_t resolution) {
248240
return mem[ch].resolution;
249241
}
250242

251-
void Pwm::printConfig() {
252-
Serial.print(F("PWM pins: "));
243+
void Pwm::printDebug() {
244+
Serial.printf("PWM pins:\n");
253245
for (uint8_t i = 0; i < 48; i++) {
254246
if ((pinMask >> i) & 1) {
255-
Serial.print(i); Serial.print(F(", "));
247+
Serial.printf("%d,", i);
256248
}
257249
}
258-
Serial.println();
259-
Serial.println();
260-
Serial.println(F("Ch Pin Hz Res Duty Phase Servo"));
250+
Serial.printf("\n\nCh Pin Hz Res Duty Servo Speed ke\n");
261251
for (uint8_t ch = 0; ch < chMax; ch++) {
262-
if (ch < 10) Serial.print(F(" "));
263-
Serial.print(ch);
264-
Serial.print(F(" "));
265-
if (mem[ch].pin < 100) Serial.print(F(" "));
266-
if (mem[ch].pin < 10) Serial.print(F(" "));
267-
Serial.print(mem[ch].pin); Serial.print(F(" "));
268-
if (mem[ch].frequency < 10000) Serial.print(F(" "));
269-
if (mem[ch].frequency < 1000) Serial.print(F(" "));
270-
if (mem[ch].frequency < 100) Serial.print(F(" "));
271-
if (mem[ch].frequency < 10) Serial.print(F(" "));
272-
Serial.print(mem[ch].frequency, 1); Serial.print(F(" "));
273-
if (mem[ch].resolution < 10) Serial.print(F(" "));
274-
Serial.print(mem[ch].resolution); Serial.print(F(" "));
275-
if (mem[ch].duty < 1000) Serial.print(F(" "));
276-
if (mem[ch].duty < 100) Serial.print(F(" "));
277-
if (mem[ch].duty < 10) Serial.print(F(" "));
278-
Serial.print(mem[ch].duty); Serial.print(F(" "));
279-
if (mem[ch].phase < 1000) Serial.print(F(" "));
280-
if (mem[ch].phase < 100) Serial.print(F(" "));
281-
if (mem[ch].phase < 10) Serial.print(F(" "));
282-
Serial.print(mem[ch].phase); Serial.print(F(" "));
283-
Serial.print(mem[ch].servoMinUs); Serial.print(F(" "));
284-
Serial.print(mem[ch].servoDefUs); Serial.print(F(" "));
285-
Serial.print(mem[ch].servoMaxUs);
286-
Serial.println();
252+
Serial.printf ("%2d %3d %5.0f %2d %4d %d-%d-%d %5.1f %1.1f\n", ch, mem[ch].pin, mem[ch].frequency, mem[ch].resolution,
253+
mem[ch].duty, mem[ch].servoMinUs, mem[ch].servoDefUs, mem[ch].servoMaxUs, mem[ch].speed, mem[ch].ke);
287254
}
255+
Serial.printf("\n");
288256
}
289257

290258
/************************* private functions ***************************/
@@ -441,4 +409,6 @@ void Pwm::reset_fields(uint8_t ch) {
441409
mem[ch].servoMinUs = 544;
442410
mem[ch].servoDefUs = 1472;
443411
mem[ch].servoMaxUs = 2400;
412+
mem[ch].speed = 0;
413+
mem[ch].ke = 1.0;
444414
}

0 commit comments

Comments
 (0)