@@ -339,6 +339,65 @@ void BattOut()
339
339
delay (1 );
340
340
}
341
341
342
+ void logHits () { // Hits out
343
+
344
+ digitalWrite (SDpower, HIGH); // SD card power on
345
+ digitalWrite (SPI_MUX_SEL, LOW); // SDcard
346
+
347
+ // make a string for assembling the data to log:
348
+ String dataString = " $HITS," ;
349
+
350
+ dataString += String (hit_count);
351
+
352
+ if (hit_count > EVENTS) hit_count = EVENTS;
353
+
354
+ for (uint16_t n=0 ; n<hit_count; n++)
355
+ {
356
+ dataString += " ," ;
357
+ dataString += String (hit_time[n]);
358
+ dataString += " ." ;
359
+ dataString += String (hit_time_s100[n]);
360
+ dataString += " ," ;
361
+ dataString += String (hit_channel[n]);
362
+ }
363
+
364
+ if (SDinserted)
365
+ {
366
+ // make sure that the default chip select pin is set to output
367
+ // see if the card is present and can be initialized:
368
+ if (!SD.begin (SS))// , SPI_HALF_SPEED))
369
+ {
370
+ Serial1.println (" #SD init false" );
371
+ SDinserted = false ;
372
+ // don't do anything more:
373
+ }
374
+ else
375
+ {
376
+ // open the file. note that only one file can be open at a time,
377
+ // so you have to close this one before opening another.
378
+ File dataFile = SD.open (filename, FILE_WRITE);
379
+
380
+ // if the file is available, write to it:
381
+ if (dataFile)
382
+ {
383
+ dataFile.println (dataString); // write to SDcard (800 ms)
384
+ dataFile.close ();
385
+ }
386
+ // if the file isn't open, pop up an error:
387
+ else
388
+ {
389
+ Serial.println (" #SD false" );
390
+ SDinserted = false ;
391
+ }
392
+ }
393
+ digitalWrite (SS, HIGH); // Disable SD card
394
+ }
395
+ digitalWrite (SPI_MUX_SEL, HIGH); // ADC
396
+ digitalWrite (SDpower, LOW); // SD card power off
397
+ delay (1 );
398
+ hits_interval = 0 ;
399
+ }
400
+
342
401
// Data out
343
402
void DataOut ()
344
403
{
@@ -949,6 +1008,7 @@ void loop()
949
1008
store = 0 ;
950
1009
batt++;
951
1010
env++;
1011
+ hits_interval++;
952
1012
953
1013
digitalWrite (LED2, digitalRead (ACONNECT));
954
1014
if (digitalRead (ACONNECT)) // Analog part is disconnected?
@@ -1022,6 +1082,13 @@ void loop()
1022
1082
BattOut ();
1023
1083
};
1024
1084
1085
+ if (hits_interval >= 30 *6 ) // Hits output at the least every 30 minutes
1086
+ {
1087
+ hits_interval = 0 ;
1088
+ logHits ();
1089
+ };
1090
+
1091
+
1025
1092
// dummy conversion
1026
1093
digitalWrite (DSET, HIGH);
1027
1094
digitalWrite (DRESET, LOW); // L on CONV
@@ -1047,6 +1114,24 @@ void loop()
1047
1114
if (histogram[adcVal]<255 ) histogram[adcVal]++;
1048
1115
digitalWrite (DRESET, HIGH);
1049
1116
1117
+ if (adcVal > RANGE)
1118
+ {
1119
+ buffer[adcVal]++;
1120
+ }
1121
+ else
1122
+ {
1123
+ if (hit_count < EVENTS)
1124
+ {
1125
+ readRTC ();
1126
+
1127
+ hit_time[hit_count] = tm;
1128
+ hit_time_s100[hit_count]=tm_s100;
1129
+ hit_channel[hit_count] = adcVal;
1130
+ }
1131
+ hit_count++;
1132
+ logHits ();
1133
+ }
1134
+
1050
1135
#ifdef RADIATION_CLICK
1051
1136
digitalWrite (BUZZER, LOW);
1052
1137
#endif
0 commit comments