11/* ***************************************************************************************************************************
2- Argument_None.ino
3- For SAM DUE boards
4- Written by Khoi Hoang
2+ Argument_None.ino
3+ For SAM DUE boards
4+ Written by Khoi Hoang
55
6- Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
7- Licensed under MIT license
6+ Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
7+ Licensed under MIT license
88
9- Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
10- unsigned long miliseconds), you just consume only one SAM DUE timer and avoid conflicting with other cores' tasks.
11- The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
12- Therefore, their executions are not blocked by bad-behaving functions / tasks.
13- This important feature is absolutely necessary for mission-critical tasks.
9+ Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
10+ unsigned long miliseconds), you just consume only one SAM DUE timer and avoid conflicting with other cores' tasks.
11+ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
12+ Therefore, their executions are not blocked by bad-behaving functions / tasks.
13+ This important feature is absolutely necessary for mission-critical tasks.
1414
15- Based on SimpleTimer - A timer library for Arduino.
16- 17- Copyright (c) 2010 OTTOTECNICA Italy
15+ Based on SimpleTimer - A timer library for Arduino.
16+ 17+ Copyright (c) 2010 OTTOTECNICA Italy
1818
19- Based on BlynkTimer.h
20- Author: Volodymyr Shymanskyy
19+ Based on BlynkTimer.h
20+ Author: Volodymyr Shymanskyy
2121
22- Version: 1.1.1
22+ Version: 1.2.0
2323
24- Version Modified By Date Comments
25- ------- ----------- ---------- -----------
26- 1.0.1 K Hoang 06/11/2020 Initial coding
27- 1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
24+ Version Modified By Date Comments
25+ ------- ----------- ---------- -----------
26+ 1.0.1 K Hoang 06/11/2020 Initial coding
27+ 1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
28+ 1.2.0 K.Hoang 10/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
2829*****************************************************************************************************************************/
2930
3031/*
4344 #error This code is designed to run on SAM DUE board / platform! Please check your Tools->Board setting.
4445#endif
4546
46- // These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
47- // Don't define SAMDUE_TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
48- #define SAMDUE_TIMER_INTERRUPT_DEBUG 1
47+ // These define's must be placed at the beginning before #include "SAMDUETimerInterrupt.h"
48+ // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
49+ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
50+ // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
51+ #define TIMER_INTERRUPT_DEBUG 0
52+ #define _TIMERINTERRUPT_LOGLEVEL_ 0
4953
5054#include " SAMDUETimerInterrupt.h"
5155
@@ -71,88 +75,94 @@ volatile uint32_t preMillisTimer1 = 0;
7175volatile uint32_t preMillisTimer2 = 0 ;
7276volatile uint32_t preMillisTimer3 = 0 ;
7377
74- void TimerHandler0 (void )
78+ void TimerHandler0 ()
7579{
76- static bool toggle = false ;
80+ static bool toggle0 = false ;
7781 static bool started = false ;
78- static uint32_t curMillis = 0 ;
79-
82+
8083 if (!started)
8184 {
8285 started = true ;
8386 pinMode (LED_BUILTIN, OUTPUT);
8487 }
8588
86- #if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
89+ #if (TIMER_INTERRUPT_DEBUG > 0)
90+ static uint32_t curMillis = 0 ;
91+
8792 curMillis = millis ();
8893
8994 if (curMillis > TIMER0_INTERVAL_MS)
9095 {
91- Serial.println (" ITimer0: millis() = " + String (curMillis) + " , delta = " + String (curMillis - preMillisTimer0));
96+ Serial.print (" ITimer0: millis() = " ); Serial.print (curMillis);
97+ Serial.print (" , delta = " ); Serial.println (curMillis - preMillisTimer0);
9298 }
9399
94100 preMillisTimer0 = curMillis;
95101#endif
96102
97103 // timer interrupt toggles pin LED_BUILTIN
98- digitalWrite (LED_BUILTIN, toggle );
99- toggle = !toggle ;
104+ digitalWrite (LED_BUILTIN, toggle0 );
105+ toggle0 = !toggle0 ;
100106}
101107
102- void TimerHandler1 (void )
108+ void TimerHandler1 ()
103109{
104- static bool toggle = false ;
110+ static bool toggle1 = false ;
105111 static bool started = false ;
106- static uint32_t curMillis = 0 ;
107112
108113 if (!started)
109114 {
110115 started = true ;
111116 pinMode (LED_BLUE, OUTPUT);
112117 }
113118
114- #if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
119+ #if (TIMER_INTERRUPT_DEBUG > 0)
120+ static uint32_t curMillis = 0 ;
121+
115122 curMillis = millis ();
116123
117124 if (curMillis > TIMER1_INTERVAL_MS)
118125 {
119- Serial.println (" ITimer1: millis() = " + String (curMillis) + " , delta = " + String (curMillis - preMillisTimer1));
126+ Serial.print (" ITimer1: millis() = " ); Serial.print (curMillis);
127+ Serial.print (" , delta = " ); Serial.println (curMillis - preMillisTimer1);
120128 }
121129
122130 preMillisTimer1 = curMillis;
123131#endif
124132
125133 // timer interrupt toggles outputPin
126- digitalWrite (LED_BLUE, toggle );
127- toggle = !toggle ;
134+ digitalWrite (LED_BLUE, toggle1 );
135+ toggle1 = !toggle1 ;
128136}
129137
130- void TimerHandler2 (void )
138+ void TimerHandler2 ()
131139{
132- #if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
140+ #if (TIMER_INTERRUPT_DEBUG > 0)
133141 static uint32_t curMillis = 0 ;
134142
135143 curMillis = millis ();
136144
137145 if (curMillis > TIMER2_INTERVAL_MS)
138146 {
139- Serial.println (" ITimer2: millis() = " + String (curMillis) + " , delta = " + String (curMillis - preMillisTimer2));
147+ Serial.print (" ITimer2: millis() = " ); Serial.print (curMillis);
148+ Serial.print (" , delta = " ); Serial.println (curMillis - preMillisTimer2);
140149 }
141150
142151 preMillisTimer2 = curMillis;
143152#endif
144153}
145154
146- void TimerHandler3 (void )
155+ void TimerHandler3 ()
147156{
148- #if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
157+ #if (TIMER_INTERRUPT_DEBUG > 0)
149158 static uint32_t curMillis = 0 ;
150159
151160 curMillis = millis ();
152161
153162 if (curMillis > TIMER3_INTERVAL_MS)
154163 {
155- Serial.println (" ITimer3: millis() = " + String (curMillis) + " , delta = " + String (curMillis - preMillisTimer3));
164+ Serial.print (" ITimer3: millis() = " ); Serial.print (curMillis);
165+ Serial.print (" , delta = " ); Serial.println (curMillis - preMillisTimer3);
156166 }
157167
158168 preMillisTimer3 = curMillis;
@@ -167,10 +177,7 @@ uint16_t attachDueInterrupt(double microseconds, timerCallback callback, const c
167177
168178 uint16_t timerNumber = dueTimerInterrupt.getTimerNumber ();
169179
170- Serial.print (TimerName);
171- Serial.print (" attached to Timer(" );
172- Serial.print (timerNumber);
173- Serial.println (" )" );
180+ Serial.print (TimerName); Serial.print (F (" attached to Timer(" )); Serial.print (timerNumber); Serial.println (F (" )" ));
174181
175182 return timerNumber;
176183}
@@ -182,10 +189,10 @@ void setup()
182189
183190 delay (100 );
184191
185- Serial.println ( " \n Starting Argument_None on " + String (BOARD_NAME) );
192+ Serial.print ( F ( " \n Starting Argument_None on " )); Serial. println (BOARD_NAME);
186193 Serial.println (SAMDUE_TIMER_INTERRUPT_VERSION);
187- Serial.println ( " CPU Frequency = " + String (F_CPU / 1000000 ) + " MHz" );
188- Serial.println ( " Timer Frequency = " + String (SystemCoreClock / 1000000 ) + " MHz" );
194+ Serial.print ( F ( " CPU Frequency = " )); Serial. print (F_CPU / 1000000 ); Serial. println ( F ( " MHz" ) );
195+ Serial.print ( F ( " Timer Frequency = " )); Serial. print (SystemCoreClock / 1000000 ); Serial. println ( F ( " MHz" ) );
189196
190197 // Interval in microsecs
191198 uint32_t curMillis = millis ();
0 commit comments