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

Commit

Permalink
v1.2.0 to fix multiple-definitions linker error
Browse files Browse the repository at this point in the history
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
  • Loading branch information
khoih-prog authored Feb 7, 2022
1 parent 4764b9c commit c6387d1
Show file tree
Hide file tree
Showing 21 changed files with 1,455 additions and 1,141 deletions.
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p

Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.16) or Platform.io version
* Arduino `mbed` Core Version (e.g. Arduino `mbed` core v1.3.2 or Arduino `mbed_nano` core v2.5.2 )
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* Arduino `mbed` Core Version (e.g. Arduino `mbed` core v1.3.2 or Arduino `mbed_nano` core v2.6.1)
* 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:
Expand All @@ -26,10 +26,10 @@ Please ensure to specify the following:
### Example

```
Arduino IDE version: 1.8.16
Arduino mbed_nano` core v2.5.2
Arduino IDE version: 1.8.19
Arduino mbed_nano` core v2.6.1
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.4.0-97-generic #110-Ubuntu SMP Thu Jan 13 18:22:13 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while trying to use the Timer Interrupt.
Expand All @@ -50,3 +50,4 @@ There are usually some outstanding feature requests in the [existing issues list
### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

344 changes: 185 additions & 159 deletions README.md

Large diffs are not rendered by default.

10 changes: 10 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.0](#releases-v120)
* [Releases v1.1.0](#releases-v110)
* [Initial Releases v1.0.0](#Initial-Releases-v100)

Expand All @@ -20,6 +21,15 @@

## Changelog

### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](https://github.com/khoih-prog/ESP8266_PWM/issues/1#issuecomment-1024969658)
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](https://github.com/khoih-prog/ESP8266_PWM/issues/2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly

### Releases v1.1.0

1. Add functions to modify PWM settings on-the-fly
Expand Down
24 changes: 8 additions & 16 deletions examples/ISR_16_PWMs_Array/ISR_16_PWMs_Array.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 25/09/2021 Initial coding for nRF52-based boards using Arduino mbed_nano core, such as Nano_33_BLE
*****************************************************************************************************************************/

#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
Expand Down Expand Up @@ -92,31 +86,31 @@ void TimerHandler()
//////////////////////////////////////////////////////

// You can assign pins here. Be carefull to select good pin to use or crash, e.g pin 6-11
uint32_t PWM_Pin[NUMBER_ISR_PWMS] =
uint32_t PWM_Pin[] =
{
LED_BUILTIN, LED_BLUE, LED_RED, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4,
PIN_D5, PIN_D6, PIN_D7, PIN_D8, PIN_D9, PIN_D10, PIN_D11, PIN_D12
};

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
uint32_t PWM_Period[] =
{
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
};

// You can assign any interval for any timer here, in Hz
double PWM_Freq[NUMBER_ISR_PWMS] =
float PWM_Freq[] =
{
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
};

// You can assign any interval for any timer here, in milliseconds
uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS] =
float PWM_DutyCycle[] =
{
5, 10, 20, 30, 40, 45, 50, 55,
60, 65, 70, 75, 80, 85, 90, 95
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0,
60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0
};

typedef void (*irqCallback) ();
Expand Down Expand Up @@ -189,7 +183,7 @@ void doingSomething15()
{
}

irqCallback irqCallbackStartFunc[NUMBER_ISR_PWMS] =
irqCallback irqCallbackStartFunc[] =
{
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
doingSomething4, doingSomething5, doingSomething6, doingSomething7,
Expand Down Expand Up @@ -218,12 +212,11 @@ void setup()
else
Serial.println(F("Can't set ITimer. Select another freq. or timer"));

#if 1
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
// You can use up to 16 timer for each ISR_PWM
for (uint16_t i = 0; i < NUMBER_ISR_PWMS; i++)
{
//void setPWM(uint32_t pin, uint32_t frequency, uint32_t dutycycle
//void setPWM(uint32_t pin, float frequency, float dutycycle
// , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr)

#if USING_PWM_FREQUENCY
Expand All @@ -241,7 +234,6 @@ void setup()
#endif
#endif
}
#endif
}

void loop()
Expand Down
41 changes: 18 additions & 23 deletions examples/ISR_16_PWMs_Array_Complex/ISR_16_PWMs_Array_Complex.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 25/09/2021 Initial coding for nRF52-based boards using Arduino mbed_nano core, such as Nano_33_BLE
*****************************************************************************************************************************/

#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
Expand Down Expand Up @@ -106,12 +100,12 @@ typedef struct
irqCallback irqCallbackStopFunc;

#if USING_PWM_FREQUENCY
uint32_t PWM_Freq;
float PWM_Freq;
#else
uint32_t PWM_Period;
#endif

uint32_t PWM_DutyCycle;
float PWM_DutyCycle;

uint64_t deltaMicrosStart;
uint64_t previousMicrosStart;
Expand All @@ -131,40 +125,41 @@ void doingSomethingStop(int index);

#else // #if USE_COMPLEX_STRUCT

volatile unsigned long deltaMicrosStart [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
volatile unsigned long previousMicrosStart [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
volatile unsigned long deltaMicrosStart [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
volatile unsigned long previousMicrosStart [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

volatile unsigned long deltaMicrosStop [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
volatile unsigned long previousMicrosStop [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
volatile unsigned long deltaMicrosStop [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
volatile unsigned long previousMicrosStop [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

// You can assign pins here. Be carefull to select good pin to use or crash, e.g pin 6-11
uint32_t PWM_Pin[NUMBER_ISR_PWMS] =
uint32_t PWM_Pin[] =
{
LED_BUILTIN, LED_BLUE, LED_RED, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4,
PIN_D5, PIN_D6, PIN_D7, PIN_D8, PIN_D9, PIN_D10, PIN_D11, PIN_D12
};

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
uint32_t PWM_Period[] =
{
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
};

// You can assign any interval for any timer here, in Hz
double PWM_Freq[NUMBER_ISR_PWMS] =
float PWM_Freq[] =
{
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
};

// You can assign any interval for any timer here, in milliseconds
uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS] =
float PWM_DutyCycle[] =
{
5, 10, 20, 30, 40, 45, 50, 55,
60, 65, 70, 75, 80, 85, 90, 95
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0,
60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0
};


void doingSomethingStart(int index)
{
unsigned long currentMicros = micros();
Expand Down Expand Up @@ -356,7 +351,7 @@ void doingSomethingStop15()

#if USING_PWM_FREQUENCY

ISR_PWM_Data curISR_PWM_Data[NUMBER_ISR_PWMS] =
ISR_PWM_Data curISR_PWM_Data[] =
{
// pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Freq, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
{ LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1, 5, 0, 0, 0, 0 },
Expand All @@ -379,7 +374,7 @@ void doingSomethingStop15()

#else // #if USING_PWM_FREQUENCY

ISR_PWM_Data curISR_PWM_Data[NUMBER_ISR_PWMS] =
ISR_PWM_Data curISR_PWM_Data[] =
{
// pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Period, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
{ LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1000000L, 5, 0, 0, 0, 0 },
Expand Down Expand Up @@ -422,15 +417,15 @@ void doingSomethingStop(int index)

#else // #if USE_COMPLEX_STRUCT

irqCallback irqCallbackStartFunc[NUMBER_ISR_PWMS] =
irqCallback irqCallbackStartFunc[] =
{
doingSomethingStart0, doingSomethingStart1, doingSomethingStart2, doingSomethingStart3,
doingSomethingStart4, doingSomethingStart5, doingSomethingStart6, doingSomethingStart7,
doingSomethingStart8, doingSomethingStart9, doingSomethingStart10, doingSomethingStart11,
doingSomethingStart12, doingSomethingStart13, doingSomethingStart14, doingSomethingStart15
};

irqCallback irqCallbackStopFunc[NUMBER_ISR_PWMS] =
irqCallback irqCallbackStopFunc[] =
{
doingSomethingStop0, doingSomethingStop1, doingSomethingStop2, doingSomethingStop3,
doingSomethingStop4, doingSomethingStop5, doingSomethingStop6, doingSomethingStop7,
Expand Down Expand Up @@ -535,7 +530,7 @@ void setup()
curISR_PWM_Data[i].previousMicrosStart = startMicros;
//ISR_PWM.setInterval(curISR_PWM_Data[i].PWM_Period, curISR_PWM_Data[i].irqCallbackStartFunc);

//void setPWM(uint32_t pin, uint32_t frequency, uint32_t dutycycle
//void setPWM(uint32_t pin, float frequency, float dutycycle
// , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr)

#if USING_PWM_FREQUENCY
Expand Down
18 changes: 5 additions & 13 deletions examples/ISR_16_PWMs_Array_Simple/ISR_16_PWMs_Array_Simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 25/09/2021 Initial coding for nRF52-based boards using Arduino mbed_nano core, such as Nano_33_BLE
*****************************************************************************************************************************/

#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
Expand Down Expand Up @@ -107,21 +101,19 @@ uint32_t PWM_Period[NUMBER_ISR_PWMS] =
};

// You can assign any interval for any timer here, in Hz
double PWM_Freq[NUMBER_ISR_PWMS] =
float PWM_Freq[] =
{
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
};

// You can assign any interval for any timer here, in milliseconds
uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS] =
float PWM_DutyCycle[] =
{
5, 10, 20, 30, 40, 45, 50, 55,
60, 65, 70, 75, 80, 85, 90, 95
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0,
60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0
};



////////////////////////////////////////////////

void setup()
Expand All @@ -147,7 +139,7 @@ void setup()
// You can use up to 16 timer for each ISR_PWM
for (uint16_t i = 0; i < NUMBER_ISR_PWMS; i++)
{
//void setPWM(uint32_t pin, uint32_t frequency, uint32_t dutycycle
//void setPWM(uint32_t pin, float frequency, float dutycycle
// , timer_callback_p StartCallback = nullptr, timer_callback_p StopCallback = nullptr)

#if USING_PWM_FREQUENCY
Expand Down
14 changes: 4 additions & 10 deletions examples/ISR_Changing_PWM/ISR_Changing_PWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 25/09/2021 Initial coding for nRF52-based boards using Arduino mbed_nano core, such as Nano_33_BLE
*****************************************************************************************************************************/

#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
Expand Down Expand Up @@ -77,19 +71,19 @@ void TimerHandler()
uint32_t PWM_Pin = LED_BUILTIN;

// You can assign any interval for any timer here, in Hz
double PWM_Freq1 = 1.0f;
float PWM_Freq1 = 1.0f;
// You can assign any interval for any timer here, in Hz
double PWM_Freq2 = 2.0f;
float PWM_Freq2 = 2.0f;

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period1 = 1000000 / PWM_Freq1;
// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period2 = 1000000 / PWM_Freq2;

// You can assign any duty_cycle for any PWM here, from 0-100
uint32_t PWM_DutyCycle1 = 50;
float PWM_DutyCycle1 = 50.0;
// You can assign any duty_cycle for any PWM here, from 0-100
uint32_t PWM_DutyCycle2 = 90;
float PWM_DutyCycle2 = 90.0;

// Channel number used to identify associated channel
int channelNum;
Expand Down
14 changes: 4 additions & 10 deletions examples/ISR_Modify_PWM/ISR_Modify_PWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.0.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 25/09/2021 Initial coding for nRF52-based boards using Arduino mbed_nano core, such as Nano_33_BLE
*****************************************************************************************************************************/

#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
Expand Down Expand Up @@ -77,19 +71,19 @@ void TimerHandler()
uint32_t PWM_Pin = LED_BUILTIN;

// You can assign any interval for any timer here, in Hz
double PWM_Freq1 = 1.0f;
float PWM_Freq1 = 1.0f;
// You can assign any interval for any timer here, in Hz
double PWM_Freq2 = 2.0f;
float PWM_Freq2 = 2.0f;

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period1 = 1000000 / PWM_Freq1;
// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period2 = 1000000 / PWM_Freq2;

// You can assign any duty_cycle for any PWM here, from 0-100
uint32_t PWM_DutyCycle1 = 10;
float PWM_DutyCycle1 = 50.0;
// You can assign any duty_cycle for any PWM here, from 0-100
uint32_t PWM_DutyCycle2 = 90;
float PWM_DutyCycle2 = 90.0;

// Channel number used to identify associated channel
int channelNum;
Expand Down
13 changes: 13 additions & 0 deletions examples/multiFileProject/multiFileProject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/****************************************************************************************************************************
multiFileProject.cpp
For nRF52-based boards using Arduino mbed_nano core, such as Nano_33_BLE
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/nRF52_MBED_Slow_PWM
Licensed under MIT license
*****************************************************************************************************************************/

// To demo how to include files in multi-file Projects

#include "multiFileProject.h"
Loading

0 comments on commit c6387d1

Please sign in to comment.