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

Commit

Permalink
1.2.1 to to not update DutyCycle immediately
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
khoih-prog authored Jan 30, 2022
1 parent b7dcbd4 commit 7b4b1fb
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 67 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ void setup()
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 3
#define USING_MICROS_RESOLUTION true //false
#define USING_MICROS_RESOLUTION true //false
// Default is true, uncomment to false
//#define CHANGING_PWM_END_OF_CYCLE false
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AVR_Slow_PWM.h"
Expand Down Expand Up @@ -790,7 +793,7 @@ The following is the sample terminal output when running example [ISR_8_PWMs_Arr

```
Starting ISR_8_PWMs_Array_Complex on Arduino AVR ATMega32U4
AVR_Slow_PWM v1.2.0
AVR_Slow_PWM v1.2.1
CPU Frequency = 16 MHz
[PWM] T3
[PWM] Freq * 1000 = 10000000.00
Expand Down Expand Up @@ -835,7 +838,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A

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

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

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

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


---
---
Expand Down
5 changes: 5 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.1](#releases-v121)
* [Releases v1.2.0](#releases-v120)
* [Releases v1.1.0](#releases-v110)
* [Initial Releases v1.0.0](#Initial-Releases-v100)
Expand All @@ -21,6 +22,10 @@

## Changelog

### 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](https://github.com/khoih-prog/ESP8266_PWM/issues/2)

### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
Expand Down
5 changes: 4 additions & 1 deletion examples/ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 3

#define USING_MICROS_RESOLUTION true //false
#define USING_MICROS_RESOLUTION true //false

// Default is true, uncomment to false
//#define CHANGING_PWM_END_OF_CYCLE false

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AVR_Slow_PWM.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 3

#define USING_MICROS_RESOLUTION true //false
#define USING_MICROS_RESOLUTION true //false

// Default is true, uncomment to false
//#define CHANGING_PWM_END_OF_CYCLE false

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AVR_Slow_PWM.h"
Expand Down
5 changes: 4 additions & 1 deletion examples/ISR_8_PWMs_Array_Simple/ISR_8_PWMs_Array_Simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 3

#define USING_MICROS_RESOLUTION true //false
#define USING_MICROS_RESOLUTION true //false

// Default is true, uncomment to false
//#define CHANGING_PWM_END_OF_CYCLE false

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AVR_Slow_PWM.h"
Expand Down
5 changes: 4 additions & 1 deletion examples/ISR_Changing_PWM/ISR_Changing_PWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 3

#define USING_MICROS_RESOLUTION true //false
#define USING_MICROS_RESOLUTION true //false

// Default is true, uncomment to false
//#define CHANGING_PWM_END_OF_CYCLE false

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AVR_Slow_PWM.h"
Expand Down
5 changes: 4 additions & 1 deletion examples/ISR_Modify_PWM/ISR_Modify_PWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 3

#define USING_MICROS_RESOLUTION true //false
#define USING_MICROS_RESOLUTION true //false

// Default is true, uncomment to false
//#define CHANGING_PWM_END_OF_CYCLE false

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AVR_Slow_PWM.h"
Expand Down
5 changes: 4 additions & 1 deletion examples/multiFileProject/multiFileProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

#pragma once

#define USING_MICROS_RESOLUTION true //false
#define USING_MICROS_RESOLUTION true //false

// Default is true, uncomment to false
//#define CHANGING_PWM_END_OF_CYCLE false

// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "AVR_Slow_PWM.hpp"
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ AVR_Slow_PWM_VERSION_PATCH LITERAL1
AVR_Slow_PWM_VERSION_INT LITERAL1

INVALID_AVR_PIN LITERAL1

USING_MICROS_RESOLUTION LITERAL1
CHANGING_PWM_END_OF_CYCLE LITERAL1
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AVR_Slow_PWM",
"version": "1.2.0",
"version": "1.2.1",
"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",
"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",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AVR_Slow_PWM
version=1.2.0
version=1.2.1
author=Khoi Hoang <[email protected]>
maintainer=Khoi Hoang <[email protected]>
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.
Expand Down
4 changes: 3 additions & 1 deletion src/AVR_Slow_PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
*****************************************************************************************************************************/

#pragma once
Expand Down
10 changes: 6 additions & 4 deletions src/AVR_Slow_PWM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
*****************************************************************************************************************************/

#pragma once
Expand Down Expand Up @@ -100,13 +102,13 @@
#endif

#ifndef AVR_SLOW_PWM_VERSION
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.0")
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.1")

#define AVR_SLOW_PWM_VERSION_MAJOR 1
#define AVR_SLOW_PWM_VERSION_MINOR 2
#define AVR_SLOW_PWM_VERSION_PATCH 0
#define AVR_SLOW_PWM_VERSION_PATCH 1

#define AVR_SLOW_PWM_VERSION_INT 1002000
#define AVR_SLOW_PWM_VERSION_INT 1002001
#endif

#ifndef _PWM_LOGLEVEL_
Expand Down
4 changes: 3 additions & 1 deletion src/AVR_Slow_PWM_ISR.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
*****************************************************************************************************************************/

#pragma once
Expand Down
28 changes: 20 additions & 8 deletions src/AVR_Slow_PWM_ISR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Version: 1.1.0
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K.Hoang 27/09/2021 Initial coding for AVR-based boards (UNO, Nano, Mega, 32U4, 16U4, etc. )
1.1.0 K Hoang 10/11/2021 Add functions to modify PWM settings on-the-fly
1.2.0 K Hoang 29/01/2022 Fix multiple-definitions linker error. Improve accuracy
1.2.1 K Hoang 30/01/2022 DutyCycle to be updated at the end current PWM period
*****************************************************************************************************************************/

#pragma once
Expand Down Expand Up @@ -100,13 +102,13 @@
#endif

#ifndef AVR_SLOW_PWM_VERSION
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.0")
#define AVR_SLOW_PWM_VERSION F("AVR_Slow_PWM v1.2.1")

#define AVR_SLOW_PWM_VERSION_MAJOR 1
#define AVR_SLOW_PWM_VERSION_MINOR 2
#define AVR_SLOW_PWM_VERSION_PATCH 0
#define AVR_SLOW_PWM_VERSION_PATCH 1

#define AVR_SLOW_PWM_VERSION_INT 1002000
#define AVR_SLOW_PWM_VERSION_INT 1002001
#endif

#ifndef _PWM_LOGLEVEL_
Expand Down Expand Up @@ -137,6 +139,11 @@ typedef void (*timer_callback_p)(void *);
#define USING_MICROS_RESOLUTION false
#endif

#if !defined(CHANGING_PWM_END_OF_CYCLE)
#warning Using default CHANGING_PWM_END_OF_CYCLE == true
#define CHANGING_PWM_END_OF_CYCLE true
#endif

#define INVALID_AVR_PIN 255

//////////////////////////////////////////////////////////////////
Expand All @@ -162,9 +169,9 @@ class AVR_Slow_PWM_ISR
int8_t setPWM(const uint32_t& pin, const double& frequency, const double& dutycycle, timer_callback StartCallback = nullptr,
timer_callback StopCallback = nullptr)
{
double period = 0;
double period = 0.0;

if ( ( frequency != 0 ) && ( frequency <= 1000 ) )
if ( ( frequency > 0.0 ) && ( frequency <= 1000.0 ) )
{
#if USING_MICROS_RESOLUTION
// period in us
Expand Down Expand Up @@ -198,9 +205,9 @@ class AVR_Slow_PWM_ISR
// returns the true on success or false on failure
bool modifyPWMChannel(const uint8_t& channelNum, const uint32_t& pin, const double& frequency, const double& dutycycle)
{
double period = 0;
double period = 0.0;

if ( ( frequency > 0 ) && ( frequency <= 1000 ) )
if ( ( frequency > 0.0 ) && ( frequency <= 1000.0 ) )
{
#if USING_MICROS_RESOLUTION
// period in us
Expand Down Expand Up @@ -290,6 +297,11 @@ class AVR_Slow_PWM_ISR
////////////////////////////////////////////////////////////

bool enabled; // true if enabled

// New from v1.2.1
double newPeriod; // period value, in us / ms
double newDutyCycle; // from 0.00 to 100.00, double precision
//////
} PWM_t;

volatile PWM_t PWM[MAX_NUMBER_CHANNELS];
Expand Down
Loading

0 comments on commit 7b4b1fb

Please sign in to comment.