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

Commit

Permalink
v1.2.1 to fix bug and optimize
Browse files Browse the repository at this point in the history
### Releases v1.2.1

1. Fix bug.
2. Optimize library code by using `reference-passing` instead of `value-passing`
  • Loading branch information
khoih-prog authored Jan 30, 2022
1 parent cfd3e0b commit 2c23550
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 83 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar

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

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

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

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

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


---
---
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.2.1](#releases-v121)
* [Releases v1.2.0](#releases-v120)
* [Releases v1.1.0](#releases-v110)
* [Releases v1.0.0](#releases-v100)
Expand All @@ -21,6 +22,11 @@

## Changelog

### Releases v1.2.1

1. Fix bug.
2. Optimize library code by using `reference-passing` instead of `value-passing`

### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
Expand Down
7 changes: 7 additions & 0 deletions examples/multiFileProject/multiFileProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@

#pragma once

#define USING_MICROS_RESOLUTION true //false

// Select a Timer Clock
#define USING_TIM_DIV1 true // for shortest and most accurate timer
#define USING_TIM_DIV16 false // for medium time and medium accurate timer
#define USING_TIM_DIV256 false // for longest timer but least accurate. Default

// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "ESP8266_PWM.hpp"
9 changes: 2 additions & 7 deletions examples/multiFileProject/multiFileProject.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@
#error This code is designed to run on ESP8266 and ESP8266-based boards! Please check your Tools->Board setting.
#endif

#define ESP8266_PWM_VERSION_MIN_TARGET "ESP8266_PWM v1.2.0"
#define ESP8266_PWM_VERSION_MIN 1002000

// Select a Timer Clock
#define USING_TIM_DIV1 false // for shortest and most accurate timer
#define USING_TIM_DIV16 false // for medium time and medium accurate timer
#define USING_TIM_DIV256 true // for longest timer but least accurate. Default
#define ESP8266_PWM_VERSION_MIN_TARGET "ESP8266_PWM v1.2.1"
#define ESP8266_PWM_VERSION_MIN 1002001

#include "multiFileProject.h"

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP8266_PWM",
"version": "1.2.0",
"version": "1.2.1",
"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",
"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",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESP8266_PWM
version=1.2.0
version=1.2.1
author=Khoi Hoang <[email protected]>
maintainer=Khoi Hoang <[email protected]>
sentence=TThis library enables you to use Interrupt from Hardware Timers on an ESP8266-based board to create and output PWM to pins.
Expand Down
4 changes: 3 additions & 1 deletion src/ESP8266_PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
*****************************************************************************************************************************/

#pragma once
Expand Down
10 changes: 6 additions & 4 deletions src/ESP8266_PWM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
*****************************************************************************************************************************/

#pragma once
Expand All @@ -37,13 +39,13 @@
#include "Arduino.h"

#ifndef ESP8266_PWM_VERSION
#define ESP8266_PWM_VERSION "ESP8266_PWM v1.2.0"
#define ESP8266_PWM_VERSION "ESP8266_PWM v1.2.1"

#define ESP8266_PWM_VERSION_MAJOR 1
#define ESP8266_PWM_VERSION_MINOR 2
#define ESP8266_PWM_VERSION_PATCH 0
#define ESP8266_PWM_VERSION_PATCH 1

#define ESP8266_PWM_VERSION_INT 1002000
#define ESP8266_PWM_VERSION_INT 1002001
#endif

#ifndef TIMER_INTERRUPT_DEBUG
Expand Down
4 changes: 3 additions & 1 deletion src/ESP8266_PWM_ISR.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
*****************************************************************************************************************************/

#pragma once
Expand Down
41 changes: 23 additions & 18 deletions src/ESP8266_PWM_ISR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 21/09/2021 Initial coding for ESP8266 boards with ESP8266 core v3.0.2+
1.1.0 K Hoang 06/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 Fix bug. Optimize code
*****************************************************************************************************************************/

#pragma once
Expand Down Expand Up @@ -109,7 +111,7 @@ class ESP8266_PWM_ISR
{
double period = 0.0;

if ( ( frequency > 0 ) && ( frequency <= 500 ) )
if ( ( frequency > 0.0 ) && ( frequency <= 500.0 ) )
{
#if USING_MICROS_RESOLUTION
// period in us
Expand All @@ -131,8 +133,8 @@ class ESP8266_PWM_ISR

// period in us
// Return the channelNum if OK, -1 if error
int setPWM_Period(const uint32_t& pin, const double& period, const double& dutycycle, esp8266_timer_callback StartCallback = nullptr,
esp8266_timer_callback StopCallback = nullptr)
int setPWM_Period(const uint32_t& pin, const double& period, const double& dutycycle,
esp8266_timer_callback StartCallback = nullptr, esp8266_timer_callback StopCallback = nullptr)
{
return setupPWMChannel(pin, period, dutycycle, (void *) StartCallback, (void *) StopCallback);
}
Expand All @@ -141,11 +143,11 @@ class ESP8266_PWM_ISR

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

if ( ( frequency > 0 ) && ( frequency <= 500 ) )
if ( ( frequency > 0.0 ) && ( frequency <= 500.0 ) )
{
#if USING_MICROS_RESOLUTION
// period in us
Expand All @@ -165,22 +167,22 @@ class ESP8266_PWM_ISR
}

//period in us
bool modifyPWMChannel_Period(const unsigned& channelNum, const uint32_t& pin, const double& period, const double& dutycycle);
bool modifyPWMChannel_Period(const uint8_t& channelNum, const uint32_t& pin, const double& period, const double& dutycycle);

// destroy the specified PWM channel
void deleteChannel(const unsigned& channelNum);
void deleteChannel(const uint8_t& channelNum);

// restart the specified PWM channel
void restartChannel(const unsigned& channelNum);
void restartChannel(const uint8_t& channelNum);

// returns true if the specified PWM channel is enabled
bool isEnabled(const unsigned& channelNum);
bool isEnabled(const uint8_t& channelNum);

// enables the specified PWM channel
void enable(const unsigned& channelNum);
void enable(const uint8_t& channelNum);

// disables the specified PWM channel
void disable(const unsigned& channelNum);
void disable(const uint8_t& channelNum);

// enables all PWM channels
void enableAll();
Expand All @@ -189,15 +191,18 @@ class ESP8266_PWM_ISR
void disableAll();

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

// returns the number of used PWM channels
unsigned getnumChannels();
int8_t getnumChannels();

// returns the number of available PWM channels
unsigned getNumAvailablePWMChannels()
uint8_t getNumAvailablePWMChannels()
{
return MAX_NUMBER_CHANNELS - numChannels;
if (numChannels <= 0)
return MAX_NUMBER_CHANNELS;
else
return MAX_NUMBER_CHANNELS - numChannels;
};

private:
Expand Down Expand Up @@ -237,7 +242,7 @@ class ESP8266_PWM_ISR
volatile PWM_t PWM[MAX_NUMBER_CHANNELS];

// actual number of PWM channels in use (-1 means uninitialized)
volatile int numChannels;
volatile int8_t numChannels;
};


Expand Down
Loading

0 comments on commit 2c23550

Please sign in to comment.