forked from tenbaht/sduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer2.c
More file actions
135 lines (111 loc) · 1.88 KB
/
timer2.c
File metadata and controls
135 lines (111 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* test timer4: show the value for millis() over time and compare
* different impementations for the delay() function
*/
#include "Arduino.h"
#include "Serial.h"
uint32_t prev=0;
void mydelay(unsigned long ms)
#if 1
{
// 88 bytes
uint16_t start;
start = (uint16_t) micros();
while (ms > 0) {
while ( (ms > 0) && (((uint16_t)micros() - start) >= 1000)) {
ms--;
start += 1000;
}
}
}
#endif
#if 0
{
// 92 bytes
uint16_t start, now;
start = (uint16_t) micros();
while (ms > 0) {
now = (uint16_t) micros();
while ( (ms > 0) && ((now - start) >= 1000)) {
ms--;
start += 1000;
}
}
}
#endif
#if 0
{
// 100 bytes
uint16_t start, passed;
start = (uint16_t) micros();
while (ms > 0) {
passed = (uint16_t) micros() - start;
while ( (ms > 0) && (passed >= 1000)) {
ms--;
passed -= 1000;
start += 1000;
}
}
}
#endif
#if 0
{
// 159 bytes
uint32_t start, passed;
start = micros();
while (ms > 0) {
passed = micros() - start;
while ( (ms > 0) && (passed >= 1000)) {
ms--;
passed -= 1000;
start += 1000;
}
}
}
#endif
#if 0
{
// 131 bytes
uint32_t start = micros();
while (ms > 0) {
while ( (ms > 0) && ((micros() - start) >= 1000)) {
ms--;
start += 1000;
}
}
}
#endif
#if 0
{
// 131 bytes
uint32_t start = micros();
while (ms > 0) {
while ( ms > 0 && (micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
}
#endif
void setup(void)
{
Serial_begin(115200);
Serial_print_s("testing delay functions.\n"
"Code size of current impementation: ");
Serial_println_u((uint16_t)setup - (uint16_t)mydelay);
}
void loop (void)
{
uint32_t now;
now = millis();
Serial_print_s("millis()=");
Serial_print_u(now);
Serial_print_s("\tdelta=");
Serial_print_u(now-prev);
Serial_print_s("\tmicros()=");
Serial_print_u(micros());
Serial_print_s("\tTIM4_CNTR=");
Serial_println_u(TIM4->CNTR);
prev = now;
mydelay(1000);
}