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

Commit 588bc9b

Browse files
authored
v1.1.0 to modify PWM settings on-the-fly
### Releases v1.1.0 1. Add functions to modify PWM settings on-the-fly 2. Add example to demo how to modify PWM settings on-the-fly
1 parent 332cec7 commit 588bc9b

22 files changed

+777
-113
lines changed

README.md

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@
2929
* [1. Init Hardware Timer](#1-init-hardware-timer)
3030
* [2. Set PWM Frequency, dutycycle, attach irqCallbackStartFunc and irqCallbackStopFunc functions](#2-Set-PWM-Frequency-dutycycle-attach-irqCallbackStartFunc-and-irqCallbackStopFunc-functions)
3131
* [Examples](#examples)
32-
* [ 1. ISR_8_PWMs_Array](examples/ISR_8_PWMs_Array)
33-
* [ 2. ISR_8_PWMs_Array_Complex](examples/ISR_8_PWMs_Array_Complex)
34-
* [ 3. ISR_8_PWMs_Array_Simple](examples/ISR_8_PWMs_Array_Simple)
32+
* [ 1. ISR_8_PWMs_Array](examples/ISR_8_PWMs_Array)
33+
* [ 2. ISR_8_PWMs_Array_Complex](examples/ISR_8_PWMs_Array_Complex)
34+
* [ 3. ISR_8_PWMs_Array_Simple](examples/ISR_8_PWMs_Array_Simple)
35+
* [ 4. ISR_Changing_PWM](examples/ISR_Changing_PWM)
36+
* [ 5. ISR_Modify_PWM](examples/ISR_Modify_PWM)
3537
* [Example ISR_8_PWMs_Array_Complex](#Example-ISR_8_PWMs_Array_Complex)
3638
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
3739
* [1. ISR_8_PWMs_Array_Complex on Teensy 4.1](#1-ISR_8_PWMs_Array_Complex-on-Teensy-41)
3840
* [2. ISR_8_PWMs_Array on Teensy 4.1](#2-isr_8_pwms_array-on-Teensy-41)
3941
* [3. ISR_8_PWMs_Array_Simple on Teensy 4.1](#3-ISR_8_PWMs_Array_Simple-on-Teensy-41)
42+
* [4. ISR_Modify_PWM on Teensy 4.1](#4-ISR_Modify_PWM-on-Teensy-41)
43+
* [5. ISR_Changing_PWM on Teensy 4.1](#5-ISR_Changing_PWM-on-Teensy-41)
4044
* [Debug](#debug)
4145
* [Troubleshooting](#troubleshooting)
4246
* [Issues](#issues)
@@ -54,7 +58,7 @@
5458

5559
### Features
5660

57-
This library enables you to use ISR-based PWM channels on **Teensy boards, such as Teensy 2.x, Teensy LC, Teensy 3.x, Teensy 4.x, Teensy MicroMod, etc.**, etc. using [Teensyduno core](https://www.pjrc.com/teensy/td_download.html) to create and output PWM any GPIO pin. Because this library doesn't use the powerful purely hardware-controlled PWM with many limitations, the maximum PWM frequency is currently limited at **500Hz**, which is still suitable for many real-life applications.
61+
This library enables you to use ISR-based PWM channels on **Teensy boards, such as Teensy 2.x, Teensy LC, Teensy 3.x, Teensy 4.x, Teensy MicroMod, etc.**, etc. using [Teensyduno core](https://www.pjrc.com/teensy/td_download.html) to create and output PWM any GPIO pin. Because this library doesn't use the powerful purely hardware-controlled PWM with many limitations, the maximum PWM frequency is currently limited at **500Hz**, which is still suitable for many real-life applications. Now you can change the PWM settings on-the-fly
5862

5963
---
6064

@@ -262,7 +266,9 @@ void setup()
262266

263267
1. [ISR_8_PWMs_Array](examples/ISR_8_PWMs_Array)
264268
2. [ISR_8_PWMs_Array_Complex](examples/ISR_8_PWMs_Array_Complex)
265-
3. [ISR_8_PWMs_Array_Simple](examples/ISR_8_PWMs_Array_Simple)
269+
3. [ISR_8_PWMs_Array_Simple](examples/ISR_8_PWMs_Array_Simple)
270+
4. [ISR_Changing_PWM](examples/ISR_Changing_PWM)
271+
5. [ISR_Modify_PWM](examples/ISR_Modify_PWM)
266272

267273

268274
---
@@ -405,11 +411,10 @@ uint32_t PWM_Period[NUMBER_ISR_PWMS] =
405411
1000L, 500L, 333L, 250L, 200L, 166L, 142L, 125L
406412
};
407413
408-
409414
// You can assign any interval for any timer here, in Hz
410-
uint32_t PWM_Freq[NUMBER_ISR_PWMS] =
415+
double PWM_Freq[NUMBER_ISR_PWMS] =
411416
{
412-
1, 2, 3, 4, 5, 6, 7, 8
417+
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
413418
};
414419
415420
// You can assign any interval for any timer here, in Microseconds
@@ -734,7 +739,7 @@ The following is the sample terminal output when running example [ISR_8_PWMs_Arr
734739

735740
```
736741
Starting ISR_8_PWMs_Array_Complex on Teensy 4.1
737-
Teensy_Slow_PWM v1.0.0
742+
Teensy_Slow_PWM v1.1.0
738743
CPU Frequency = 600 MHz
739744
[PWM] TEENSY_TIMER_1: , F_BUS_ACTUAL (MHz) = 150
740745
[PWM] Request interval = 20 , actual interval (us) = 20
@@ -785,7 +790,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A
785790

786791
```
787792
Starting ISR_8_PWMs_Array on Teensy 4.1
788-
Teensy_Slow_PWM v1.0.0
793+
Teensy_Slow_PWM v1.1.0
789794
CPU Frequency = 600 MHz
790795
[PWM] TEENSY_TIMER_1: , F_BUS_ACTUAL (MHz) = 150
791796
[PWM] Request interval = 33 , actual interval (us) = 33
@@ -809,7 +814,7 @@ The following is the sample terminal output when running example [**ISR_8_PWMs_A
809814

810815
```
811816
Starting ISR_8_PWMs_Array_Simple on Teensy 4.1
812-
Teensy_Slow_PWM v1.0.0
817+
Teensy_Slow_PWM v1.1.0
813818
CPU Frequency = 600 MHz
814819
[PWM] TEENSY_TIMER_1: , F_BUS_ACTUAL (MHz) = 150
815820
[PWM] Request interval = 33 , actual interval (us) = 33
@@ -825,6 +830,51 @@ Channel : 6 Period : 142857 OnTime : 57142 Start_Time : 3906007
825830
Channel : 7 Period : 125000 OnTime : 56250 Start_Time : 3906007
826831
```
827832

833+
---
834+
835+
### 4. ISR_Modify_PWM on Teensy 4.1
836+
837+
The following is the sample terminal output when running example [ISR_Modify_PWM](examples/ISR_Modify_PWM) on **Teensy 4.1** to demonstrate how to modify PWM settings on-the-fly without deleting the PWM channel
838+
839+
```
840+
Starting ISR_Modify_PWM on Teensy 4.1
841+
Teensy_Slow_PWM v1.1.0
842+
CPU Frequency = 600 MHz
843+
[PWM] TEENSY_TIMER_1: , F_BUS_ACTUAL (MHz) = 150
844+
[PWM] Request interval = 33 , actual interval (us) = 33
845+
[PWM] Prescale = 0 , _timerCount = 2475
846+
Starting ITimer OK, micros() = 2826009
847+
Using PWM Freq = 1.00, PWM DutyCycle = 10
848+
Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 2826012
849+
Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 12827000
850+
Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 22828000
851+
Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 32829000
852+
```
853+
854+
---
855+
856+
### 5. ISR_Changing_PWM on Teensy 4.1
857+
858+
The following is the sample terminal output when running example [ISR_Changing_PWM](examples/ISR_Changing_PWM) on **Teensy 4.1** to demonstrate how to modify PWM settings on-the-fly by deleting the PWM channel and reinit the PWM channel
859+
860+
```
861+
Starting ISR_Changing_PWM on Teensy 4.1
862+
Teensy_Slow_PWM v1.1.0
863+
CPU Frequency = 600 MHz
864+
[PWM] TEENSY_TIMER_1: , F_BUS_ACTUAL (MHz) = 150
865+
[PWM] Request interval = 33 , actual interval (us) = 33
866+
[PWM] Prescale = 0 , _timerCount = 2475
867+
Starting ITimer OK, micros() = 2892009
868+
Using PWM Freq = 1.00, PWM DutyCycle = 50
869+
Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 2892013
870+
Using PWM Freq = 2.00, PWM DutyCycle = 90
871+
Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 12892018
872+
Using PWM Freq = 1.00, PWM DutyCycle = 50
873+
Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 22892023
874+
Using PWM Freq = 2.00, PWM DutyCycle = 90
875+
Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 32892029
876+
```
877+
828878

829879
---
830880
---
@@ -869,6 +919,7 @@ Submit issues to: [Teensy_Slow_PWM issues](https://github.com/khoih-prog/Teensy_
869919

870920
1. Basic hardware multi-channel PWM for **Teensy boards, such as Teensy 2.x, Teensy LC, Teensy 3.x, Teensy 4.x, Teensy MicroMod, etc.**, etc. using [Teensyduno core](https://www.pjrc.com/teensy/td_download.html)
871921
2. Add Table of Contents
922+
3. Add functions to modify PWM settings on-the-fly
872923

873924
---
874925
---

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
## Table of Contents
1313

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

1718
---
1819
---
1920

2021
## Changelog
2122

23+
### Releases v1.1.0
24+
25+
1. Add functions to modify PWM settings on-the-fly
26+
2. Add example to demo how to modify PWM settings on-the-fly
27+
2228
### Initial Releases v1.0.0
2329

2430
1. Initial coding to support **Teensy boards, such as Teensy 2.x, Teensy LC, Teensy 3.x, Teensy 4.x, Teensy MicroMod, etc.**, using [Teensyduno core](https://www.pjrc.com/teensy/td_download.html)

examples/ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
14-
15-
Version: 1.0.0
16-
17-
Version Modified By Date Comments
18-
------- ----------- ---------- -----------
19-
1.0.0 K.Hoang 28/09/2021 Initial coding for Teensy 2.x, Teensy LC, Teensy 3.x, Teensy 4.x, etc.
2014
*****************************************************************************************************************************/
2115

2216
#if !( defined(CORE_TEENSY) || defined(TEENSYDUINO) )
@@ -104,11 +98,10 @@ uint32_t PWM_Pin[] =
10498

10599
#define NUMBER_ISR_PWMS ( sizeof(PWM_Pin) / sizeof(uint32_t) )
106100

107-
108101
// You can assign any interval for any timer here, in Hz
109-
uint32_t PWM_Freq[NUMBER_ISR_PWMS] =
102+
double PWM_Freq[NUMBER_ISR_PWMS] =
110103
{
111-
1, 2, 3, 4, 5, 6, 7, 8
104+
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
112105
};
113106

114107
// You can assign any interval for any timer here, in Microseconds

examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
14-
15-
Version: 1.0.0
16-
17-
Version Modified By Date Comments
18-
------- ----------- ---------- -----------
19-
1.0.0 K.Hoang 28/09/2021 Initial coding for Teensy 2.x, Teensy LC, Teensy 3.x, Teensy 4.x, etc.
2014
*****************************************************************************************************************************/
2115

2216
#if !( defined(CORE_TEENSY) || defined(TEENSYDUINO) )
@@ -153,11 +147,10 @@ uint32_t PWM_Period[NUMBER_ISR_PWMS] =
153147
1000L, 500L, 333L, 250L, 200L, 166L, 142L, 125L
154148
};
155149

156-
157150
// You can assign any interval for any timer here, in Hz
158-
uint32_t PWM_Freq[NUMBER_ISR_PWMS] =
151+
double PWM_Freq[NUMBER_ISR_PWMS] =
159152
{
160-
1, 2, 3, 4, 5, 6, 7, 8
153+
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
161154
};
162155

163156
// You can assign any interval for any timer here, in Microseconds

examples/ISR_8_PWMs_Array_Simple/ISR_8_PWMs_Array_Simple.ino

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
14-
15-
Version: 1.0.0
16-
17-
Version Modified By Date Comments
18-
------- ----------- ---------- -----------
19-
1.0.0 K.Hoang 28/09/2021 Initial coding for Teensy 2.x, Teensy LC, Teensy 3.x, Teensy 4.x, etc.
2014
*****************************************************************************************************************************/
2115

2216
#if !( defined(CORE_TEENSY) || defined(TEENSYDUINO) )
@@ -104,11 +98,10 @@ uint32_t PWM_Pin[] =
10498

10599
#define NUMBER_ISR_PWMS ( sizeof(PWM_Pin) / sizeof(uint32_t) )
106100

107-
108101
// You can assign any interval for any timer here, in Hz
109-
uint32_t PWM_Freq[NUMBER_ISR_PWMS] =
102+
double PWM_Freq[NUMBER_ISR_PWMS] =
110103
{
111-
1, 2, 3, 4, 5, 6, 7, 8
104+
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
112105
};
113106

114107
// You can assign any interval for any timer here, in Microseconds

0 commit comments

Comments
 (0)