39
39
40
40
#define USING_MICROS_RESOLUTION true // false
41
41
42
+ // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
42
43
#include " AVR_Slow_PWM.h"
43
44
44
45
#include < SimpleTimer.h> // https://github.com/jfturcot/SimpleTimer
@@ -110,9 +111,9 @@ typedef struct
110
111
irqCallback irqCallbackStartFunc;
111
112
irqCallback irqCallbackStopFunc;
112
113
113
- uint32_t PWM_Freq;
114
+ double PWM_Freq;
114
115
115
- uint32_t PWM_DutyCycle;
116
+ double PWM_DutyCycle;
116
117
117
118
uint32_t deltaMicrosStart;
118
119
uint32_t previousMicrosStart;
@@ -132,29 +133,29 @@ void doingSomethingStop(int index);
132
133
133
134
#else // #if USE_COMPLEX_STRUCT
134
135
135
- volatile unsigned long deltaMicrosStart [NUMBER_ISR_PWMS ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
136
- volatile unsigned long previousMicrosStart [NUMBER_ISR_PWMS ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
136
+ volatile unsigned long deltaMicrosStart [] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
137
+ volatile unsigned long previousMicrosStart [] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
137
138
138
- volatile unsigned long deltaMicrosStop [NUMBER_ISR_PWMS ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
139
- volatile unsigned long previousMicrosStop [NUMBER_ISR_PWMS ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
139
+ volatile unsigned long deltaMicrosStop [] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
140
+ volatile unsigned long previousMicrosStop [] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
140
141
141
142
142
143
// You can assign any interval for any timer here, in Microseconds
143
- uint32_t PWM_Period[NUMBER_ISR_PWMS ] =
144
+ double PWM_Period[] =
144
145
{
145
- 1000L , 500L , 333L , 250L , 200L , 166L , 142L , 125L
146
+ 1000.0 , 500.0 , 333.333 , 250.0 , 200.0 , 166.667 , 142.857 , 125.0
146
147
};
147
148
148
149
// You can assign any interval for any timer here, in Hz
149
- double PWM_Freq[NUMBER_ISR_PWMS ] =
150
+ double PWM_Freq[] =
150
151
{
151
152
1 .0f , 2 .0f , 3 .0f , 4 .0f , 5 .0f , 6 .0f , 7 .0f , 8 .0f ,
152
153
};
153
154
154
155
// You can assign any interval for any timer here, in Microseconds
155
- uint32_t PWM_DutyCycle[NUMBER_ISR_PWMS ] =
156
+ double PWM_DutyCycle[] =
156
157
{
157
- 5 , 10 , 20 , 25 , 30 , 35 , 40 , 45
158
+ 5.0 , 10.0 , 20.0 , 25.0 , 30.0 , 35.0 , 40.0 , 45.0
158
159
};
159
160
160
161
void doingSomethingStart (int index)
@@ -268,17 +269,17 @@ void doingSomethingStop7()
268
269
269
270
#if USE_COMPLEX_STRUCT
270
271
271
- ISR_PWM_Data curISR_PWM_Data[NUMBER_ISR_PWMS ] =
272
+ ISR_PWM_Data curISR_PWM_Data[] =
272
273
{
273
274
// pin, irqCallbackStartFunc, irqCallbackStopFunc, PWM_Freq, PWM_DutyCycle, deltaMicrosStart, previousMicrosStart, deltaMicrosStop, previousMicrosStop
274
- { LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1 , 5 , 0 , 0 , 0 , 0 },
275
- { PIN_D0, doingSomethingStart1, doingSomethingStop1, 2 , 10 , 0 , 0 , 0 , 0 },
276
- { PIN_D1, doingSomethingStart2, doingSomethingStop2, 3 , 20 , 0 , 0 , 0 , 0 },
277
- { PIN_D2, doingSomethingStart3, doingSomethingStop3, 4 , 25 , 0 , 0 , 0 , 0 },
278
- { PIN_D3, doingSomethingStart4, doingSomethingStop4, 5 , 30 , 0 , 0 , 0 , 0 },
279
- { PIN_D4, doingSomethingStart5, doingSomethingStop5, 6 , 35 , 0 , 0 , 0 , 0 },
280
- { PIN_D5, doingSomethingStart6, doingSomethingStop6, 7 , 40 , 0 , 0 , 0 , 0 },
281
- { PIN_D6, doingSomethingStart7, doingSomethingStop7, 8 , 45 , 0 , 0 , 0 , 0 },
275
+ { LED_BUILTIN, doingSomethingStart0, doingSomethingStop0, 1.0 , 5.0 , 0 , 0 , 0 , 0 },
276
+ { PIN_D0, doingSomethingStart1, doingSomethingStop1, 2.0 , 10.0 , 0 , 0 , 0 , 0 },
277
+ { PIN_D1, doingSomethingStart2, doingSomethingStop2, 3.0 , 20.0 , 0 , 0 , 0 , 0 },
278
+ { PIN_D2, doingSomethingStart3, doingSomethingStop3, 4.0 , 25.0 , 0 , 0 , 0 , 0 },
279
+ { PIN_D3, doingSomethingStart4, doingSomethingStop4, 5.0 , 30.0 , 0 , 0 , 0 , 0 },
280
+ { PIN_D4, doingSomethingStart5, doingSomethingStop5, 6.0 , 35.0 , 0 , 0 , 0 , 0 },
281
+ { PIN_D5, doingSomethingStart6, doingSomethingStop6, 7.0 , 40.0 , 0 , 0 , 0 , 0 },
282
+ { PIN_D6, doingSomethingStart7, doingSomethingStop7, 8.0 , 45.0 , 0 , 0 , 0 , 0 },
282
283
};
283
284
284
285
@@ -302,13 +303,13 @@ void doingSomethingStop(int index)
302
303
303
304
#else // #if USE_COMPLEX_STRUCT
304
305
305
- irqCallback irqCallbackStartFunc[NUMBER_ISR_PWMS ] =
306
+ irqCallback irqCallbackStartFunc[] =
306
307
{
307
308
doingSomethingStart0, doingSomethingStart1, doingSomethingStart2, doingSomethingStart3,
308
309
doingSomethingStart4, doingSomethingStart5, doingSomethingStart6, doingSomethingStart7
309
310
};
310
311
311
- irqCallback irqCallbackStopFunc[NUMBER_ISR_PWMS ] =
312
+ irqCallback irqCallbackStopFunc[] =
312
313
{
313
314
doingSomethingStop0, doingSomethingStop1, doingSomethingStop2, doingSomethingStop3,
314
315
doingSomethingStop4, doingSomethingStop5, doingSomethingStop6, doingSomethingStop7
@@ -343,9 +344,9 @@ void simpleTimerDoingSomething2s()
343
344
Serial.print (F (" PWM Channel : " )); Serial.print (i);
344
345
Serial.print (F (" , prog Period (ms): " ));
345
346
346
- Serial.print (1000 .f / curISR_PWM_Data[i].PWM_Freq );
347
+ Serial.print (1000 .0f / curISR_PWM_Data[i].PWM_Freq );
347
348
348
- Serial.print (F (" , actual : " )); Serial.print (( uint32_t ) curISR_PWM_Data[i].deltaMicrosStart );
349
+ Serial.print (F (" , actual (uS) : " )); Serial.print (curISR_PWM_Data[i].deltaMicrosStart );
349
350
350
351
Serial.print (F (" , prog DutyCycle : " ));
351
352
@@ -359,7 +360,7 @@ void simpleTimerDoingSomething2s()
359
360
360
361
Serial.print (F (" PWM Channel : " )); Serial.print (i);
361
362
362
- Serial.print (1000 / PWM_Freq[i]);
363
+ Serial.print (1000 . 0f / PWM_Freq[i]);
363
364
364
365
Serial.print (F (" , prog. Period (us): " )); Serial.print (PWM_Period[i]);
365
366
Serial.print (F (" , actual : " )); Serial.print (deltaMicrosStart[i]);
0 commit comments