質問編集履歴
3
コードの概要を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,6 +28,10 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
+
GPIO1,GPIO2でEVENT,OVERFLOWの2つの割り込みに待機して、割り込みが発生したらそれぞれのカウントを増やします。
|
32
|
+
|
33
|
+
また、EVENT割り込みが発生した際はGPIO3からGPIO10より、2進数8bitのデータを読み込み、表示します。
|
34
|
+
|
31
35
|
```c++
|
32
36
|
|
33
37
|
#include <stdio.h>
|
2
コードを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
RaspberryPiのGPIO でパルスを受け取り、コールバック関数(gpioSetAlertFunc)を用いてカウントするプログラムを作成しています。
|
4
4
|
|
5
|
-
使用言語は C
|
5
|
+
使用言語は C++、使用ライブラリは pigpio です。
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -28,12 +28,296 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
|
31
|
+
```c++
|
32
|
+
|
33
|
+
#include <stdio.h>
|
34
|
+
|
35
|
+
#include <stdlib.h>
|
36
|
+
|
37
|
+
#include <pigpio.h>
|
38
|
+
|
39
|
+
#include <unistd.h>
|
40
|
+
|
41
|
+
#include <time.h>
|
42
|
+
|
43
|
+
#include <string>
|
44
|
+
|
45
|
+
#define locate(x,y) printf("\033[%d;%dH",x,y)
|
46
|
+
|
47
|
+
#define clr printf("\033[2J")
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
unsigned long EventPulse = 0x00000000;
|
54
|
+
|
55
|
+
int ETCounter[256];
|
56
|
+
|
57
|
+
int OverFlow;
|
58
|
+
|
59
|
+
int Event;
|
60
|
+
|
61
|
+
char date[64];
|
62
|
+
|
63
|
+
unsigned char num = 0x00;
|
64
|
+
|
65
|
+
int ret1;
|
66
|
+
|
67
|
+
int ret2;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// callback1
|
72
|
+
|
73
|
+
void CallbackEvent(int GPIO, int level, uint32_t tick){
|
74
|
+
|
75
|
+
char buffer[50];
|
76
|
+
|
77
|
+
sprintf(buffer,"%d%d%d%d%d%d%d%d",gpioRead(3),gpioRead(4),gpioRead(5),gpioRead(6),gpioRead(7),gpioRead(8),gpioRead(9),gpioRead(10));
|
78
|
+
|
79
|
+
int num=strtol(buffer,NULL,2);
|
80
|
+
|
81
|
+
ETCounter[num]++;
|
82
|
+
|
83
|
+
Event++;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
locate(9,1);
|
90
|
+
|
91
|
+
for(int i=0;i<=255;i=i+16){
|
92
|
+
|
93
|
+
for(int j=0;j<=15;j++){
|
94
|
+
|
95
|
+
printf("%4d",ETCounter[i+j]);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
printf("\n");
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
//Event
|
104
|
+
|
105
|
+
locate(26,4);
|
106
|
+
|
107
|
+
printf("Event : %d",Event);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
//callback2
|
116
|
+
|
117
|
+
void CallbackOverFlow(int GPIO, int level, uint32_t tick){
|
118
|
+
|
119
|
+
OverFlow++;
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
//OverFlow
|
126
|
+
|
127
|
+
locate(28,4);
|
128
|
+
|
129
|
+
printf("OverFlow : %d",OverFlow);
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
//main
|
146
|
+
|
147
|
+
int main(){
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
if(gpioInitialise()<0){
|
152
|
+
|
153
|
+
return 1;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
gpioSetMode(1,PI_INPUT);
|
158
|
+
|
159
|
+
gpioSetMode(2,PI_INPUT);
|
160
|
+
|
161
|
+
gpioSetMode(3,PI_INPUT);
|
162
|
+
|
163
|
+
gpioSetMode(4,PI_INPUT);
|
164
|
+
|
165
|
+
gpioSetMode(5,PI_INPUT);
|
166
|
+
|
167
|
+
gpioSetMode(6,PI_INPUT);
|
168
|
+
|
169
|
+
gpioSetMode(7,PI_INPUT);
|
170
|
+
|
171
|
+
gpioSetMode(8,PI_INPUT);
|
172
|
+
|
173
|
+
gpioSetMode(9,PI_INPUT);
|
174
|
+
|
175
|
+
gpioSetMode(10,PI_INPUT);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
gpioSetPullUpDown(1,PI_PUD_DOWN);
|
180
|
+
|
181
|
+
gpioSetPullUpDown(2,PI_PUD_DOWN);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
callback1=gpioSetAlertFunc(1,CallbackEvent);
|
188
|
+
|
189
|
+
callback2=gpioSetAlertFunc(2,CallbackOverFlow);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
while(1){
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
clr;
|
200
|
+
|
201
|
+
locate(30,5);
|
202
|
+
|
203
|
+
printf("A : END OBSERVATION");
|
204
|
+
|
205
|
+
//Counter
|
206
|
+
|
207
|
+
locate(9,1);
|
208
|
+
|
209
|
+
for(int i=0;i<=255;i=i+16){
|
210
|
+
|
211
|
+
for(int j=0;j<=15;j++){
|
212
|
+
|
213
|
+
printf("%4d",ETCounter[i+j]);
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
printf("\n");
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
//Event
|
222
|
+
|
223
|
+
locate(26,4);
|
224
|
+
|
225
|
+
printf("Event : %d",Event);
|
226
|
+
|
227
|
+
//OverFlow
|
228
|
+
|
229
|
+
locate(28,4);
|
230
|
+
|
231
|
+
printf("OverFlow : %d",OverFlow);
|
232
|
+
|
233
|
+
//GetTime
|
234
|
+
|
235
|
+
locate(5,3);
|
236
|
+
|
237
|
+
time_t t = time(NULL);
|
238
|
+
|
239
|
+
strftime(date, sizeof(date), "%Y %m %d %H %M %S", localtime(&t));
|
240
|
+
|
241
|
+
printf("STARTTIME = %s\n\n", date);
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
int a=getchar();
|
246
|
+
|
247
|
+
if(a =='A'){
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
locate(30,5);
|
252
|
+
|
253
|
+
printf("A : END OBSERVATION");
|
254
|
+
|
255
|
+
//Counter
|
256
|
+
|
257
|
+
locate(9,1);
|
258
|
+
|
259
|
+
for(int i=0;i<=255;i=i+16){
|
260
|
+
|
261
|
+
for(int j=0;j<=15;j++){
|
262
|
+
|
263
|
+
printf("%4d",ETCounter[i+j]);
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
printf("\n");
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
//Event
|
272
|
+
|
273
|
+
locate(26,4);
|
274
|
+
|
275
|
+
printf("Event : %d",Event);
|
276
|
+
|
277
|
+
//OverFlow
|
278
|
+
|
279
|
+
locate(28,4);
|
280
|
+
|
281
|
+
printf("OverFlow : %d",OverFlow);
|
282
|
+
|
283
|
+
//GetTime
|
284
|
+
|
285
|
+
locate(6,3);
|
286
|
+
|
287
|
+
time_t t = time(NULL);
|
288
|
+
|
289
|
+
strftime(date, sizeof(date), "%Y %m %d %H %M %S", localtime(&t));
|
290
|
+
|
291
|
+
printf("ENDTIME = %s\n\n", date);
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
gpioTerminate();
|
296
|
+
|
297
|
+
return 0;
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
```
|
32
316
|
|
33
317
|
変更不可な部分
|
34
318
|
|
35
319
|
・RaspberryPi
|
36
320
|
|
37
|
-
・C
|
321
|
+
・C++
|
38
322
|
|
39
323
|
・パルス幅600ns
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,4 +36,4 @@
|
|
36
36
|
|
37
37
|
・C言語
|
38
38
|
|
39
|
-
・パルス幅600n
|
39
|
+
・パルス幅600ns
|