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

Commit 655e979

Browse files
authored
v1.2.0 to fix multiple-definitions linker error
### Releases v1.2.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project 3. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period` 4. Optimize library code by using `reference-passing` instead of `value-passing` 5. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 6. Update examples accordingly
1 parent 7e4c9fd commit 655e979

20 files changed

+1242
-985
lines changed

CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1414

1515
Please ensure to specify the following:
1616

17-
* Arduino IDE version (e.g. 1.8.16) or Platform.io version
18-
* `STM32` Core Version (e.g. STM32 core v2.1.0)
17+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18+
* `STM32` Core Version (e.g. STM32 core v2.2.0)
1919
* Board type and relevant info
2020
* Contextual information (e.g. what you were trying to achieve)
2121
* Simplest possible steps to reproduce
@@ -27,11 +27,11 @@ Please ensure to specify the following:
2727
### Example
2828

2929
```
30-
Arduino IDE version: 1.8.16
31-
STM32 Core Version 2.1.0
30+
Arduino IDE version: 1.8.19
31+
STM32 Core Version 2.2.0
3232
Nucleo-144 STM32H7 NUCLEO_H743ZI2
3333
OS: Ubuntu 20.04 LTS
34-
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
34+
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
3535
3636
Context:
3737
I encountered a crash while using TimerInterrupt.

README.md

+286-240
Large diffs are not rendered by default.

changelog.md

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.2.0](#releases-v120)
1516
* [Releases v1.1.0](#releases-v110)
1617
* [Initial Releases v1.0.0](#Initial-Releases-v100)
1718

@@ -20,6 +21,15 @@
2021

2122
## Changelog
2223

24+
### Releases v1.2.0
25+
26+
1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
27+
2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
28+
3. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`
29+
4. Optimize library code by using `reference-passing` instead of `value-passing`
30+
5. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](https://github.com/khoih-prog/ESP8266TimerInterrupt/pull/19)
31+
6. Update examples accordingly
32+
2333
### Releases v1.1.0
2434

2535
1. Add functions to modify PWM settings on-the-fly

examples/ISR_16_PWMs_Array/ISR_16_PWMs_Array.ino

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define MAX_STM32_PWM_FREQ 1000
3030

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

3334
#define LED_OFF LOW
@@ -96,31 +97,30 @@ void TimerHandler()
9697
//////////////////////////////////////////////////////
9798

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

105106
// You can assign any interval for any timer here, in microseconds
106-
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
107+
double PWM_Period[] =
107108
{
108-
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
109-
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
110-
};
109+
1000000.0, 500000.0, 333333.333, 250000.0, 200000.0, 166666.667, 142857.143, 125000.0,
110+
111111.111, 100000.0, 66666.667, 50000.0, 40000.0, 33333.333, 25000.0, 20000.0};
111111

112112
// You can assign any interval for any timer here, in Hz
113-
double PWM_Freq[NUMBER_ISR_PWMS] =
113+
double PWM_Freq[] =
114114
{
115115
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
116116
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
117117
};
118118

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

126126
typedef void (*irqCallback) ();

examples/ISR_16_PWMs_Array_Complex/ISR_16_PWMs_Array_Complex.ino

+59-59
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define MAX_STM32_PWM_FREQ 1000
3030

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

3334
#define boolean bool
@@ -112,12 +113,12 @@ typedef struct
112113
irqCallback irqCallbackStopFunc;
113114

114115
#if USING_PWM_FREQUENCY
115-
uint32_t PWM_Freq;
116+
double PWM_Freq;
116117
#else
117-
uint32_t PWM_Period;
118+
double PWM_Period;
118119
#endif
119120

120-
uint32_t PWM_DutyCycle;
121+
double PWM_DutyCycle;
121122

122123
uint64_t deltaMicrosStart;
123124
uint64_t previousMicrosStart;
@@ -137,38 +138,37 @@ void doingSomethingStop(int index);
137138

138139
#else // #if USE_COMPLEX_STRUCT
139140

140-
volatile unsigned long deltaMicrosStart [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
141-
volatile unsigned long previousMicrosStart [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
141+
volatile unsigned long deltaMicrosStart [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
142+
volatile unsigned long previousMicrosStart [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
142143

143-
volatile unsigned long deltaMicrosStop [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
144-
volatile unsigned long previousMicrosStop [NUMBER_ISR_PWMS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
144+
volatile unsigned long deltaMicrosStop [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
145+
volatile unsigned long previousMicrosStop [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
145146

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

153154
// You can assign any interval for any timer here, in microseconds
154-
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
155+
double PWM_Period[] =
155156
{
156-
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
157-
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
158-
};
157+
1000000.0, 500000.0, 333333.333, 250000.0, 200000.0, 166666.667, 142857.143, 125000.0,
158+
111111.111, 100000.0, 66666.667, 50000.0, 40000.0, 33333.333, 25000.0, 20000.0};
159159

160160
// You can assign any interval for any timer here, in Hz
161-
double PWM_Freq[NUMBER_ISR_PWMS] =
161+
double PWM_Freq[] =
162162
{
163163
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
164164
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
165165
};
166166

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

174174
void doingSomethingStart(int index)
@@ -362,48 +362,48 @@ void doingSomethingStop15()
362362

363363
#if USING_PWM_FREQUENCY
364364

365-
ISR_PWM_Data curISR_PWM_Data[NUMBER_ISR_PWMS] =
365+
ISR_PWM_Data curISR_PWM_Data[] =
366366
{
367367
// pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Freq, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
368-
{ LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1, 5, 0, 0, 0, 0 },
369-
{ LED_BLUE, doingSomethingStart1, doingSomethingStop1, 2, 10, 0, 0, 0, 0 },
370-
{ LED_RED, doingSomethingStart2, doingSomethingStop2, 3, 20, 0, 0, 0, 0 },
371-
{ PIN_D0, doingSomethingStart3, doingSomethingStop3, 4, 30, 0, 0, 0, 0 },
372-
{ PIN_D1, doingSomethingStart4, doingSomethingStop4, 5, 40, 0, 0, 0, 0 },
373-
{ PIN_D2, doingSomethingStart5, doingSomethingStop5, 6, 45, 0, 0, 0, 0 },
374-
{ PIN_D3, doingSomethingStart6, doingSomethingStop6, 7, 50, 0, 0, 0, 0 },
375-
{ PIN_D4, doingSomethingStart7, doingSomethingStop7, 8, 55, 0, 0, 0, 0 },
376-
{ PIN_D5, doingSomethingStart8, doingSomethingStop8, 9, 60, 0, 0, 0, 0 },
377-
{ PIN_D6, doingSomethingStart9, doingSomethingStop9, 10, 65, 0, 0, 0, 0 },
378-
{ PIN_D7, doingSomethingStart10, doingSomethingStop10, 15, 70, 0, 0, 0, 0 },
379-
{ PIN_D8, doingSomethingStart11, doingSomethingStop11, 20, 75, 0, 0, 0, 0 },
380-
{ PIN_D9, doingSomethingStart12, doingSomethingStop12, 25, 80, 0, 0, 0, 0 },
381-
{ PIN_D10, doingSomethingStart13, doingSomethingStop13, 30, 85, 0, 0, 0, 0 },
382-
{ PIN_D11, doingSomethingStart14, doingSomethingStop14, 40, 90, 0, 0, 0, 0 },
383-
{ PIN_D12, doingSomethingStart15, doingSomethingStop15, 50, 95, 0, 0, 0, 0 }
368+
{ LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1.0, 5.0, 0, 0, 0, 0 },
369+
{ LED_BLUE, doingSomethingStart1, doingSomethingStop1, 2.0, 10.0, 0, 0, 0, 0 },
370+
{ LED_RED, doingSomethingStart2, doingSomethingStop2, 3.0, 20.0, 0, 0, 0, 0 },
371+
{ PIN_D0, doingSomethingStart3, doingSomethingStop3, 4.0, 30.0, 0, 0, 0, 0 },
372+
{ PIN_D1, doingSomethingStart4, doingSomethingStop4, 5.0, 40.0, 0, 0, 0, 0 },
373+
{ PIN_D2, doingSomethingStart5, doingSomethingStop5, 6.0, 45.0, 0, 0, 0, 0 },
374+
{ PIN_D3, doingSomethingStart6, doingSomethingStop6, 7.0, 50.0, 0, 0, 0, 0 },
375+
{ PIN_D4, doingSomethingStart7, doingSomethingStop7, 8.0, 55.0, 0, 0, 0, 0 },
376+
{ PIN_D5, doingSomethingStart8, doingSomethingStop8, 9.0, 60.0, 0, 0, 0, 0 },
377+
{ PIN_D6, doingSomethingStart9, doingSomethingStop9, 10.0, 65.0, 0, 0, 0, 0 },
378+
{ PIN_D7, doingSomethingStart10, doingSomethingStop10, 15.0, 70.0, 0, 0, 0, 0 },
379+
{ PIN_D8, doingSomethingStart11, doingSomethingStop11, 20.0, 75.0, 0, 0, 0, 0 },
380+
{ PIN_D9, doingSomethingStart12, doingSomethingStop12, 25.0, 80.0, 0, 0, 0, 0 },
381+
{ PIN_D10, doingSomethingStart13, doingSomethingStop13, 30.0, 85.0, 0, 0, 0, 0 },
382+
{ PIN_D11, doingSomethingStart14, doingSomethingStop14, 40.0, 90.0, 0, 0, 0, 0 },
383+
{ PIN_D12, doingSomethingStart15, doingSomethingStop15, 50.0, 95.0, 0, 0, 0, 0 }
384384
};
385385

386386
#else // #if USING_PWM_FREQUENCY
387387

388-
ISR_PWM_Data curISR_PWM_Data[NUMBER_ISR_PWMS] =
388+
ISR_PWM_Data curISR_PWM_Data[] =
389389
{
390390
// pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Period, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
391-
{ LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1000000L, 5, 0, 0, 0, 0 },
392-
{ LED_BLUE, doingSomethingStart1, doingSomethingStop1, 500000L, 10, 0, 0, 0, 0 },
393-
{ LED_RED, doingSomethingStart2, doingSomethingStop2, 333333L, 20, 0, 0, 0, 0 },
394-
{ PIN_D0, doingSomethingStart3, doingSomethingStop3, 250000L, 30, 0, 0, 0, 0 },
395-
{ PIN_D1, doingSomethingStart4, doingSomethingStop4, 200000L, 40, 0, 0, 0, 0 },
396-
{ PIN_D2, doingSomethingStart5, doingSomethingStop5, 166667L, 45, 0, 0, 0, 0 },
397-
{ PIN_D3, doingSomethingStart6, doingSomethingStop6, 142857L, 50, 0, 0, 0, 0 },
398-
{ PIN_D4, doingSomethingStart7, doingSomethingStop7, 125000L, 55, 0, 0, 0, 0 },
399-
{ PIN_D5, doingSomethingStart8, doingSomethingStop8, 111111L, 60, 0, 0, 0, 0 },
400-
{ PIN_D6, doingSomethingStart9, doingSomethingStop9, 100000L, 65, 0, 0, 0, 0 },
401-
{ PIN_D7, doingSomethingStart10, doingSomethingStop10, 66667L, 70, 0, 0, 0, 0 },
402-
{ PIN_D8, doingSomethingStart11, doingSomethingStop11, 50000L, 75, 0, 0, 0, 0 },
403-
{ PIN_D9, doingSomethingStart12, doingSomethingStop12, 40000L, 80, 0, 0, 0, 0 },
404-
{ PIN_D10, doingSomethingStart13, doingSomethingStop13, 33333L, 85, 0, 0, 0, 0 },
405-
{ PIN_D11, doingSomethingStart14, doingSomethingStop14, 25000L, 90, 0, 0, 0, 0 },
406-
{ PIN_D12, doingSomethingStart15, doingSomethingStop15, 20000L, 95, 0, 0, 0, 0 }
391+
{ LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1000000.0, 5.0, 0, 0, 0, 0 },
392+
{ LED_BLUE, doingSomethingStart1, doingSomethingStop1, 500000.0, 10.0, 0, 0, 0, 0 },
393+
{ LED_RED, doingSomethingStart2, doingSomethingStop2, 333333.0, 20.0, 0, 0, 0, 0 },
394+
{ PIN_D0, doingSomethingStart3, doingSomethingStop3, 250000.0, 30.0, 0, 0, 0, 0 },
395+
{ PIN_D1, doingSomethingStart4, doingSomethingStop4, 200000.0, 40.0, 0, 0, 0, 0 },
396+
{ PIN_D2, doingSomethingStart5, doingSomethingStop5, 166667.0, 45.0, 0, 0, 0, 0 },
397+
{ PIN_D3, doingSomethingStart6, doingSomethingStop6, 142857.0, 50.0, 0, 0, 0, 0 },
398+
{ PIN_D4, doingSomethingStart7, doingSomethingStop7, 125000.0, 55.0, 0, 0, 0, 0 },
399+
{ PIN_D5, doingSomethingStart8, doingSomethingStop8, 111111.0, 60.0, 0, 0, 0, 0 },
400+
{ PIN_D6, doingSomethingStart9, doingSomethingStop9, 100000.0, 65.0, 0, 0, 0, 0 },
401+
{ PIN_D7, doingSomethingStart10, doingSomethingStop10, 66667.0, 70.0, 0, 0, 0, 0 },
402+
{ PIN_D8, doingSomethingStart11, doingSomethingStop11, 50000.0, 75.0, 0, 0, 0, 0 },
403+
{ PIN_D9, doingSomethingStart12, doingSomethingStop12, 40000.0, 80.0, 0, 0, 0, 0 },
404+
{ PIN_D10, doingSomethingStart13, doingSomethingStop13, 33333.0, 85.0.0, 0, 0, 0, 0 },
405+
{ PIN_D11, doingSomethingStart14, doingSomethingStop14, 25000.0, 90.0, 0, 0, 0, 0 },
406+
{ PIN_D12, doingSomethingStart15, doingSomethingStop15, 20000.0, 95.0, 0, 0, 0, 0 }
407407
};
408408

409409
#endif // #if USING_PWM_FREQUENCY
@@ -428,15 +428,15 @@ void doingSomethingStop(int index)
428428

429429
#else // #if USE_COMPLEX_STRUCT
430430

431-
irqCallback irqCallbackStartFunc[NUMBER_ISR_PWMS] =
431+
irqCallback irqCallbackStartFunc[] =
432432
{
433433
doingSomethingStart0, doingSomethingStart1, doingSomethingStart2, doingSomethingStart3,
434434
doingSomethingStart4, doingSomethingStart5, doingSomethingStart6, doingSomethingStart7,
435435
doingSomethingStart8, doingSomethingStart9, doingSomethingStart10, doingSomethingStart11,
436436
doingSomethingStart12, doingSomethingStart13, doingSomethingStart14, doingSomethingStart15
437437
};
438438

439-
irqCallback irqCallbackStopFunc[NUMBER_ISR_PWMS] =
439+
irqCallback irqCallbackStopFunc[] =
440440
{
441441
doingSomethingStop0, doingSomethingStop1, doingSomethingStop2, doingSomethingStop3,
442442
doingSomethingStop4, doingSomethingStop5, doingSomethingStop6, doingSomethingStop7,
@@ -471,15 +471,15 @@ void simpleTimerDoingSomething2s()
471471
{
472472
#if USE_COMPLEX_STRUCT
473473
Serial.print(F("PWM Channel : ")); Serial.print(i);
474-
Serial.print(F(", programmed Period (us): "));
474+
Serial.print(F(", programmed Period (uS): "));
475475

476476
#if USING_PWM_FREQUENCY
477-
Serial.print(1000000 / curISR_PWM_Data[i].PWM_Freq);
477+
Serial.print(1000000.0 / curISR_PWM_Data[i].PWM_Freq);
478478
#else
479479
Serial.print(curISR_PWM_Data[i].PWM_Period);
480480
#endif
481481

482-
Serial.print(F(", actual : ")); Serial.print(curISR_PWM_Data[i].deltaMicrosStart);
482+
Serial.print(F(", actual (uS) : ")); Serial.print(curISR_PWM_Data[i].deltaMicrosStart);
483483

484484
Serial.print(F(", programmed DutyCycle : "));
485485

@@ -497,8 +497,8 @@ void simpleTimerDoingSomething2s()
497497
Serial.print(PWM_Period[i]);
498498
#endif
499499

500-
Serial.print(F(", programmed Period (us): ")); Serial.print(PWM_Period[i]);
501-
Serial.print(F(", actual : ")); Serial.print(deltaMicrosStart[i]);
500+
Serial.print(F(", programmed Period (uS): ")); Serial.print(PWM_Period[i]);
501+
Serial.print(F(", actual (uS): ")); Serial.print(deltaMicrosStart[i]);
502502

503503
Serial.print(F(", programmed DutyCycle : "));
504504

examples/ISR_16_PWMs_Array_Simple/ISR_16_PWMs_Array_Simple.ino

+11-12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define MAX_STM32_PWM_FREQ 1000
3030

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

3334
#define LED_OFF LOW
@@ -96,35 +97,33 @@ void TimerHandler()
9697
//////////////////////////////////////////////////////
9798

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

105106
// You can assign any interval for any timer here, in microseconds
106-
uint32_t PWM_Period[NUMBER_ISR_PWMS] =
107+
double PWM_Period[] =
107108
{
108-
1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L,
109-
111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
110-
};
109+
1000000.0, 500000.0, 333333.333, 250000.0, 200000.0, 166666.667, 142857.143, 125000.0,
110+
111111.111, 100000.0, 66666.667, 50000.0, 40000.0, 33333.333, 25000.0, 20000.0};
111111

112112
// You can assign any interval for any timer here, in Hz
113-
double PWM_Freq[NUMBER_ISR_PWMS] =
113+
double PWM_Freq[] =
114114
{
115115
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
116116
9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
117117
};
118118

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

126126

127-
128127
////////////////////////////////////////////////
129128

130129
void setup()

examples/ISR_Changing_PWM/ISR_Changing_PWM.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define MAX_STM32_PWM_FREQ 1000
3030

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

3334
#define LED_OFF LOW
@@ -87,14 +88,14 @@ double PWM_Freq1 = 1.0f;
8788
double PWM_Freq2 = 2.0f;
8889

8990
// You can assign any interval for any timer here, in microseconds
90-
uint32_t PWM_Period1 = 1000000 / PWM_Freq1;
91+
double PWM_Period1 = 1000000.0 / PWM_Freq1;
9192
// You can assign any interval for any timer here, in microseconds
92-
uint32_t PWM_Period2 = 1000000 / PWM_Freq2;
93+
double PWM_Period2 = 1000000.0 / PWM_Freq2;
9394

9495
// You can assign any duty_cycle for any PWM here, from 0-100
95-
uint32_t PWM_DutyCycle1 = 50;
96+
double PWM_DutyCycle1 = 10.0;
9697
// You can assign any duty_cycle for any PWM here, from 0-100
97-
uint32_t PWM_DutyCycle2 = 90;
98+
double PWM_DutyCycle2 = 90.0;
9899

99100
// Channel number used to identify associated channel
100101
int channelNum;

0 commit comments

Comments
 (0)