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

Commit 7698bc4

Browse files
authored
1.2.1 to to not update DutyCycle immediately
### Releases v1.2.1 1. 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)
1 parent 655e979 commit 7698bc4

17 files changed

+111
-32
lines changed

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ void setup()
408408
#define _PWM_LOGLEVEL_ 4
409409
410410
#define USING_MICROS_RESOLUTION true //false
411+
412+
// Default is true, uncomment to false
413+
//#define CHANGING_PWM_END_OF_CYCLE false
411414
412415
#define MAX_STM32_PWM_FREQ 1000
413416
@@ -982,7 +985,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar
982985

983986
```
984987
Starting ISR_16_PWMs_Array_Complex on NUCLEO_H743ZI2
985-
STM32_SLOW_PWM v1.2.0
988+
STM32_SLOW_PWM v1.2.1
986989
[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 240000000
987990
[PWM] Frequency = 1000000.00 , _count = 20
988991
Starting ITimer OK, micros() = 2015843
@@ -1047,7 +1050,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar
10471050

10481051
```
10491052
Starting ISR_16_PWMs_Array_Complex on NUCLEO_F767ZI
1050-
STM32_SLOW_PWM v1.2.0
1053+
STM32_SLOW_PWM v1.2.1
10511054
[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00
10521055
[PWM] Timer Frequency = 50000.00 , _count = 20
10531056
Starting ITimer OK, micros() = 2016553
@@ -1112,7 +1115,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar
11121115

11131116
```
11141117
Starting ISR_16_PWMs_Array_Complex on NUCLEO_L552ZE_Q
1115-
STM32_SLOW_PWM v1.1.0
1118+
STM32_SLOW_PWM v1.2.1
11161119
[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 110000000
11171120
[PWM] Frequency = 1000000.00 , _count = 20
11181121
Starting ITimer OK, micros() = 2016141
@@ -1177,7 +1180,7 @@ The following is the sample terminal output when running example [ISR_16_PWMs_Ar
11771180

11781181
```
11791182
Starting ISR_16_PWMs_Array_Complex on BLUEPILL_F103CB
1180-
STM32_SLOW_PWM v1.1.0
1183+
STM32_SLOW_PWM v1.2.1
11811184
[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 72000000
11821185
[PWM] Frequency = 1000000.00 , _count = 20
11831186
Starting ITimer OK, micros() = 3390333
@@ -1241,7 +1244,7 @@ The following is the sample terminal output when running example [ISR_Modify_PWM
12411244

12421245
```
12431246
Starting ISR_Modify_PWM on NUCLEO_F767ZI
1244-
STM32_SLOW_PWM v1.2.0
1247+
STM32_SLOW_PWM v1.2.1
12451248
[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00
12461249
[PWM] Timer Frequency = 50000.00 , _count = 20
12471250
Starting ITimer OK, micros() = 2016545
@@ -1264,7 +1267,7 @@ The following is the sample terminal output when running example [ISR_Changing_P
12641267

12651268
```
12661269
Starting ISR_Changing_PWM on NUCLEO_F767ZI
1267-
STM32_SLOW_PWM v1.2.0
1270+
STM32_SLOW_PWM v1.2.1
12681271
[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00
12691272
[PWM] Timer Frequency = 50000.00 , _count = 20
12701273
Starting ITimer OK, micros() = 2016547
@@ -1334,7 +1337,7 @@ Submit issues to: [STM32_Slow_PWM issues](https://github.com/khoih-prog/STM32_Sl
13341337
6. 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)
13351338
7. Optimize library code by using `reference-passing` instead of `value-passing`
13361339
8. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](https://github.com/khoih-prog/ESP8266TimerInterrupt/pull/19)
1337-
1340+
9. DutyCycle to be optionally updated at the end current PWM period instead of immediately
13381341

13391342
---
13401343
---

changelog.md

+5
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
* [Initial Releases v1.0.0](#Initial-Releases-v100)
@@ -21,6 +22,10 @@
2122

2223
## Changelog
2324

25+
### Releases v1.2.1
26+
27+
1. 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)
28+
2429
### Releases v1.2.0
2530

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

examples/ISR_16_PWMs_Array/ISR_16_PWMs_Array.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
2525
#define _PWM_LOGLEVEL_ 4
2626

27-
#define USING_MICROS_RESOLUTION true //false
27+
#define USING_MICROS_RESOLUTION true //false
28+
29+
// Default is true, uncomment to false
30+
//#define CHANGING_PWM_END_OF_CYCLE false
2831

2932
#define MAX_STM32_PWM_FREQ 1000
3033

examples/ISR_16_PWMs_Array_Complex/ISR_16_PWMs_Array_Complex.ino

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#define _PWM_LOGLEVEL_ 4
2626

2727
#define USING_MICROS_RESOLUTION true //false
28+
29+
// Default is true, uncomment to false
30+
//#define CHANGING_PWM_END_OF_CYCLE false
2831

2932
#define MAX_STM32_PWM_FREQ 1000
3033

examples/ISR_16_PWMs_Array_Simple/ISR_16_PWMs_Array_Simple.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
2525
#define _PWM_LOGLEVEL_ 4
2626

27-
#define USING_MICROS_RESOLUTION true //false
27+
#define USING_MICROS_RESOLUTION true //false
28+
29+
// Default is true, uncomment to false
30+
//#define CHANGING_PWM_END_OF_CYCLE false
2831

2932
#define MAX_STM32_PWM_FREQ 1000
3033

examples/ISR_Changing_PWM/ISR_Changing_PWM.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
2525
#define _PWM_LOGLEVEL_ 4
2626

27-
#define USING_MICROS_RESOLUTION true //false
27+
#define USING_MICROS_RESOLUTION true //false
28+
29+
// Default is true, uncomment to false
30+
//#define CHANGING_PWM_END_OF_CYCLE false
2831

2932
#define MAX_STM32_PWM_FREQ 1000
3033

examples/ISR_Modify_PWM/ISR_Modify_PWM.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
2525
#define _PWM_LOGLEVEL_ 4
2626

27-
#define USING_MICROS_RESOLUTION true //false
27+
#define USING_MICROS_RESOLUTION true //false
28+
29+
// Default is true, uncomment to false
30+
//#define CHANGING_PWM_END_OF_CYCLE false
2831

2932
#define MAX_STM32_PWM_FREQ 1000
3033

examples/multiFileProject/multiFileProject.h

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414

1515
#define USING_MICROS_RESOLUTION true //false
1616

17+
// Default is true, uncomment to false
18+
//#define CHANGING_PWM_END_OF_CYCLE false
19+
1720
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
1821
#include "STM32_Slow_PWM.hpp"

keywords.txt

+3
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ STM32_SLOW_PWM_VERSION_INT LITERAL1
5959

6060
INVALID_STM32_PIN LITERAL1
6161

62+
USING_MICROS_RESOLUTION LITERAL1
63+
CHANGING_PWM_END_OF_CYCLE LITERAL1
64+

library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "STM32_Slow_PWM",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"keywords": "timing, device, control, timer, pwm, interrupt, isr, isr-based, hardware-timer, mission-critical, accuracy, non-blocking, stm32, stm32h7, stm32l5, stm32f1, stm32f4, stm32f7, stm32g4, precise, hardware",
55
"description": "This library enables you to use Hardware Timers on STM32F/L/H/G/WB/MP1 boards to create and output PWM to pins. The most important feature is they're purely hardware-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 timers, 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. PWM feature can now be used. Max PWM frequency is limited at 1000Hz. Now you can change the PWM settings on-the-fly",
66
"authors":

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32_Slow_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=This library enables you to use Hardware Timers on STM32F/L/H/G/WB/MP1 boards to create and output PWM to pins.

src/PWM_Generic_Debug.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.2.0
15+
Version: 1.2.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 22/09/2021 Initial coding for STM32F/L/H/G/WB/MP1
2020
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
2121
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
22+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2223
*****************************************************************************************************************************/
2324

2425
#pragma once

src/STM32_Slow_PWM.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.2.0
15+
Version: 1.2.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 22/09/2021 Initial coding for STM32F/L/H/G/WB/MP1
2020
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
2121
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
22+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2223
*****************************************************************************************************************************/
2324

2425
#pragma once

src/STM32_Slow_PWM.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.2.0
15+
Version: 1.2.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 22/09/2021 Initial coding for STM32F/L/H/G/WB/MP1
2020
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
2121
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
22+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2223
*****************************************************************************************************************************/
2324

2425
#pragma once
@@ -41,13 +42,13 @@
4142
#endif
4243

4344
#ifndef STM32_SLOW_PWM_VERSION
44-
#define STM32_SLOW_PWM_VERSION "STM32_SLOW_PWM v1.2.0"
45+
#define STM32_SLOW_PWM_VERSION "STM32_SLOW_PWM v1.2.1"
4546

4647
#define STM32_SLOW_PWM_VERSION_MAJOR 1
4748
#define STM32_SLOW_PWM_VERSION_MINOR 2
48-
#define STM32_SLOW_PWM_VERSION_PATCH 0
49+
#define STM32_SLOW_PWM_VERSION_PATCH 1
4950

50-
#define STM32_SLOW_PWM_VERSION_INT 1002000
51+
#define STM32_SLOW_PWM_VERSION_INT 1002001
5152
#endif
5253

5354
///////////////////////////////////////////

src/STM32_Slow_PWM_ISR.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.2.0
15+
Version: 1.2.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 22/09/2021 Initial coding for STM32F/L/H/G/WB/MP1
2020
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
2121
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
22+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2223
*****************************************************************************************************************************/
2324

2425
#pragma once

src/STM32_Slow_PWM_ISR.hpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.2.0
15+
Version: 1.2.1
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 22/09/2021 Initial coding for STM32F/L/H/G/WB/MP1
2020
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
2121
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
22+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2223
*****************************************************************************************************************************/
2324

2425
#pragma once
@@ -41,13 +42,13 @@
4142
#endif
4243

4344
#ifndef STM32_SLOW_PWM_VERSION
44-
#define STM32_SLOW_PWM_VERSION "STM32_SLOW_PWM v1.2.0"
45+
#define STM32_SLOW_PWM_VERSION "STM32_SLOW_PWM v1.2.1"
4546

4647
#define STM32_SLOW_PWM_VERSION_MAJOR 1
4748
#define STM32_SLOW_PWM_VERSION_MINOR 2
48-
#define STM32_SLOW_PWM_VERSION_PATCH 0
49+
#define STM32_SLOW_PWM_VERSION_PATCH 1
4950

50-
#define STM32_SLOW_PWM_VERSION_INT 1002000
51+
#define STM32_SLOW_PWM_VERSION_INT 1002001
5152
#endif
5253

5354
#ifndef _PWM_LOGLEVEL_
@@ -70,6 +71,11 @@ typedef void (*timer_callback_p)(void *);
7071
#define USING_MICROS_RESOLUTION false
7172
#endif
7273

74+
#if !defined(CHANGING_PWM_END_OF_CYCLE)
75+
#warning Using default CHANGING_PWM_END_OF_CYCLE == true
76+
#define CHANGING_PWM_END_OF_CYCLE true
77+
#endif
78+
7379
#define INVALID_STM32_PIN 255
7480

7581

@@ -225,6 +231,11 @@ class STM32_SLOW_PWM_ISR
225231
////////////////////////////////////////////////////////////
226232

227233
bool enabled; // true if enabled
234+
235+
// New from v1.2.1
236+
double newPeriod; // period value, in us / ms
237+
double newDutyCycle; // from 0.00 to 100.00, double precision
238+
//////
228239
} PWM_t;
229240

230241
volatile PWM_t PWM[MAX_NUMBER_CHANNELS];

0 commit comments

Comments
 (0)