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

Commit 7b4b1fb

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 b7dcbd4 commit 7b4b1fb

18 files changed

+176
-67
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ void setup()
317317
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
318318
#define _PWM_LOGLEVEL_ 3
319319
320-
#define USING_MICROS_RESOLUTION true //false
320+
#define USING_MICROS_RESOLUTION true //false
321+
322+
// Default is true, uncomment to false
323+
//#define CHANGING_PWM_END_OF_CYCLE false
321324
322325
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
323326
#include "AVR_Slow_PWM.h"
@@ -790,7 +793,7 @@ The following is the sample terminal output when running example [ISR_8_PWMs_Arr
790793

791794
```
792795
Starting ISR_8_PWMs_Array_Complex on Arduino AVR ATMega32U4
793-
AVR_Slow_PWM v1.2.0
796+
AVR_Slow_PWM v1.2.1
794797
CPU Frequency = 16 MHz
795798
[PWM] T3
796799
[PWM] Freq * 1000 = 10000000.00
@@ -835,7 +838,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A
835838

836839
```
837840
Starting ISR_8_PWMs_Array_Complex on Arduino AVR Mega2560/ADK
838-
AVR_Slow_PWM v1.2.0
841+
AVR_Slow_PWM v1.2.1
839842
CPU Frequency = 16 MHz
840843
[PWM] T3
841844
[PWM] Freq * 1000 = 10000000.00
@@ -880,7 +883,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A
880883

881884
```
882885
Starting ISR_8_PWMs_Array_Complex on Arduino AVR UNO, Nano, etc.
883-
AVR_Slow_PWM v1.2.0
886+
AVR_Slow_PWM v1.2.1
884887
CPU Frequency = 16 MHz
885888
[PWM] T1
886889
[PWM] Freq * 1000 = 10000000.00
@@ -926,7 +929,7 @@ The following is the sample terminal output when running example [ISR_Modify_PWM
926929

927930
```
928931
Starting ISR_Modify_PWM on Arduino AVR Mega2560/ADK
929-
AVR_Slow_PWM v1.2.0
932+
AVR_Slow_PWM v1.2.1
930933
CPU Frequency = 16 MHz
931934
[PWM] T3
932935
[PWM] Freq * 1000 = 10000000.00
@@ -950,7 +953,7 @@ The following is the sample terminal output when running example [ISR_Changing_P
950953

951954
```
952955
Starting ISR_Changing_PWM on Arduino AVR Mega2560/ADK
953-
AVR_Slow_PWM v1.2.0
956+
AVR_Slow_PWM v1.2.1
954957
CPU Frequency = 16 MHz
955958
[PWM] T3
956959
[PWM] Freq * 1000 = 10000000.00
@@ -1017,6 +1020,8 @@ Submit issues to: [AVR_Slow_PWM issues](https://github.com/khoih-prog/AVR_Slow_P
10171020
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
10181021
6. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`
10191022
7. Optimize library code by using `reference-passing` instead of `value-passing`
1023+
8. DutyCycle to be optionally updated at the end current PWM period instead of immediately.
1024+
10201025

10211026
---
10221027
---

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_8_PWMs_Array/ISR_8_PWMs_Array.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
3838
#define _PWM_LOGLEVEL_ 3
3939

40-
#define USING_MICROS_RESOLUTION true //false
40+
#define USING_MICROS_RESOLUTION true //false
41+
42+
// Default is true, uncomment to false
43+
//#define CHANGING_PWM_END_OF_CYCLE false
4144

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

examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
3838
#define _PWM_LOGLEVEL_ 3
3939

40-
#define USING_MICROS_RESOLUTION true //false
40+
#define USING_MICROS_RESOLUTION true //false
41+
42+
// Default is true, uncomment to false
43+
//#define CHANGING_PWM_END_OF_CYCLE false
4144

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

examples/ISR_8_PWMs_Array_Simple/ISR_8_PWMs_Array_Simple.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
3838
#define _PWM_LOGLEVEL_ 3
3939

40-
#define USING_MICROS_RESOLUTION true //false
40+
#define USING_MICROS_RESOLUTION true //false
41+
42+
// Default is true, uncomment to false
43+
//#define CHANGING_PWM_END_OF_CYCLE false
4144

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

examples/ISR_Changing_PWM/ISR_Changing_PWM.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
3838
#define _PWM_LOGLEVEL_ 3
3939

40-
#define USING_MICROS_RESOLUTION true //false
40+
#define USING_MICROS_RESOLUTION true //false
41+
42+
// Default is true, uncomment to false
43+
//#define CHANGING_PWM_END_OF_CYCLE false
4144

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

examples/ISR_Modify_PWM/ISR_Modify_PWM.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
3838
#define _PWM_LOGLEVEL_ 3
3939

40-
#define USING_MICROS_RESOLUTION true //false
40+
#define USING_MICROS_RESOLUTION true //false
41+
42+
// Default is true, uncomment to false
43+
//#define CHANGING_PWM_END_OF_CYCLE false
4144

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

examples/multiFileProject/multiFileProject.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
#pragma once
1414

15-
#define USING_MICROS_RESOLUTION true //false
15+
#define USING_MICROS_RESOLUTION true //false
16+
17+
// Default is true, uncomment to false
18+
//#define CHANGING_PWM_END_OF_CYCLE false
1619

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

keywords.txt

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ AVR_Slow_PWM_VERSION_PATCH LITERAL1
5757
AVR_Slow_PWM_VERSION_INT LITERAL1
5858

5959
INVALID_AVR_PIN LITERAL1
60+
61+
USING_MICROS_RESOLUTION LITERAL1
62+
CHANGING_PWM_END_OF_CYCLE LITERAL1

library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "AVR_Slow_PWM",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, precise, non-blocking, avr, mega-2560, nano, uno, leonardo, 32u4, 16u4, at-mega",
55
"description": "This library enables you to use ISR-based PWM channels on AVR-based boards, such as Mega-2560, UNO,Nano, Leonardo, etc., to create and output PWM any GPIO pin. It now supports 16 ISR-based PWM channels, while consuming only 1 Hardware Timer. PWM channel interval can be very long (ulong microsecs / millisecs). The most important feature is they're ISR-based PWM channels, supporting lower PWM frequencies with suitable accuracy. Their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These ISR-based PWMs, still work even if other software functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software-based PWM using millis() or micros(). That's necessary if you need to control devices requiring high precision. 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=AVR_Slow_PWM
2-
version=1.2.0
2+
version=1.2.1
33
author=Khoi Hoang <khoih.prog@gmail.com>
44
maintainer=Khoi Hoang <khoih.prog@gmail.com>
55
sentence=This library enables you to use ISR-based PWM channels on AVR-based boards, such as Mega-2560, UNO,Nano, Leonardo, etc., to create and output PWM any GPIO pin.

src/AVR_Slow_PWM.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.1.0
21+
Version: 1.2.1
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
2525
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
2626
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
27+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
28+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2729
*****************************************************************************************************************************/
2830

2931
#pragma once

src/AVR_Slow_PWM.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.1.0
21+
Version: 1.2.1
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
2525
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
2626
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
27+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
28+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2729
*****************************************************************************************************************************/
2830

2931
#pragma once
@@ -100,13 +102,13 @@
100102
#endif
101103

102104
#ifndef AVR_SLOW_PWM_VERSION
103-
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.0")
105+
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.1")
104106

105107
#define AVR_SLOW_PWM_VERSION_MAJOR 1
106108
#define AVR_SLOW_PWM_VERSION_MINOR 2
107-
#define AVR_SLOW_PWM_VERSION_PATCH 0
109+
#define AVR_SLOW_PWM_VERSION_PATCH 1
108110

109-
#define AVR_SLOW_PWM_VERSION_INT 1002000
111+
#define AVR_SLOW_PWM_VERSION_INT 1002001
110112
#endif
111113

112114
#ifndef _PWM_LOGLEVEL_

src/AVR_Slow_PWM_ISR.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.1.0
21+
Version: 1.2.1
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
2525
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
2626
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
27+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
28+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2729
*****************************************************************************************************************************/
2830

2931
#pragma once

src/AVR_Slow_PWM_ISR.hpp

+20-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.1.0
21+
Version: 1.2.1
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
2525
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
2626
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
27+
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
28+
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
2729
*****************************************************************************************************************************/
2830

2931
#pragma once
@@ -100,13 +102,13 @@
100102
#endif
101103

102104
#ifndef AVR_SLOW_PWM_VERSION
103-
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.0")
105+
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.1")
104106

105107
#define AVR_SLOW_PWM_VERSION_MAJOR 1
106108
#define AVR_SLOW_PWM_VERSION_MINOR 2
107-
#define AVR_SLOW_PWM_VERSION_PATCH 0
109+
#define AVR_SLOW_PWM_VERSION_PATCH 1
108110

109-
#define AVR_SLOW_PWM_VERSION_INT 1002000
111+
#define AVR_SLOW_PWM_VERSION_INT 1002001
110112
#endif
111113

112114
#ifndef _PWM_LOGLEVEL_
@@ -137,6 +139,11 @@ typedef void (*timer_callback_p)(void *);
137139
#define USING_MICROS_RESOLUTION false
138140
#endif
139141

142+
#if !defined(CHANGING_PWM_END_OF_CYCLE)
143+
#warning Using default CHANGING_PWM_END_OF_CYCLE == true
144+
#define CHANGING_PWM_END_OF_CYCLE true
145+
#endif
146+
140147
#define INVALID_AVR_PIN 255
141148

142149
//////////////////////////////////////////////////////////////////
@@ -162,9 +169,9 @@ class AVR_Slow_PWM_ISR
162169
int8_t setPWM(const uint32_t& pin, const double& frequency, const double& dutycycle, timer_callback StartCallback = nullptr,
163170
timer_callback StopCallback = nullptr)
164171
{
165-
double period = 0;
172+
double period = 0.0;
166173

167-
if ( ( frequency != 0 ) && ( frequency <= 1000 ) )
174+
if ( ( frequency > 0.0 ) && ( frequency <= 1000.0 ) )
168175
{
169176
#if USING_MICROS_RESOLUTION
170177
// period in us
@@ -198,9 +205,9 @@ class AVR_Slow_PWM_ISR
198205
// returns the true on success or false on failure
199206
bool modifyPWMChannel(const uint8_t& channelNum, const uint32_t& pin, const double& frequency, const double& dutycycle)
200207
{
201-
double period = 0;
208+
double period = 0.0;
202209

203-
if ( ( frequency > 0 ) && ( frequency <= 1000 ) )
210+
if ( ( frequency > 0.0 ) && ( frequency <= 1000.0 ) )
204211
{
205212
#if USING_MICROS_RESOLUTION
206213
// period in us
@@ -290,6 +297,11 @@ class AVR_Slow_PWM_ISR
290297
////////////////////////////////////////////////////////////
291298

292299
bool enabled; // true if enabled
300+
301+
// New from v1.2.1
302+
double newPeriod; // period value, in us / ms
303+
double newDutyCycle; // from 0.00 to 100.00, double precision
304+
//////
293305
} PWM_t;
294306

295307
volatile PWM_t PWM[MAX_NUMBER_CHANNELS];

0 commit comments

Comments
 (0)