Skip to content

Commit 3f856f8

Browse files
committed
Fix undefined variables.
Restrict histogram range to RANGE channels.
1 parent 9471811 commit 3f856f8

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

fw/AIRDOS04/AIRDOS04.ino

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#define XSTR(s) STR(s)
1616
#define STR(s) #s
1717

18+
19+
#define RANGE 25 // histogram range
20+
#define EVENTS 256 // maximal number of single events detection in memory
1821
#define CHANNELS 1024 // number of channels in the buffer for histogram
1922

2023
String FWversion = XSTR(MAJOR)"."XSTR(MINOR)"."XSTR(GHRELEASE)"-"XSTR(GHBUILD)"-"XSTR(GHBUILDTYPE);
@@ -108,6 +111,9 @@ String filename = "";
108111
uint16_t fn;
109112
uint16_t count = 0;
110113
boolean SDinserted = true;
114+
uint32_t hit_time[EVENTS]; // time of events
115+
uint8_t hit_time_s100[EVENTS];
116+
uint16_t hit_channel[EVENTS]; // energy of events
111117
uint8_t histogram[CHANNELS];
112118
uint8_t ADCconf1;
113119
uint8_t ADCconf2;
@@ -396,6 +402,7 @@ void logHits() { // Hits out
396402
digitalWrite(SDpower, LOW); // SD card power off
397403
delay(1);
398404
hits_interval = 0;
405+
hit_count = 0
399406
}
400407

401408
// Data out
@@ -995,6 +1002,8 @@ void loop()
9951002
SPI.transfer16(0x0000);
9961003
digitalWrite(DRESET, HIGH);
9971004

1005+
uint16_t hit_count = 0; // clear events
1006+
9981007
store = 0;
9991008
batt = 0;
10001009
env = 0;
@@ -1110,13 +1119,11 @@ void loop()
11101119
if (adcVal>320) digitalWrite(BUZZER, HIGH); // buzzer click on ADC conversion.
11111120
#endif
11121121

1113-
adcVal >>= 6;
1114-
if (histogram[adcVal]<255) histogram[adcVal]++;
1115-
digitalWrite(DRESET, HIGH);
1122+
adcVal >>= 6; // squash to 10 bit value
11161123

1117-
if (adcVal > RANGE)
1124+
if (adcVal < RANGE)
11181125
{
1119-
buffer[adcVal]++;
1126+
if (histogram[adcVal]<255) histogram[adcVal]++; // increment histogram bin count and avoid overflow
11201127
}
11211128
else
11221129
{
@@ -1125,12 +1132,12 @@ void loop()
11251132
readRTC();
11261133

11271134
hit_time[hit_count] = tm;
1128-
hit_time_s100[hit_count]=tm_s100;
1135+
hit_time_s100[hit_count]=tm_s100;
11291136
hit_channel[hit_count] = adcVal;
11301137
}
1131-
hit_count++;
11321138
logHits();
11331139
}
1140+
digitalWrite(DRESET, HIGH);
11341141

11351142
#ifdef RADIATION_CLICK
11361143
digitalWrite(BUZZER, LOW);

0 commit comments

Comments
 (0)