|
20 | 20 | Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
21 | 21 | This important feature is absolutely necessary for mission-critical tasks.
|
22 | 22 | *****************************************************************************************************************************/
|
| 23 | + |
23 | 24 | #if !defined( ESP32 )
|
24 | 25 | #error This code is designed to run on ESP32 platform, not Arduino nor ESP8266! Please check your Tools->Board setting.
|
25 |
| -#elif ( ARDUINO_ESP32C3_DEV ) |
26 |
| - #error This code is not designed to run on ESP32-C3 platform! Please check your Tools->Board setting. |
| 26 | + |
27 | 27 | #endif
|
28 | 28 |
|
29 | 29 | // These define's must be placed at the beginning before #include "ESP32_PWM.h"
|
|
33 | 33 |
|
34 | 34 | #define USING_MICROS_RESOLUTION true //false
|
35 | 35 |
|
| 36 | +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error |
36 | 37 | #include "ESP32_PWM.h"
|
37 | 38 |
|
38 | 39 | #ifndef LED_BUILTIN
|
@@ -66,7 +67,11 @@ bool IRAM_ATTR TimerHandler(void * timerNo)
|
66 | 67 |
|
67 | 68 | //////////////////////////////////////////////////////
|
68 | 69 |
|
69 |
| -#define NUMBER_ISR_PWMS 16 |
| 70 | +#if ( ARDUINO_ESP32C3_DEV ) |
| 71 | + #define NUMBER_ISR_PWMS 4 |
| 72 | +#else |
| 73 | + #define NUMBER_ISR_PWMS 16 |
| 74 | +#endif |
70 | 75 |
|
71 | 76 | #define PIN_D0 0 // Pin D0 mapped to pin GPIO0/BOOT/ADC11/TOUCH1 of ESP32
|
72 | 77 | #define PIN_D1 1 // Pin D1 mapped to pin GPIO1/TX0 of ESP32
|
@@ -99,32 +104,40 @@ bool IRAM_ATTR TimerHandler(void * timerNo)
|
99 | 104 |
|
100 | 105 | // You can assign pins here. Be carefull to select good pin to use or crash, e.g pin 6-11
|
101 | 106 | // Can't use PIN_D1 for core v2.0.1+
|
102 |
| -uint32_t PWM_Pin[NUMBER_ISR_PWMS] = |
| 107 | + |
| 108 | +#if ( ARDUINO_ESP32C3_DEV ) |
| 109 | +uint32_t PWM_Pin[] = |
| 110 | +// Bad pins to use: PIN_D12-PIN_D24 |
| 111 | +{ |
| 112 | + LED_BUILTIN, PIN_D3, PIN_D4, PIN_D5 |
| 113 | +}; |
| 114 | +#else |
| 115 | +uint32_t PWM_Pin[] = |
103 | 116 | {
|
104 | 117 | PIN_D24, LED_BUILTIN, PIN_D3, PIN_D4, PIN_D5, PIN_D12, PIN_D13, PIN_D14,
|
105 | 118 | PIN_D15, PIN_D16, PIN_D17, PIN_D18, PIN_D19, PIN_D21, PIN_D22, PIN_D23
|
106 | 119 | };
|
| 120 | +#endif |
107 | 121 |
|
108 | 122 | // You can assign any interval for any timer here, in microseconds
|
109 |
| -uint32_t PWM_Period[NUMBER_ISR_PWMS] = |
| 123 | +double PWM_Period[] = |
110 | 124 | {
|
111 |
| - 1000000L, 500000L, 333333L, 250000L, 200000L, 166667L, 142857L, 125000L, |
112 |
| - 111111L, 100000L, 66667L, 50000L, 40000L, 33333L, 25000L, 20000L |
| 125 | + 1000000.0, 500000.0, 333333.333, 250000.0, 200000.0, 166666.666, 142857.143, 125000.0, |
| 126 | + 111111.111, 100000.0, 66666.666, 50000.0, 40000.0, 33333.333, 25000.0, 20000.0 |
113 | 127 | };
|
114 | 128 |
|
115 | 129 | // You can assign any interval for any timer here, in Hz
|
116 |
| -double PWM_Freq[NUMBER_ISR_PWMS] = |
| 130 | +double PWM_Freq[] = |
117 | 131 | {
|
118 | 132 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
|
119 | 133 | 9.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 40.0f, 50.0f
|
120 | 134 | };
|
121 | 135 |
|
122 |
| - |
123 | 136 | // You can assign any interval for any timer here, in milliseconds
|
124 |
| -uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS] = |
| 137 | +double PWM_DutyCycle[] = |
125 | 138 | {
|
126 |
| - 5, 10, 20, 30, 40, 45, 50, 55, |
127 |
| - 60, 65, 70, 75, 80, 85, 90, 95 |
| 139 | + 5.00, 10.00, 20.00, 30.00, 40.00, 45.00, 50.00, 55.00, |
| 140 | + 60.00, 65.00, 70.00, 75.00, 80.00, 85.00, 90.00, 95.00 |
128 | 141 | };
|
129 | 142 |
|
130 | 143 | typedef void (*irqCallback) ();
|
@@ -197,7 +210,7 @@ void doingSomething15()
|
197 | 210 | {
|
198 | 211 | }
|
199 | 212 |
|
200 |
| -irqCallback irqCallbackStartFunc[NUMBER_ISR_PWMS] = |
| 213 | +irqCallback irqCallbackStartFunc[] = |
201 | 214 | {
|
202 | 215 | doingSomething0, doingSomething1, doingSomething2, doingSomething3,
|
203 | 216 | doingSomething4, doingSomething5, doingSomething6, doingSomething7,
|
|
0 commit comments