Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 5fe937c

Browse files
authored
v1.0.2
### Releases v1.0.2 1. Add complicated example ISR_16_Timers_Array_Complex 2. Optimize examples
1 parent 81ee26d commit 5fe937c

File tree

19 files changed

+570
-395
lines changed

19 files changed

+570
-395
lines changed

examples/Argument_None/Argument_None.ino

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
Based on BlynkTimer.h
2020
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.0.1
22+
Version: 1.0.2
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.0.0 K Hoang 02/11/2020 Initial coding
2727
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
2829
*****************************************************************************************************************************/
2930

3031
/*
@@ -79,28 +80,20 @@ NRF52Timer ITimer0(NRF_TIMER_1);
7980
// Init NRF52 timer NRF_TIMER2
8081
NRF52Timer ITimer1(NRF_TIMER_2);
8182

83+
volatile uint32_t Timer0Count = 0;
84+
volatile uint32_t Timer1Count = 0;
85+
86+
void printResult(uint32_t currTime)
87+
{
88+
Serial.printf("Time = %ld, Timer0Count = %lu, , Timer1Count = %lu\n", currTime, Timer0Count, Timer1Count);
89+
}
90+
8291
void TimerHandler0(void)
8392
{
8493
static bool toggle0 = false;
85-
static bool started = false;
86-
static uint32_t curMillis = 0;
8794

88-
if (!started)
89-
{
90-
started = true;
91-
pinMode(LED_BUILTIN, OUTPUT);
92-
}
93-
94-
#if (NRF52_TIMER_INTERRUPT_DEBUG > 0)
95-
curMillis = millis();
96-
97-
if (curMillis > TIMER0_INTERVAL_MS)
98-
{
99-
Serial.println("ITimer0: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer0));
100-
}
101-
102-
preMillisTimer0 = curMillis;
103-
#endif
95+
// Flag for checking to be sure ISR is working as SErial.print is not OK here in ISR
96+
Timer0Count++;
10497

10598
//timer interrupt toggles pin LED_BUILTIN
10699
digitalWrite(LED_BUILTIN, toggle0);
@@ -110,26 +103,10 @@ void TimerHandler0(void)
110103
void TimerHandler1(void)
111104
{
112105
static bool toggle1 = false;
113-
static bool started = false;
114-
static uint32_t curMillis = 0;
115106

116-
if (!started)
117-
{
118-
started = true;
119-
pinMode(LED_BLUE_PIN, OUTPUT);
120-
}
107+
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
108+
Timer1Count++;
121109

122-
#if (NRF52_TIMER_INTERRUPT_DEBUG > 0)
123-
curMillis = millis();
124-
125-
if (curMillis > TIMER1_INTERVAL_MS)
126-
{
127-
Serial.println("ITimer1: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer1));
128-
}
129-
130-
preMillisTimer1 = curMillis;
131-
#endif
132-
133110
//timer interrupt toggles outputPin
134111
digitalWrite(LED_BLUE_PIN, toggle1);
135112
toggle1 = !toggle1;
@@ -144,30 +121,40 @@ void setup()
144121
while (!Serial);
145122

146123
delay(100);
147-
148-
Serial.println("\nStarting Argument_None on " + String(BOARD_NAME));
149-
Serial.println("Version : " + String(NRF52_TIMER_INTERRUPT_VERSION));
150124

125+
Serial.printf("\nStarting Argument_None on %s\n", BOARD_NAME);
126+
Serial.printf("Version : v%s\n", NRF52_TIMER_INTERRUPT_VERSION);
127+
Serial.printf("CPU Frequency = %ld MHz\n", F_CPU / 1000000);
128+
151129
// Interval in microsecs
152130
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
153131
{
154-
preMillisTimer0 = millis();
155-
Serial.println("Starting ITimer0 OK, millis() = " + String(preMillisTimer0));
132+
Serial.printf("Starting ITimer0 OK, millis() = %ld\n", millis());
156133
}
157134
else
158135
Serial.println("Can't set ITimer0. Select another freq. or timer");
159136

160137
// Interval in microsecs
161138
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
162139
{
163-
preMillisTimer1 = millis();
164-
Serial.println("Starting ITimer1 OK, millis() = " + String(preMillisTimer1));
140+
Serial.printf("Starting ITimer1 OK, millis() = %ld\n", millis());
165141
}
166142
else
167143
Serial.println("Can't set ITimer1. Select another freq. or timer");
168144
}
169145

146+
#define CHECK_INTERVAL_MS 10000L
147+
170148
void loop()
171149
{
150+
static uint32_t lastTime = 0;
151+
static uint32_t currTime;
152+
153+
currTime = millis();
172154

155+
if (currTime - lastTime > CHECK_INTERVAL_MS)
156+
{
157+
printResult(currTime);
158+
lastTime = currTime;
159+
}
173160
}

0 commit comments

Comments
 (0)