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. Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
3. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19)
4. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
5. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](#1 (comment))
6. Update examples accordingly
  • Loading branch information
khoih-prog authored Jan 29, 2022
1 parent a47bbab commit f85307b
Show file tree
Hide file tree
Showing 19 changed files with 1,131 additions and 856 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 IDE version (e.g. 1.8.19) or Platform.io version
* `ESP8266` Core Version (e.g. ESP8266 core v3.0.2)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
Expand All @@ -26,11 +26,11 @@ Please ensure to specify the following:
### Example

```
Arduino IDE version: 1.8.16
ESP8266 core v3.0.2
ESP8266_NODEMCU_ESP12E Module
Arduino IDE version: v1.8.19
ESP8266 Core Version v3.0.2
ESP8266_NODEMCU
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-86-generic #97-Ubuntu SMP Fri Sep 17 19:19:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while using TimerInterrupt.
Expand Down
285 changes: 143 additions & 142 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)
* [Releases v1.0.0](#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. Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
3. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](https://github.com/khoih-prog/ESP8266TimerInterrupt/pull/19)
4. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
5. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](https://github.com/khoih-prog/ESP8266_PWM/issues/1#issuecomment-1024969658)
6. Update examples accordingly

### Releases v1.1.0

1. Add functions to modify PWM settings on-the-fly
Expand Down
23 changes: 15 additions & 8 deletions examples/ISR_16_PWMs_Array/ISR_16_PWMs_Array.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 4

#define USING_MICROS_RESOLUTION true //false
#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

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "ESP8266_PWM.h"

#ifndef LED_BUILTIN
Expand Down Expand Up @@ -85,24 +91,25 @@ uint32_t PWM_Pin[NUMBER_ISR_PWMS] =
};

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
double PWM_Period[NUMBER_ISR_PWMS] =
{
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L
1000000.0, 500000.0, 333333.333, 250000.0, 200000.0, 166666.667, 142857.143, 125000.0
};


// You can assign any interval for any timer here, in Hz
uint32_t PWM_Freq[NUMBER_ISR_PWMS] =
double PWM_Freq[NUMBER_ISR_PWMS] =
{
1, 2, 3, 4, 5, 6, 7, 8
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0
};

// You can assign any interval for any timer here, in milliseconds
uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS] =
// You can assign any interval for any timer here, in Microseconds
double PWM_DutyCycle[NUMBER_ISR_PWMS] =
{
5, 10, 20, 30, 40, 45, 50, 55
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0
};


typedef void (*irqCallback) ();


Expand Down
60 changes: 33 additions & 27 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 @@ -30,8 +30,14 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 4

#define USING_MICROS_RESOLUTION true //false
#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

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "ESP8266_PWM.h"

#include <SimpleTimer.h> // https://github.com/jfturcot/SimpleTimer
Expand Down Expand Up @@ -97,12 +103,12 @@ typedef struct
irqCallback irqCallbackStopFunc;

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

uint32_t PWM_DutyCycle;
double PWM_DutyCycle;

uint64_t deltaMicrosStart;
uint64_t previousMicrosStart;
Expand Down Expand Up @@ -134,22 +140,22 @@ uint32_t PWM_Pin[NUMBER_ISR_PWMS] =
};

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
double PWM_Period[NUMBER_ISR_PWMS] =
{
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L
1000000.0, 500000.0, 333333.333, 250000.0, 200000.0, 166666.667, 142857.143, 125000.0
};


// You can assign any interval for any timer here, in Hz
uint32_t PWM_Freq[NUMBER_ISR_PWMS] =
double PWM_Freq[NUMBER_ISR_PWMS] =
{
1, 2, 3, 4, 5, 6, 7, 8
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0
};

// You can assign any interval for any timer here, in Microseconds
uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS] =
double PWM_DutyCycle[NUMBER_ISR_PWMS] =
{
5, 10, 20, 30, 40, 45, 50, 55
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0
};

///////////////////////////////////
Expand Down Expand Up @@ -269,29 +275,29 @@ void doingSomethingStop7()
ISR_PWM_Data curISR_PWM_Data[NUMBER_ISR_PWMS] =
{
//pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Period, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
{ PIN_D0, doingSomethingStart0, doingSomethingStop0, 1, 5, 0, 0, 0, 0 },
{ PIN_D1, doingSomethingStart1, doingSomethingStop1, 2, 10, 0, 0, 0, 0 },
{ LED_BUILTIN, doingSomethingStart2, doingSomethingStop2, 3, 20, 0, 0, 0, 0 },
{ PIN_D3, doingSomethingStart3, doingSomethingStop3, 4, 30, 0, 0, 0, 0 },
{ PIN_D4, doingSomethingStart4, doingSomethingStop4, 5, 40, 0, 0, 0, 0 },
{ PIN_D5, doingSomethingStart5, doingSomethingStop5, 6, 45, 0, 0, 0, 0 },
{ PIN_D6, doingSomethingStart6, doingSomethingStop6, 7, 50, 0, 0, 0, 0 },
{ PIN_D7, doingSomethingStart7, doingSomethingStop7, 8, 55, 0, 0, 0, 0 },
{ PIN_D0, doingSomethingStart0, doingSomethingStop0, 1.0, 5.0, 0, 0, 0, 0 },
{ PIN_D1, doingSomethingStart1, doingSomethingStop1, 2.0, 10.0, 0, 0, 0, 0 },
{ LED_BUILTIN, doingSomethingStart2, doingSomethingStop2, 3.0, 20.0, 0, 0, 0, 0 },
{ PIN_D3, doingSomethingStart3, doingSomethingStop3, 4.0, 30.0, 0, 0, 0, 0 },
{ PIN_D4, doingSomethingStart4, doingSomethingStop4, 5.0, 40.0, 0, 0, 0, 0 },
{ PIN_D5, doingSomethingStart5, doingSomethingStop5, 6.0, 45.0, 0, 0, 0, 0 },
{ PIN_D6, doingSomethingStart6, doingSomethingStop6, 7.0, 50.0, 0, 0, 0, 0 },
{ PIN_D7, doingSomethingStart7, doingSomethingStop7, 8.0, 55.0, 0, 0, 0, 0 },
};

#else // #if USING_PWM_FREQUENCY

ISR_PWM_Data curISR_PWM_Data[NUMBER_ISR_PWMS] =
{
//irqCallbackStartFunc, PWM_Period, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
{ PIN_D0, doingSomethingStart0, doingSomethingStop0, 1000000L, 5, 0, 0, 0, 0 },
{ PIN_D1, doingSomethingStart1, doingSomethingStop1, 500000L, 10, 0, 0, 0, 0 },
{ LED_BUILTIN, doingSomethingStart2, doingSomethingStop2, 333333L, 20, 0, 0, 0, 0 },
{ PIN_D3, doingSomethingStart3, doingSomethingStop3, 250000L, 30, 0, 0, 0, 0 },
{ PIN_D4, doingSomethingStart4, doingSomethingStop4, 200000L, 40, 0, 0, 0, 0 },
{ PIN_D5, doingSomethingStart5, doingSomethingStop5, 166667L, 45, 0, 0, 0, 0 },
{ PIN_D6, doingSomethingStart6, doingSomethingStop6, 142857L, 50, 0, 0, 0, 0 },
{ PIN_D7, doingSomethingStart7, doingSomethingStop7, 125000L, 55, 0, 0, 0, 0 },
{ PIN_D0, doingSomethingStart0, doingSomethingStop0, 1000000.0, 5.0, 0, 0, 0, 0 },
{ PIN_D1, doingSomethingStart1, doingSomethingStop1, 500000.0, 10.0, 0, 0, 0, 0 },
{ LED_BUILTIN, doingSomethingStart2, doingSomethingStop2, 333333,333, 20.0, 0, 0, 0, 0 },
{ PIN_D3, doingSomethingStart3, doingSomethingStop3, 250000.0, 30.0, 0, 0, 0, 0 },
{ PIN_D4, doingSomethingStart4, doingSomethingStop4, 200000.0, 40.0, 0, 0, 0, 0 },
{ PIN_D5, doingSomethingStart5, doingSomethingStop5, 166666.667, 45.0, 0, 0, 0, 0 },
{ PIN_D6, doingSomethingStart6, doingSomethingStop6, 142857.143, 50.0, 0, 0, 0, 0 },
{ PIN_D7, doingSomethingStart7, doingSomethingStop7, 125000.0, 55.0, 0, 0, 0, 0 },
};

#endif // #if USING_PWM_FREQUENCY
Expand Down Expand Up @@ -376,7 +382,7 @@ void simpleTimerdoingSomething2s()
Serial.print(F("PWM Channel : ")); Serial.print(i);

#if USING_PWM_FREQUENCY
Serial.print(1000000 / PWM_Freq[i]);
Serial.print(1000000.0 / PWM_Freq[i]);
#else
Serial.print(PWM_Period[i]);
#endif
Expand Down
23 changes: 15 additions & 8 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 @@ -26,8 +26,14 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 4

#define USING_MICROS_RESOLUTION true //false
#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

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "ESP8266_PWM.h"

#ifndef LED_BUILTIN
Expand Down Expand Up @@ -85,21 +91,22 @@ uint32_t PWM_Pin[NUMBER_ISR_PWMS] =
};

// You can assign any interval for any timer here, in microseconds
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
double PWM_Period[NUMBER_ISR_PWMS] =
{
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L
1000000.0, 500000.0, 333333.333, 250000.0, 200000.0, 166666.667, 142857.143, 125000.0
};


// You can assign any interval for any timer here, in Hz
uint32_t PWM_Freq[NUMBER_ISR_PWMS] =
double PWM_Freq[NUMBER_ISR_PWMS] =
{
1, 2, 3, 4, 5, 6, 7, 8
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0
};

// You can assign any interval for any timer here, in milliseconds
uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS] =
// You can assign any interval for any timer here, in Microseconds
double PWM_DutyCycle[NUMBER_ISR_PWMS] =
{
5, 10, 20, 30, 40, 45, 50, 55
5.0, 10.0, 20.0, 30.0, 40.0, 45.0, 50.0, 55.0
};

////////////////////////////////////////////////
Expand Down
18 changes: 12 additions & 6 deletions examples/ISR_Changing_PWM/ISR_Changing_PWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@
*****************************************************************************************************************************/

#if !defined(ESP8266)
#error This code is designed to run on ESP8266 and ESP8266-based boards! Please check your Tools->Board setting.
#error This code is designed to run on ESP8266 and ESP8266-based boards! Please check your Tools->Board setting.
#endif

// These define's must be placed at the beginning before #include "ESP8266_PWM.h"
// _PWM_LOGLEVEL_ from 0 to 4
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 4

#define USING_MICROS_RESOLUTION true //false
#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

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "ESP8266_PWM.h"

#ifndef LED_BUILTIN
Expand Down Expand Up @@ -85,14 +91,14 @@ double PWM_Freq1 = 1.0f;
double PWM_Freq2 = 2.0f;

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

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

// Channel number used to identify associated channel
int channelNum;
Expand Down
16 changes: 11 additions & 5 deletions examples/ISR_Modify_PWM/ISR_Modify_PWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 4

#define USING_MICROS_RESOLUTION true //false
#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

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "ESP8266_PWM.h"

#ifndef LED_BUILTIN
Expand Down Expand Up @@ -64,14 +70,14 @@ double PWM_Freq1 = 1.0f;
double PWM_Freq2 = 2.0f;

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

// You can assign any duty_cycle for any PWM here, from 0-100
uint32_t PWM_DutyCycle1 = 10;
double PWM_DutyCycle1 = 10.0;
// You can assign any duty_cycle for any PWM here, from 0-100
uint32_t PWM_DutyCycle2 = 90;
double 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 ESP8266 boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_PWM
Licensed under MIT license
*****************************************************************************************************************************/

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

#include "multiFileProject.h"
16 changes: 16 additions & 0 deletions examples/multiFileProject/multiFileProject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/****************************************************************************************************************************
multiFileProject.h
For ESP8266 boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_PWM
Licensed under MIT license
*****************************************************************************************************************************/

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

#pragma once

// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "ESP8266_PWM.hpp"
Loading

0 comments on commit f85307b

Please sign in to comment.