|
28 | 28 | * [1. Init Hardware Timer](#1-init-hardware-timer)
|
29 | 29 | * [2. Set PWM Frequency, dutycycle, attach irqCallbackStartFunc and irqCallbackStopFunc functions](#2-Set-PWM-Frequency-dutycycle-attach-irqCallbackStartFunc-and-irqCallbackStopFunc-functions)
|
30 | 30 | * [Examples](#examples)
|
31 |
| - * [ 1. ISR_16_PWMs_Array](examples/ISR_16_PWMs_Array) |
32 |
| - * [ 2. ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) |
33 |
| - * [ 3. ISR_16_PWMs_Array_Simple](examples/ISR_16_PWMs_Array_Simple) |
| 31 | + * [ 1. ISR_16_PWMs_Array](examples/ISR_16_PWMs_Array) |
| 32 | + * [ 2. ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) |
| 33 | + * [ 3. ISR_16_PWMs_Array_Simple](examples/ISR_16_PWMs_Array_Simple) |
| 34 | + * [ 4. ISR_Changing_PWM](examples/ISR_Changing_PWM) |
| 35 | + * [ 5. ISR_Modify_PWM](examples/ISR_Modify_PWM) |
34 | 36 | * [Example ISR_16_PWMs_Array_Complex](#Example-ISR_16_PWMs_Array_Complex)
|
35 | 37 | * [Debug Terminal Output Samples](#debug-terminal-output-samples)
|
36 | 38 | * [1. ISR_16_PWMs_Array_Complex on NUCLEO_H743ZI2](#1-ISR_16_PWMs_Array_Complex-on-NUCLEO_H743ZI2)
|
37 | 39 | * [2. ISR_16_PWMs_Array_Complex on NUCLEO_F767ZI](#2-ISR_16_PWMs_Array_Complex-on-NUCLEO_F767ZI)
|
38 | 40 | * [3. ISR_16_PWMs_Array_Complex on NUCLEO_L552ZE_Q](#3-ISR_16_PWMs_Array_Complex-on-NUCLEO_L552ZE_Q)
|
39 | 41 | * [4. ISR_16_PWMs_Array_Complex on BLUEPILL_F103CB](#4-ISR_16_PWMs_Array_Complex-on-BLUEPILL_F103CB)
|
| 42 | + * [5. ISR_Modify_PWM on NUCLEO_F767ZI](#5-ISR_Modify_PWM-on-NUCLEO_F767ZI) |
| 43 | + * [6. ISR_Changing_PWM on NUCLEO_F767ZI](#6-ISR_Changing_PWM-on-NUCLEO_F767ZI) |
40 | 44 | * [Debug](#debug)
|
41 | 45 | * [Troubleshooting](#troubleshooting)
|
42 | 46 | * [Issues](#issues)
|
|
54 | 58 |
|
55 | 59 | ### Features
|
56 | 60 |
|
57 |
| -This library enables you to use Hardware Timers on **STM32F/L/H/G/WB/MP1 boards** such as NUCLEO_H743ZI2, NUCLEO_L552ZE_Q, NUCLEO_F767ZI, BLUEPILL_F103CB, etc., to create and output PWM to pins. Because this library doesn't use the powerful hardware-controlled PWM with limitations, the maximum PWM frequency is currently limited at **1000Hz**, which is suitable for many real-life applications. |
| 61 | +This library enables you to use Hardware Timers on **STM32F/L/H/G/WB/MP1 boards** such as NUCLEO_H743ZI2, NUCLEO_L552ZE_Q, NUCLEO_F767ZI, BLUEPILL_F103CB, etc., to create and output PWM to pins. Because this library doesn't use the powerful hardware-controlled PWM with limitations, the maximum PWM frequency is currently limited at **1000Hz**, which is suitable for many real-life applications. Now you can also modify PWM settings on-the-fly. |
58 | 62 |
|
59 | 63 | ---
|
60 | 64 |
|
@@ -115,7 +119,7 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
|
115 | 119 | ## Prerequisites
|
116 | 120 |
|
117 | 121 | 1. [`Arduino IDE 1.8.16+` for Arduino](https://www.arduino.cc/en/Main/Software)
|
118 |
| - 2. [`Arduino Core for STM32 v2.0.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32F/L/H/G/WB/MP1 boards. [](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) |
| 122 | + 2. [`Arduino Core for STM32 v2.1.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32F/L/H/G/WB/MP1 boards. [](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) |
119 | 123 |
|
120 | 124 | 3. To use with certain example
|
121 | 125 | - [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_16_Timers_Array example](examples/ISR_16_Timers_Array).
|
@@ -346,7 +350,9 @@ void setup()
|
346 | 350 |
|
347 | 351 | 1. [ISR_16_PWMs_Array](examples/ISR_16_PWMs_Array)
|
348 | 352 | 2. [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex)
|
349 |
| - 3. [ISR_16_PWMs_Array_Simple](examples/ISR_16_PWMs_Array_Simple) |
| 353 | + 3. [ISR_16_PWMs_Array_Simple](examples/ISR_16_PWMs_Array_Simple) |
| 354 | + 4. [ISR_Changing_PWM](examples/ISR_Changing_PWM) |
| 355 | + 5. [ISR_Modify_PWM](examples/ISR_Modify_PWM) |
350 | 356 |
|
351 | 357 |
|
352 | 358 | ---
|
@@ -499,12 +505,11 @@ uint32_t PWM_Period[NUMBER_ISR_PWMS] =
|
499 | 505 | 111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
|
500 | 506 | };
|
501 | 507 |
|
502 |
| -
|
503 | 508 | // You can assign any interval for any timer here, in Hz
|
504 |
| -uint32_t PWM_Freq[NUMBER_ISR_PWMS] = |
| 509 | +double PWM_Freq[NUMBER_ISR_PWMS] = |
505 | 510 | {
|
506 |
| - 1, 2, 3, 4, 5, 6, 7, 8, |
507 |
| - 9, 10, 15, 20, 25, 30, 40, 50 |
| 511 | + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, |
| 512 | + 9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f |
508 | 513 | };
|
509 | 514 |
|
510 | 515 | // You can assign any interval for any timer here, in milliseconds
|
@@ -937,12 +942,12 @@ void loop()
|
937 | 942 |
|
938 | 943 | ### 1. ISR_16_PWMs_Array_Complex on NUCLEO_H743ZI2
|
939 | 944 |
|
940 |
| -The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on NUCLEO_H743ZI2 to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
| 945 | +The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on **NUCLEO_H743ZI2** to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
941 | 946 |
|
942 | 947 |
|
943 | 948 | ```
|
944 | 949 | Starting ISR_16_PWMs_Array_Complex on NUCLEO_H743ZI2
|
945 |
| -STM32_SLOW_PWM v1.0.0 |
| 950 | +STM32_SLOW_PWM v1.1.0 |
946 | 951 | [PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 240000000
|
947 | 952 | [PWM] Frequency = 1000000.00 , _count = 20
|
948 | 953 | Starting ITimer OK, micros() = 2015843
|
@@ -1002,12 +1007,12 @@ PWM Channel : 15, programmed Period (us): 20000, actual : 20000, programmed Duty
|
1002 | 1007 |
|
1003 | 1008 | ### 2. ISR_16_PWMs_Array_Complex on NUCLEO_F767ZI
|
1004 | 1009 |
|
1005 |
| -The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on NUCLEO_F767ZI to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
| 1010 | +The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on **NUCLEO_F767ZI** to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
1006 | 1011 |
|
1007 | 1012 |
|
1008 | 1013 | ```
|
1009 | 1014 | Starting ISR_16_PWMs_Array_Complex on NUCLEO_F767ZI
|
1010 |
| -STM32_SLOW_PWM v1.0.0 |
| 1015 | +STM32_SLOW_PWM v1.1.0 |
1011 | 1016 | [PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000
|
1012 | 1017 | [PWM] Frequency = 1000000.00 , _count = 20
|
1013 | 1018 | Starting ITimer OK, micros() = 2015789
|
@@ -1067,12 +1072,12 @@ PWM Channel : 15, programmed Period (us): 20000, actual : 20000, programmed Duty
|
1067 | 1072 |
|
1068 | 1073 | ### 3. ISR_16_PWMs_Array_Complex on NUCLEO_L552ZE_Q
|
1069 | 1074 |
|
1070 |
| -The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on NUCLEO_L552ZE_Q to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
| 1075 | +The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on **NUCLEO_L552ZE_Q** to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
1071 | 1076 |
|
1072 | 1077 |
|
1073 | 1078 | ```
|
1074 | 1079 | Starting ISR_16_PWMs_Array_Complex on NUCLEO_L552ZE_Q
|
1075 |
| -STM32_SLOW_PWM v1.0.0 |
| 1080 | +STM32_SLOW_PWM v1.1.0 |
1076 | 1081 | [PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 110000000
|
1077 | 1082 | [PWM] Frequency = 1000000.00 , _count = 20
|
1078 | 1083 | Starting ITimer OK, micros() = 2016141
|
@@ -1132,12 +1137,12 @@ PWM Channel : 15, programmed Period (us): 20000, actual : 20000, programmed Duty
|
1132 | 1137 |
|
1133 | 1138 | ### 4. ISR_16_PWMs_Array_Complex on BLUEPILL_F103CB
|
1134 | 1139 |
|
1135 |
| -The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on BLUEPILL_F103CB to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
| 1140 | +The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on **BLUEPILL_F103CB** to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles** |
1136 | 1141 |
|
1137 | 1142 |
|
1138 | 1143 | ```
|
1139 | 1144 | Starting ISR_16_PWMs_Array_Complex on BLUEPILL_F103CB
|
1140 |
| -STM32_SLOW_PWM v1.0.0 |
| 1145 | +STM32_SLOW_PWM v1.1.0 |
1141 | 1146 | [PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 72000000
|
1142 | 1147 | [PWM] Frequency = 1000000.00 , _count = 20
|
1143 | 1148 | Starting ITimer OK, micros() = 3390333
|
@@ -1193,6 +1198,52 @@ PWM Channel : 14, programmed Period (us): 25000, actual : 24988, programmed Duty
|
1193 | 1198 | PWM Channel : 15, programmed Period (us): 20000, actual : 19984, programmed DutyCycle : 95, actual : 95.00
|
1194 | 1199 | ```
|
1195 | 1200 |
|
| 1201 | +--- |
| 1202 | + |
| 1203 | +### 5. ISR_Modify_PWM on NUCLEO_F767ZI |
| 1204 | + |
| 1205 | +The following is the sample terminal output when running example [ISR_Modify_PWM](examples/ISR_Modify_PWM) on **NUCLEO_F767ZI** to demonstrate how to modify PWM settings on-the-fly without deleting the PWM channel |
| 1206 | + |
| 1207 | +``` |
| 1208 | +Starting ISR_Modify_PWM on NUCLEO_F767ZI |
| 1209 | +STM32_SLOW_PWM v1.1.0 |
| 1210 | +[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 |
| 1211 | +[PWM] Frequency = 1000000.00 , _count = 20 |
| 1212 | +Starting ITimer OK, micros() = 2010993 |
| 1213 | +Using PWM Freq = 1.00, PWM DutyCycle = 10 |
| 1214 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 2016713 |
| 1215 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 12028002 |
| 1216 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 22029002 |
| 1217 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 32030001 |
| 1218 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 42031001 |
| 1219 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 52032001 |
| 1220 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 62033001 |
| 1221 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 72034001 |
| 1222 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 82035001 |
| 1223 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 92036002 |
| 1224 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 102037001 |
| 1225 | +``` |
| 1226 | + |
| 1227 | +--- |
| 1228 | + |
| 1229 | +### 6. ISR_Changing_PWM on NUCLEO_F767ZI |
| 1230 | + |
| 1231 | +The following is the sample terminal output when running example [ISR_Changing_PWM](examples/ISR_Changing_PWM) on **NUCLEO_F767ZI** to demonstrate how to modify PWM settings on-the-fly by deleting the PWM channel and reinit the PWM channel |
| 1232 | + |
| 1233 | +``` |
| 1234 | +Starting ISR_Changing_PWM on NUCLEO_F767ZI |
| 1235 | +STM32_SLOW_PWM v1.1.0 |
| 1236 | +[PWM] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 |
| 1237 | +[PWM] Frequency = 1000000.00 , _count = 20 |
| 1238 | +Starting ITimer OK, micros() = 2010992 |
| 1239 | +Using PWM Freq = 1.00, PWM DutyCycle = 50 |
| 1240 | +Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 2022102 |
| 1241 | +Using PWM Freq = 2.00, PWM DutyCycle = 90 |
| 1242 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 12027024 |
| 1243 | +Using PWM Freq = 1.00, PWM DutyCycle = 50 |
| 1244 | +Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 22032024 |
| 1245 | +``` |
| 1246 | + |
1196 | 1247 |
|
1197 | 1248 | ---
|
1198 | 1249 | ---
|
@@ -1237,6 +1288,7 @@ Submit issues to: [STM32_Slow_PWM issues](https://github.com/khoih-prog/STM32_Sl
|
1237 | 1288 |
|
1238 | 1289 | 1. Basic hardware multi-channel PWM for **STM32F/L/H/G/WB/MP1 boards** such as NUCLEO_H743ZI2, NUCLEO_L552ZE_Q, NUCLEO_F767ZI, BLUEPILL_F103CB, etc., using [`Arduino Core for STM32`](https://github.com/stm32duino/Arduino_Core_STM32)
|
1239 | 1290 | 2. Add Table of Contents
|
| 1291 | +3. Add functions to modify PWM settings on-the-fly |
1240 | 1292 |
|
1241 | 1293 | ---
|
1242 | 1294 | ---
|
|
0 commit comments