|
34 | 34 | * [2. Set PWM Frequency, dutycycle, attach irqCallbackStartFunc and irqCallbackStopFunc functions](#2-Set-PWM-Frequency-dutycycle-attach-irqCallbackStartFunc-and-irqCallbackStopFunc-functions)
|
35 | 35 | * [Examples](#examples)
|
36 | 36 | * [For SAMD21](#For-SAMD21)
|
37 |
| - * [ 1. ISR_16_PWMs_Array](examples/SAMD21/ISR_16_PWMs_Array) |
38 |
| - * [ 2. ISR_16_PWMs_Array_Complex](examples/SAMD21/ISR_16_PWMs_Array_Complex) |
39 |
| - * [ 3. ISR_16_PWMs_Array_Simple](examples/SAMD21/ISR_16_PWMs_Array_Simple) |
| 37 | + * [ 1. ISR_16_PWMs_Array](examples/SAMD21/ISR_16_PWMs_Array) |
| 38 | + * [ 2. ISR_16_PWMs_Array_Complex](examples/SAMD21/ISR_16_PWMs_Array_Complex) |
| 39 | + * [ 3. ISR_16_PWMs_Array_Simple](examples/SAMD21/ISR_16_PWMs_Array_Simple) |
| 40 | + * [ 4. ISR_Changing_PWM](examples/SAMD21/ISR_Changing_PWM) |
| 41 | + * [ 5. ISR_Modify_PWM](examples/SAMD21/ISR_Modify_PWM) |
40 | 42 | * [For SAMD51](#For-SAMD51)
|
41 |
| - * [ 1. ISR_16_PWMs_Array](examples/SAMD51/ISR_16_PWMs_Array) |
42 |
| - * [ 2. ISR_16_PWMs_Array_Complex](examples/SAMD51/ISR_16_PWMs_Array_Complex) |
43 |
| - * [ 3. ISR_16_PWMs_Array_Simple](examples/SAMD51/ISR_16_PWMs_Array_Simple) |
| 43 | + * [ 1. ISR_16_PWMs_Array](examples/SAMD51/ISR_16_PWMs_Array) |
| 44 | + * [ 2. ISR_16_PWMs_Array_Complex](examples/SAMD51/ISR_16_PWMs_Array_Complex) |
| 45 | + * [ 3. ISR_16_PWMs_Array_Simple](examples/SAMD51/ISR_16_PWMs_Array_Simple) |
| 46 | + * [ 4. ISR_Changing_PWM](examples/SAMD51/ISR_Changing_PWM) |
| 47 | + * [ 5. ISR_Modify_PWM](examples/SAMD51/ISR_Modify_PWM) |
44 | 48 | * [Example SAMD51 ISR_16_PWMs_Array_Complex](#Example-SAMD51-ISR_16_PWMs_Array_Complex)
|
45 | 49 | * [Debug Terminal Output Samples](#debug-terminal-output-samples)
|
46 | 50 | * [1. ISR_16_PWMs_Array_Complex on SAMD_NANO_33_IOT](#1-ISR_16_PWMs_Array_Complex-on-SAMD_NANO_33_IOT)
|
47 | 51 | * [2. ISR_16_PWMs_Array_Complex on ITSYBITSY_M4](#2-ISR_16_PWMs_Array_Complex-on-ITSYBITSY_M4)
|
48 | 52 | * [3. ISR_16_PWMs_Array_Complex on SEEED_XIAO_M0](#3-ISR_16_PWMs_Array_Complex-on-SEEED_XIAO_M0)
|
| 53 | + * [4. ISR_Modify_PWM on SAMD_NANO_33_IOT](#4-ISR_Modify_PWM-on-SAMD_NANO_33_IOT) |
| 54 | + * [5. ISR_Changing_PWM on SAMD_NANO_33_IOT](#5-ISR_Changing_PWM-on-SAMD_NANO_33_IOT) |
| 55 | + * [6. ISR_Modify_PWM on ITSYBITSY_M4](#6-ISR_Modify_PWM-on-ITSYBITSY_M4) |
| 56 | + * [7. ISR_Changing_PWM on ITSYBITSY_M4](#7-ISR_Changing_PWM-on-ITSYBITSY_M4) |
49 | 57 | * [Debug](#debug)
|
50 | 58 | * [Troubleshooting](#troubleshooting)
|
51 | 59 | * [Issues](#issues)
|
@@ -132,7 +140,7 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
|
132 | 140 | 2. [`Arduino SAMD core 1.8.11+`](https://github.com/arduino/ArduinoCore-samd) for SAMD ARM Cortex-M0+ boards. [](https://github.com/arduino/ArduinoCore-samd/releases/latest)
|
133 | 141 | 3. [`Adafruit SAMD core 1.7.5+`](https://github.com/adafruit/ArduinoCore-samd) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). [](https://github.com/adafruit/ArduinoCore-samd/releases/latest)
|
134 | 142 | 4. [`Seeeduino SAMD core 1.8.1+`](https://github.com/Seeed-Studio/ArduinoCore-samd) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). [](https://github.com/Seeed-Studio/ArduinoCore-samd/releases/latest/)
|
135 |
| - 5. [`Sparkfun SAMD core 1.8.1+`](https://github.com/sparkfun/Arduino_Boards) for SAMD21/SAMD51 boards (SparkFun_RedBoard_Turbo, SparkFun_SAMD51_Thing_Plus, etc.). |
| 143 | + 5. [`Sparkfun SAMD core 1.8.3+`](https://github.com/sparkfun/Arduino_Boards) for SAMD21/SAMD51 boards (SparkFun_RedBoard_Turbo, SparkFun_SAMD51_Thing_Plus, etc.). |
136 | 144 |
|
137 | 145 | 6. To use with certain example
|
138 | 146 | - [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_16_Timers_Array example](examples/ISR_16_Timers_Array).
|
@@ -319,12 +327,16 @@ void setup()
|
319 | 327 | 1. [ISR_16_PWMs_Array](examples/SAMD21/ISR_16_PWMs_Array)
|
320 | 328 | 2. [ISR_16_PWMs_Array_Complex](examples/SAMD21/ISR_16_PWMs_Array_Complex)
|
321 | 329 | 3. [ISR_16_PWMs_Array_Simple](examples/SAMD21/ISR_16_PWMs_Array_Simple)
|
| 330 | + 4. [ISR_Changing_PWM](examples/SAMD21/ISR_Changing_PWM) |
| 331 | + 5. [ISR_Modify_PWM](examples/SAMD21/ISR_Modify_PWM) |
322 | 332 |
|
323 | 333 | #### For SAMD51
|
324 | 334 |
|
325 | 335 | 1. [ISR_16_PWMs_Array](examples/SAMD51/ISR_16_PWMs_Array)
|
326 | 336 | 2. [ISR_16_PWMs_Array_Complex](examples/SAMD51/ISR_16_PWMs_Array_Complex)
|
327 |
| - 3. [ISR_16_PWMs_Array_Simple](examples/SAMD51/ISR_16_PWMs_Array_Simple) |
| 337 | + 3. [ISR_16_PWMs_Array_Simple](examples/SAMD51/ISR_16_PWMs_Array_Simple) |
| 338 | + 4. [ISR_Changing_PWM](examples/SAMD51/ISR_Changing_PWM) |
| 339 | + 5. [ISR_Modify_PWM](examples/SAMD51/ISR_Modify_PWM) |
328 | 340 |
|
329 | 341 |
|
330 | 342 | ---
|
@@ -468,12 +480,11 @@ uint32_t PWM_Period[] =
|
468 | 480 | 111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L
|
469 | 481 | };
|
470 | 482 |
|
471 |
| -
|
472 | 483 | // You can assign any interval for any timer here, in Hz
|
473 |
| -uint32_t PWM_Freq[] = |
| 484 | +double PWM_Freq[NUMBER_ISR_PWMS] = |
474 | 485 | {
|
475 |
| - 1, 2, 3, 4, 5, 6, 7, 8, |
476 |
| - 9, 10, 15, 20, 25, 30, 40, 50 |
| 486 | + 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, |
| 487 | + 9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f |
477 | 488 | };
|
478 | 489 |
|
479 | 490 | // You can assign any interval for any timer here, in milliseconds
|
@@ -906,12 +917,12 @@ void loop()
|
906 | 917 |
|
907 | 918 | ### 1. ISR_16_PWMs_Array_Complex on SAMD_NANO_33_IOT
|
908 | 919 |
|
909 |
| -The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on SAMD_NANO_33_IOT 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** |
| 920 | +The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/SAMD21/ISR_16_PWMs_Array_Complex) on SAMD_NANO_33_IOT 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** |
910 | 921 |
|
911 | 922 |
|
912 | 923 | ```
|
913 | 924 | Starting ISR_16_PWMs_Array_Complex on SAMD_NANO_33_IOT
|
914 |
| -SAMD_Slow_PWM v1.0.0 |
| 925 | +SAMD_Slow_PWM v1.1.0 |
915 | 926 | [PWM] _period = 20 , frequency = 50000.00
|
916 | 927 | [PWM] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
|
917 | 928 | [PWM] TC3_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
|
@@ -959,12 +970,12 @@ PWM Channel : 7, programmed Period (us): 20000, actual : 20006, programmed DutyC
|
959 | 970 |
|
960 | 971 | ### 2. ISR_16_PWMs_Array_Complex on ITSYBITSY_M4
|
961 | 972 |
|
962 |
| -The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on ITSYBITSY_M4 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** |
| 973 | +The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/SAMD51/ISR_16_PWMs_Array_Complex) on ITSYBITSY_M4 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** |
963 | 974 |
|
964 | 975 |
|
965 | 976 | ```
|
966 | 977 | Starting ISR_16_PWMs_Array_Complex on ITSYBITSY_M4
|
967 |
| -SAMD_Slow_PWM v1.0.0 |
| 978 | +SAMD_Slow_PWM v1.1.0 |
968 | 979 | [PWM] SAMDTimerInterrupt: F_CPU (MHz) = 120 , TIMER_HZ = 48
|
969 | 980 | [PWM] TC_Timer::startTimer _Timer = 0x 4101c000 , TC3 = 0x 4101c000
|
970 | 981 | [PWM] SAMD51 TC3 period = 20 , _prescaler = 1
|
@@ -1027,12 +1038,12 @@ PWM Channel : 15, programmed Period (us): 20000, actual : 19989, programmed Duty
|
1027 | 1038 |
|
1028 | 1039 | ### 3. ISR_16_PWMs_Array_Complex on SEEED_XIAO_M0
|
1029 | 1040 |
|
1030 |
| -The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/ISR_16_PWMs_Array_Complex) on SEEED_XIAO_M0 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** |
| 1041 | +The following is the sample terminal output when running example [ISR_16_PWMs_Array_Complex](examples/SAMD21/ISR_16_PWMs_Array_Complex) on SEEED_XIAO_M0 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** |
1031 | 1042 |
|
1032 | 1043 |
|
1033 | 1044 | ```
|
1034 | 1045 | Starting ISR_16_PWMs_Array_Complex on SEEED_XIAO_M0
|
1035 |
| -SAMD_Slow_PWM v1.0.0 |
| 1046 | +SAMD_Slow_PWM v1.1.0 |
1036 | 1047 | [PWM] _period = 20 , frequency = 50000.00
|
1037 | 1048 | [PWM] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
|
1038 | 1049 | [PWM] TC3_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
|
@@ -1067,6 +1078,103 @@ PWM Channel : 6, programmed Period (us): 25000, actual : 24994, programmed DutyC
|
1067 | 1078 | PWM Channel : 7, programmed Period (us): 20000, actual : 20000, programmed DutyCycle : 70, actual : 70.00
|
1068 | 1079 | ```
|
1069 | 1080 |
|
| 1081 | +--- |
| 1082 | + |
| 1083 | +### 4. ISR_Modify_PWM on SAMD_NANO_33_IOT |
| 1084 | + |
| 1085 | +The following is the sample terminal output when running example [ISR_Modify_PWM](examples/SAMD21/ISR_Modify_PWM) on **SAMD_NANO_33_IOT** to demonstrate how to modify PWM settings on-the-fly without deleting the PWM channel |
| 1086 | + |
| 1087 | +``` |
| 1088 | +Starting ISR_Modify_PWM on SAMD_NANO_33_IOT |
| 1089 | +SAMD_Slow_PWM v1.1.0 |
| 1090 | +[PWM] _period = 20 , frequency = 50000.00 |
| 1091 | +[PWM] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48 |
| 1092 | +[PWM] TC3_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00 |
| 1093 | +[PWM] SAMD21 TC3 period = 20 , _prescaler = 1 |
| 1094 | +[PWM] _compareValue = 959 |
| 1095 | +Starting ITimer OK, micros() = 2821686 |
| 1096 | +Using PWM Freq = 1.00, PWM DutyCycle = 10 |
| 1097 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 2822762 |
| 1098 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 12824098 |
| 1099 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 22825080 |
| 1100 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 32826081 |
| 1101 | +``` |
| 1102 | + |
| 1103 | +--- |
| 1104 | + |
| 1105 | +### 5. ISR_Changing_PWM on SAMD_NANO_33_IOT |
| 1106 | + |
| 1107 | +The following is the sample terminal output when running example [ISR_Changing_PWM](examples/SAMD21/ISR_Changing_PWM) on **SAMD_NANO_33_IOT** to demonstrate how to modify PWM settings on-the-fly by deleting the PWM channel and reinit the PWM channel |
| 1108 | + |
| 1109 | +``` |
| 1110 | +Starting ISR_Changing_PWM on SAMD_NANO_33_IOT |
| 1111 | +SAMD_Slow_PWM v1.1.0 |
| 1112 | +[PWM] _period = 20 , frequency = 50000.00 |
| 1113 | +[PWM] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48 |
| 1114 | +[PWM] TC3_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00 |
| 1115 | +[PWM] SAMD21 TC3 period = 20 , _prescaler = 1 |
| 1116 | +[PWM] _compareValue = 959 |
| 1117 | +Starting ITimer OK, micros() = 2921757 |
| 1118 | +Using PWM Freq = 1.00, PWM DutyCycle = 50 |
| 1119 | +Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 2922855 |
| 1120 | +Using PWM Freq = 2.00, PWM DutyCycle = 90 |
| 1121 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 12924175 |
| 1122 | +Using PWM Freq = 1.00, PWM DutyCycle = 50 |
| 1123 | +Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 22925508 |
| 1124 | +Using PWM Freq = 2.00, PWM DutyCycle = 90 |
| 1125 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 32926654 |
| 1126 | +``` |
| 1127 | + |
| 1128 | +--- |
| 1129 | + |
| 1130 | +### 6. ISR_Modify_PWM on ITSYBITSY_M4 |
| 1131 | + |
| 1132 | +The following is the sample terminal output when running example [ISR_Modify_PWM](examples/SAMD51/ISR_Modify_PWM) on **ITSYBITSY_M4** to demonstrate how to modify PWM settings on-the-fly without deleting the PWM channel |
| 1133 | + |
| 1134 | +``` |
| 1135 | +Starting ISR_Modify_PWM on ITSYBITSY_M4 |
| 1136 | +SAMD_Slow_PWM v1.1.0 |
| 1137 | +[PWM] SAMDTimerInterrupt: F_CPU (MHz) = 120 , TIMER_HZ = 48 |
| 1138 | +[PWM] TC_Timer::startTimer _Timer = 0x 4101c000 , TC3 = 0x 4101c000 |
| 1139 | +[PWM] SAMD51 TC3 period = 20 , _prescaler = 1 |
| 1140 | +[PWM] _compareValue = 959 |
| 1141 | +Starting ITimer OK, micros() = 3821127 |
| 1142 | +Using PWM Freq = 1.00, PWM DutyCycle = 10 |
| 1143 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 3821615 |
| 1144 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 13823005 |
| 1145 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 23824004 |
| 1146 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 33825004 |
| 1147 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 43826004 |
| 1148 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 53827004 |
| 1149 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 63828004 |
| 1150 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 73829003 |
| 1151 | +Channel : 0 Period : 1000000 OnTime : 100000 Start_Time : 83830004 |
| 1152 | +``` |
| 1153 | + |
| 1154 | +--- |
| 1155 | + |
| 1156 | +### 7. ISR_Changing_PWM on ITSYBITSY_M4 |
| 1157 | + |
| 1158 | +The following is the sample terminal output when running example [ISR_Changing_PWM](examples/SAMD51/ISR_Changing_PWM) on **ITSYBITSY_M4** to demonstrate how to modify PWM settings on-the-fly by deleting the PWM channel and reinit the PWM channel |
| 1159 | + |
| 1160 | +``` |
| 1161 | +Starting ISR_Changing_PWM on ITSYBITSY_M4 |
| 1162 | +SAMD_Slow_PWM v1.1.0 |
| 1163 | +[PWM] SAMDTimerInterrupt: F_CPU (MHz) = 120 , TIMER_HZ = 48 |
| 1164 | +[PWM] TC_Timer::startTimer _Timer = 0x 4101c000 , TC3 = 0x 4101c000 |
| 1165 | +[PWM] SAMD51 TC3 period = 20 , _prescaler = 1 |
| 1166 | +[PWM] _compareValue = 959 |
| 1167 | +Starting ITimer OK, micros() = 2721076 |
| 1168 | +Using PWM Freq = 1.00, PWM DutyCycle = 50 |
| 1169 | +Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 2721574 |
| 1170 | +Using PWM Freq = 2.00, PWM DutyCycle = 90 |
| 1171 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 12722174 |
| 1172 | +Using PWM Freq = 1.00, PWM DutyCycle = 50 |
| 1173 | +Channel : 0 Period : 1000000 OnTime : 500000 Start_Time : 22722759 |
| 1174 | +Using PWM Freq = 2.00, PWM DutyCycle = 90 |
| 1175 | +Channel : 0 Period : 500000 OnTime : 450000 Start_Time : 32723417 |
| 1176 | +``` |
| 1177 | + |
1070 | 1178 | ---
|
1071 | 1179 | ---
|
1072 | 1180 |
|
@@ -1110,6 +1218,7 @@ Submit issues to: [SAMD_Slow_PWM issues](https://github.com/khoih-prog/SAMD_Slow
|
1110 | 1218 |
|
1111 | 1219 | 1. Basic hardware multi-channel PWM for **SAMD21/SAMD51 boards** such as NANO_33_IOT, ITSYBITSY_M4, SEEED_XIAO_M0, SparkFun_SAMD51_Thing_Plus, etc. using Arduino, Adafruit or Sparkfun core
|
1112 | 1220 | 2. Add Table of Contents
|
| 1221 | +3. Add functions to modify PWM settings on-the-fly |
1113 | 1222 |
|
1114 | 1223 | ---
|
1115 | 1224 | ---
|
|
0 commit comments