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

Commit 2c23550

Browse files
authored
v1.2.1 to fix bug and optimize
### Releases v1.2.1 1. Fix bug. 2. Optimize library code by using `reference-passing` instead of `value-passing`
1 parent cfd3e0b commit 2c23550

12 files changed

+126
-83
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar
695695

696696
```
697697
Starting ISR_16_PWMs_Array_Complex on ESP8266_NODEMCU_ESP12E
698-
ESP8266_PWM v1.2.0
698+
ESP8266_PWM v1.2.1
699699
CPU Frequency = 160 MHz
700700
[PWM] ESP8266TimerInterrupt: Timer Clock fre = 80000000
701701
[PWM] Timer fre = 50000.00 , _count = 1600
@@ -736,7 +736,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar
736736

737737
```
738738
Starting ISR_16_PWMs_Array on ESP8266_NODEMCU_ESP12E
739-
ESP8266_PWM v1.2.0
739+
ESP8266_PWM v1.2.1
740740
CPU Frequency = 160 MHz
741741
[PWM] ESP8266TimerInterrupt: Timer Clock fre = 80000000
742742
[PWM] Timer fre = 50000.00 , _count = 1600
@@ -760,7 +760,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar
760760

761761
```
762762
Starting ISR_16_PWMs_Array_Simple on ESP8266_NODEMCU_ESP12E
763-
ESP8266_PWM v1.2.0
763+
ESP8266_PWM v1.2.1
764764
CPU Frequency = 160 MHz
765765
[PWM] ESP8266TimerInterrupt: Timer Clock fre = 80000000
766766
[PWM] Timer fre = 50000.00 , _count = 1600
@@ -783,7 +783,7 @@ The following is the sample terminal output when running example [ISR_Modify_PWM
783783

784784
```
785785
Starting ISR_Modify_PWM on ESP8266_NODEMCU_ESP12E
786-
ESP8266_PWM v1.2.0
786+
ESP8266_PWM v1.2.1
787787
CPU Frequency = 160 MHz
788788
[PWM] ESP8266TimerInterrupt: Timer Clock fre = 80000000
789789
[PWM] Timer fre = 50000.00 , _count = 1600
@@ -805,7 +805,7 @@ The following is the sample terminal output when running example [ISR_Changing_P
805805

806806
```
807807
Starting ISR_Changing_PWM on ESP8266_NODEMCU_ESP12E
808-
ESP8266_PWM v1.2.0
808+
ESP8266_PWM v1.2.1
809809
CPU Frequency = 160 MHz
810810
[PWM] ESP8266TimerInterrupt: Timer Clock fre = 80000000
811811
[PWM] Timer fre = 50000.00 , _count = 1600
@@ -867,6 +867,9 @@ Submit issues to: [ESP8266_PWM issues](https://github.com/khoih-prog/ESP8266_PWM
867867
2. Longer time interval
868868
3. Add complex examples.
869869
4. Add functions to modify PWM settings on-the-fly
870+
5. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`
871+
6. Optimize library code by using `reference-passing` instead of `value-passing`
872+
870873

871874
---
872875
---

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.2.1](#releases-v121)
1516
* [Releases v1.2.0](#releases-v120)
1617
* [Releases v1.1.0](#releases-v110)
1718
* [Releases v1.0.0](#releases-v100)
@@ -21,6 +22,11 @@
2122

2223
## Changelog
2324

25+
### Releases v1.2.1
26+
27+
1. Fix bug.
28+
2. Optimize library code by using `reference-passing` instead of `value-passing`
29+
2430
### Releases v1.2.0
2531

2632
1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories

examples/multiFileProject/multiFileProject.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,12 @@
1212

1313
#pragma once
1414

15+
#define USING_MICROS_RESOLUTION true //false
16+
17+
// Select a Timer Clock
18+
#define USING_TIM_DIV1 true // for shortest and most accurate timer
19+
#define USING_TIM_DIV16 false // for medium time and medium accurate timer
20+
#define USING_TIM_DIV256 false // for longest timer but least accurate. Default
21+
1522
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
1623
#include "ESP8266_PWM.hpp"

examples/multiFileProject/multiFileProject.ino

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@
1414
#error This code is designed to run on ESP8266 and ESP8266-based boards! Please check your Tools->Board setting.
1515
#endif
1616

17-
#define ESP8266_PWM_VERSION_MIN_TARGET "ESP8266_PWM v1.2.0"
18-
#define ESP8266_PWM_VERSION_MIN 1002000
19-
20-
// Select a Timer Clock
21-
#define USING_TIM_DIV1 false // for shortest and most accurate timer
22-
#define USING_TIM_DIV16 false // for medium time and medium accurate timer
23-
#define USING_TIM_DIV256 true // for longest timer but least accurate. Default
17+
#define ESP8266_PWM_VERSION_MIN_TARGET "ESP8266_PWM v1.2.1"
18+
#define ESP8266_PWM_VERSION_MIN 1002001
2419

2520
#include "multiFileProject.h"
2621

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ESP8266_PWM",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"keywords": "timing, device, control, pwm, timer, interrupt, hardware, isr, isr-based, hardware-timer, isr-timer, isr-based-timer, mission-critical, accuracy, precise, non-blocking, ESP8266, synchronized-PWM, on-the-fly",
55
"description": "This library enables you to use Interrupt from Hardware Timers on an ESP8266-based board to create and output PWM to pins. It now supports 16 ISR-based synchronized PWM channels, while consuming only 1 Hardware Timer. PWM interval can be very long (uint32_t millisecs). The most important feature is they're ISR-based PWM channels. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware PWM channels, using interrupt, still work even if other 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 measure some data requiring better accuracy. Now you can change the PWM settings 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=ESP8266_PWM
2-
version=1.2.0
2+
version=1.2.1
33
author=Khoi Hoang <[email protected]>
44
maintainer=Khoi Hoang <[email protected]>
55
sentence=TThis library enables you to use Interrupt from Hardware Timers on an ESP8266-based board to create and output PWM to pins.

src/ESP8266_PWM.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1818
This important feature is absolutely necessary for mission-critical tasks.
1919
20-
Version: 1.1.0
20+
Version: 1.2.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
2525
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
26+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
27+
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
2628
*****************************************************************************************************************************/
2729

2830
#pragma once

src/ESP8266_PWM.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1818
This important feature is absolutely necessary for mission-critical tasks.
1919
20-
Version: 1.1.0
20+
Version: 1.2.1
2121
2222
Version Modified By Date Comments
2323
------- ----------- ---------- -----------
2424
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
2525
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
26+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
27+
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
2628
*****************************************************************************************************************************/
2729

2830
#pragma once
@@ -37,13 +39,13 @@
3739
#include "Arduino.h"
3840

3941
#ifndef ESP8266_PWM_VERSION
40-
#define ESP8266_PWM_VERSION "ESP8266_PWM v1.2.0"
42+
#define ESP8266_PWM_VERSION "ESP8266_PWM v1.2.1"
4143

4244
#define ESP8266_PWM_VERSION_MAJOR 1
4345
#define ESP8266_PWM_VERSION_MINOR 2
44-
#define ESP8266_PWM_VERSION_PATCH 0
46+
#define ESP8266_PWM_VERSION_PATCH 1
4547

46-
#define ESP8266_PWM_VERSION_INT 1002000
48+
#define ESP8266_PWM_VERSION_INT 1002001
4749
#endif
4850

4951
#ifndef TIMER_INTERRUPT_DEBUG

src/ESP8266_PWM_ISR.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1717
This important feature is absolutely necessary for mission-critical tasks.
1818
19-
Version: 1.1.0
19+
Version: 1.2.1
2020
2121
Version Modified By Date Comments
2222
------- ----------- ---------- -----------
2323
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
2424
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
25+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
26+
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
2527
*****************************************************************************************************************************/
2628

2729
#pragma once

src/ESP8266_PWM_ISR.hpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1717
This important feature is absolutely necessary for mission-critical tasks.
1818
19-
Version: 1.1.0
19+
Version: 1.2.1
2020
2121
Version Modified By Date Comments
2222
------- ----------- ---------- -----------
2323
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
2424
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
25+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
26+
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
2527
*****************************************************************************************************************************/
2628

2729
#pragma once
@@ -109,7 +111,7 @@ class ESP8266_PWM_ISR
109111
{
110112
double period = 0.0;
111113

112-
if ( ( frequency > 0 ) && ( frequency <= 500 ) )
114+
if ( ( frequency > 0.0 ) && ( frequency <= 500.0 ) )
113115
{
114116
#if USING_MICROS_RESOLUTION
115117
// period in us
@@ -131,8 +133,8 @@ class ESP8266_PWM_ISR
131133

132134
// period in us
133135
// Return the channelNum if OK, -1 if error
134-
int setPWM_Period(const uint32_t& pin, const double& period, const double& dutycycle, esp8266_timer_callback StartCallback = nullptr,
135-
esp8266_timer_callback StopCallback = nullptr)
136+
int setPWM_Period(const uint32_t& pin, const double& period, const double& dutycycle,
137+
esp8266_timer_callback StartCallback = nullptr, esp8266_timer_callback StopCallback = nullptr)
136138
{
137139
return setupPWMChannel(pin, period, dutycycle, (void *) StartCallback, (void *) StopCallback);
138140
}
@@ -141,11 +143,11 @@ class ESP8266_PWM_ISR
141143

142144
// low level function to modify a PWM channel
143145
// returns the true on success or false on failure
144-
bool modifyPWMChannel(const unsigned& channelNum, const uint32_t& pin, const double& frequency, const double& dutycycle)
146+
bool modifyPWMChannel(const uint8_t& channelNum, const uint32_t& pin, const double& frequency, const double& dutycycle)
145147
{
146-
uint32_t period = 0;
148+
double period = 0.0;
147149

148-
if ( ( frequency > 0 ) && ( frequency <= 500 ) )
150+
if ( ( frequency > 0.0 ) && ( frequency <= 500.0 ) )
149151
{
150152
#if USING_MICROS_RESOLUTION
151153
// period in us
@@ -165,22 +167,22 @@ class ESP8266_PWM_ISR
165167
}
166168

167169
//period in us
168-
bool modifyPWMChannel_Period(const unsigned& channelNum, const uint32_t& pin, const double& period, const double& dutycycle);
170+
bool modifyPWMChannel_Period(const uint8_t& channelNum, const uint32_t& pin, const double& period, const double& dutycycle);
169171

170172
// destroy the specified PWM channel
171-
void deleteChannel(const unsigned& channelNum);
173+
void deleteChannel(const uint8_t& channelNum);
172174

173175
// restart the specified PWM channel
174-
void restartChannel(const unsigned& channelNum);
176+
void restartChannel(const uint8_t& channelNum);
175177

176178
// returns true if the specified PWM channel is enabled
177-
bool isEnabled(const unsigned& channelNum);
179+
bool isEnabled(const uint8_t& channelNum);
178180

179181
// enables the specified PWM channel
180-
void enable(const unsigned& channelNum);
182+
void enable(const uint8_t& channelNum);
181183

182184
// disables the specified PWM channel
183-
void disable(const unsigned& channelNum);
185+
void disable(const uint8_t& channelNum);
184186

185187
// enables all PWM channels
186188
void enableAll();
@@ -189,15 +191,18 @@ class ESP8266_PWM_ISR
189191
void disableAll();
190192

191193
// enables the specified PWM channel if it's currently disabled, and vice-versa
192-
void toggle(const unsigned& channelNum);
194+
void toggle(const uint8_t& channelNum);
193195

194196
// returns the number of used PWM channels
195-
unsigned getnumChannels();
197+
int8_t getnumChannels();
196198

197199
// returns the number of available PWM channels
198-
unsigned getNumAvailablePWMChannels()
200+
uint8_t getNumAvailablePWMChannels()
199201
{
200-
return MAX_NUMBER_CHANNELS - numChannels;
202+
if (numChannels <= 0)
203+
return MAX_NUMBER_CHANNELS;
204+
else
205+
return MAX_NUMBER_CHANNELS - numChannels;
201206
};
202207

203208
private:
@@ -237,7 +242,7 @@ class ESP8266_PWM_ISR
237242
volatile PWM_t PWM[MAX_NUMBER_CHANNELS];
238243

239244
// actual number of PWM channels in use (-1 means uninitialized)
240-
volatile int numChannels;
245+
volatile int8_t numChannels;
241246
};
242247

243248

0 commit comments

Comments
 (0)