1
1
/* ***************************************************************************************************************************
2
- Change_Interval.ino
3
- For NRF52 boards
4
- Written by Khoi Hoang
5
-
6
- Built by Khoi Hoang https://github.com/khoih-prog/NRF52_TimerInterrupt
7
- Licensed under MIT license
8
-
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 NRF52 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.
14
-
15
- Based on SimpleTimer - A timer library for Arduino.
16
- Author: mromani@ottotecnica.com
17
- Copyright (c) 2010 OTTOTECNICA Italy
18
-
19
- Based on BlynkTimer.h
20
- Author: Volodymyr Shymanskyy
21
-
22
- Version: 1.1.1
23
-
24
- Version Modified By Date Comments
25
- ------- ----------- ---------- -----------
26
- 1.0.0 K Hoang 02/11/2020 Initial coding
27
- 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
28
- 1.0.2 K Hoang 24/11/2020 Add complicated example ISR_16_Timers_Array_Complex and optimize examples
29
- 1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
2
+ Change_Interval.ino
3
+ For NRF52 boards
4
+ Written by Khoi Hoang
5
+
6
+ Built by Khoi Hoang https://github.com/khoih-prog/NRF52_TimerInterrupt
7
+ Licensed under MIT license
8
+
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 NRF52 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.
14
+
15
+ Based on SimpleTimer - A timer library for Arduino.
16
+ Author: mromani@ottotecnica.com
17
+ Copyright (c) 2010 OTTOTECNICA Italy
18
+
19
+ Based on BlynkTimer.h
20
+ Author: Volodymyr Shymanskyy
21
+
22
+ Version: 1.2.0
23
+
24
+ Version Modified By Date Comments
25
+ ------- ----------- ---------- -----------
26
+ 1.0.0 K Hoang 02/11/2020 Initial coding
27
+ 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
28
+ 1.0.2 K Hoang 24/11/2020 Add complicated example ISR_16_Timers_Array_Complex and optimize examples
29
+ 1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
30
+ 1.2.0 K.Hoang 11/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
30
31
*****************************************************************************************************************************/
31
32
32
33
/*
49
50
#endif
50
51
51
52
// These define's must be placed at the beginning before #include "NRF52TimerInterrupt.h"
52
- // Don't define NRF52_TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
53
- #define NRF52_TIMER_INTERRUPT_DEBUG 0
53
+ // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
54
+ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
55
+ // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
56
+ #define TIMER_INTERRUPT_DEBUG 0
57
+ #define _TIMERINTERRUPT_LOGLEVEL_ 0
54
58
55
59
#include " NRF52TimerInterrupt.h"
56
60
@@ -83,10 +87,12 @@ NRF52Timer ITimer1(NRF_TIMER_3);
83
87
84
88
void printResult (uint32_t currTime)
85
89
{
86
- Serial.printf (" Time = %ld, Timer0Count = %lu, , Timer1Count = %lu\n " , currTime, Timer0Count, Timer1Count);
90
+ Serial.print (F (" Time = " )); Serial.print (currTime);
91
+ Serial.print (F (" , Timer0Count = " )); Serial.print (Timer0Count);
92
+ Serial.print (F (" , Timer1Count = " )); Serial.println (Timer1Count);
87
93
}
88
94
89
- void TimerHandler0 (void )
95
+ void TimerHandler0 ()
90
96
{
91
97
static bool toggle0 = false ;
92
98
@@ -98,7 +104,7 @@ void TimerHandler0(void)
98
104
toggle0 = !toggle0;
99
105
}
100
106
101
- void TimerHandler1 (void )
107
+ void TimerHandler1 ()
102
108
{
103
109
static bool toggle1 = false ;
104
110
@@ -119,26 +125,26 @@ void setup()
119
125
while (!Serial);
120
126
121
127
delay (100 );
122
-
123
- Serial.printf ( " \n Starting Change_Interval on %s \n " , BOARD_NAME);
128
+
129
+ Serial.print ( F ( " \n Starting Change_Interval on " )); Serial. println ( BOARD_NAME);
124
130
Serial.println (NRF52_TIMER_INTERRUPT_VERSION);
125
- Serial.printf ( " CPU Frequency = %ld MHz \n " , F_CPU / 1000000 );
131
+ Serial.print ( F ( " CPU Frequency = " )); Serial. print ( F_CPU / 1000000 ); Serial. println ( F ( " MHz " ) );
126
132
127
133
// Interval in microsecs
128
134
if (ITimer0.attachInterruptInterval (TIMER0_INTERVAL_MS * 1000 , TimerHandler0))
129
135
{
130
- Serial.printf ( " Starting ITimer0 OK, millis() = %ld \n " , millis ());
136
+ Serial.print ( F ( " Starting ITimer0 OK, millis() = " )); Serial. println ( millis ());
131
137
}
132
138
else
133
- Serial.println (" Can't set ITimer0. Select another freq. or timer" );
139
+ Serial.println (F ( " Can't set ITimer0. Select another freq. or timer" ) );
134
140
135
141
// Interval in microsecs
136
142
if (ITimer1.attachInterruptInterval (TIMER1_INTERVAL_MS * 1000 , TimerHandler1))
137
143
{
138
- Serial.printf ( " Starting ITimer1 OK, millis() = %ld \n " , millis ());
144
+ Serial.print ( F ( " Starting ITimer1 OK, millis() = " )); Serial. println ( millis ());
139
145
}
140
146
else
141
- Serial.println (" Can't set ITimer1. Select another freq. or timer" );
147
+ Serial.println (F ( " Can't set ITimer1. Select another freq. or timer" ) );
142
148
}
143
149
144
150
#define CHECK_INTERVAL_MS 10000L
@@ -166,8 +172,9 @@ void loop()
166
172
ITimer0.setInterval (TIMER0_INTERVAL_MS * 1000 * (multFactor + 1 ), TimerHandler0);
167
173
ITimer1.setInterval (TIMER1_INTERVAL_MS * 1000 * (multFactor + 1 ), TimerHandler1);
168
174
169
- Serial.printf (" Changing Interval, Timer0 = %lu, Timer1 = %lu\n " , TIMER0_INTERVAL_MS * (multFactor + 1 ), TIMER1_INTERVAL_MS * (multFactor + 1 ));
170
-
175
+ Serial.print (F (" Changing Interval, Timer0 = " )); Serial.print (TIMER0_INTERVAL_MS * (multFactor + 1 ));
176
+ Serial.print (F (" , Timer1 = " )); Serial.println (TIMER1_INTERVAL_MS * (multFactor + 1 ));
177
+
171
178
lastChangeTime = currTime;
172
179
}
173
180
}
0 commit comments