Rev 4485 Rev 4487
Line 29... Line 29...
29   29  
30 const int CHANNELS=256; // Number of channels 30 const int CHANNELS=256; // Number of channels
31   31  
32 //unsigned int channelT[CHANNELS]; // recordig buffer 32 //unsigned int channelT[CHANNELS]; // recordig buffer
33 unsigned int channelA[CHANNELS]; // recordig buffer 33 unsigned int channelA[CHANNELS]; // recordig buffer
34 int interval=0; // seconds counter -  
35 boolean rise=false; // flag fo recording time 34 boolean rise=false; // flag fo recording time
36 char inChar; // input character from GPS 35 char inChar; // input character from GPS
37 String dataString = ""; // concantenated string with NMEA messages and measured values 36 String dataString = ""; // concantenated string with NMEA messages and measured values
38 int coll = 0; // collons counter in NMEA messages 37 int coll = 0; // collons counter in NMEA messages
39 unsigned int num = 0; // measurements counter 38 unsigned int num = 0; // measurements counter
Line 130... Line 129...
130 while (coll < 12); // read only 7 coma separated values 129 while (coll < 12); // read only 7 coma separated values
131 } 130 }
132   131  
133 void isr() // interrupt service routine driven from 1PPS from GPS 132 void isr() // interrupt service routine driven from 1PPS from GPS
134 { 133 {
135 //if (++interval == 10) // 10 seconds -  
136 { 134 {
137 rise=true; 135 rise=true;
138 //interval = 0; -  
139 } 136 }
140   137  
141 } 138 }
142   139  
143 void record() 140 void record()
144 { 141 {
145 for (int c=129; c<CHANNELS; c++) 142 for (int c=67; c<CHANNELS; c++)
146 { 143 {
147 if (channelA[c]>0) 144 if (channelA[c]>0)
148 { 145 {
149 digitalWrite(LED4, HIGH); // LED 16-64 146 digitalWrite(LED4, HIGH); // LED 16-64
150 break; 147 break;
151 } 148 }
152 } 149 }
153   150  
154 for (int c=65; c<128; c++) 151 for (int c=33; c<64; c++)
155 { 152 {
156 if (channelA[c]>0) 153 if (channelA[c]>0)
157 { 154 {
158 digitalWrite(LED3, HIGH); // LED 9-16 155 digitalWrite(LED3, HIGH); // LED 9-16
159 break; 156 break;
160 } 157 }
161 } 158 }
162   159  
163 for (int c=33; c<64; c++) 160 for (int c=17; c<32; c++)
164 { 161 {
165 if (channelA[c]>0) 162 if (channelA[c]>0)
166 { 163 {
167 digitalWrite(LED2, HIGH); // LED 5-8 164 digitalWrite(LED2, HIGH); // LED 5-8
168 break; 165 break;
169 } 166 }
170 } 167 }
171   168  
172 for (int c=10; c<32; c++) 169 for (int c=0; c<16; c++)
173 { 170 {
174 if (channelA[c]>0) 171 if (channelA[c]>0)
175 { 172 {
176 digitalWrite(LED1, HIGH); // LED 0-4 173 digitalWrite(LED1, HIGH); // LED 0-4
177 break; 174 break;
178 } 175 }
179 } 176 }
180 177
181 dataString = ""; // make a string for assembling the data to log 178 dataString = ""; // make a string for assembling the data to log
182 ReadGPRMC(); // read NMEA sentences from GPS 179 //!!!ReadGPRMC(); // read NMEA sentences from GPS
183 ReadGPGGA(); 180 //!!!ReadGPGGA();
184 // make a string for assembling the data to log: 181 // make a string for assembling the data to log:
185 dataString += String(num++); 182 dataString += String(num++);
186 //dataString += ","; 183 //dataString += ",";
187 //Serial.print(dataString); 184 //Serial.print(dataString);
188 185
Line 222... Line 219...
222 } 219 }
223 else 220 else
224 { 221 {
225 errorLED(); 222 errorLED();
226 } 223 }
-   224 }
227   225  
-   226 dataString = ",";
-   227 dataString += String(count);
228 dataFile = SD.open(fileNameCharArray, FILE_WRITE); 228 dataFile = SD.open(fileNameCharArray, FILE_WRITE);
229 if (dataFile) 229 if (dataFile)
230 { 230 {
231 dataFile.println(); 231 dataFile.println(dataString);
232 dataFile.close(); 232 dataFile.close();
233 } 233 }
234 else 234 else
235 { 235 {
236 errorLED(); 236 errorLED();
237 } 237 }
238   238  
239 } -  
240 239
241 digitalWrite(chipSelect, LOW); 240 digitalWrite(chipSelect, LOW);
242   241  
-   242 //!!! control print
-   243 //TODO print to I2C display
-   244 Serial.print(count);
-   245 Serial.print("*");
-   246 for(int j=0;j<256;j++) {Serial.print(channelA[j]); Serial.print(' ');}
-   247 Serial.println();
-   248  
-   249  
243 for (int n=0; n<CHANNELS; n++) // clear recording buffer 250 for (int n=0; n<CHANNELS; n++) // clear recording buffer
244 { 251 {
245 //channelT[n]=0; -  
246 channelA[n]=0; 252 channelA[n]=0;
247 } 253 }
248   254  
249 //!!! -  
250 Serial.print(count); -  
251 for(int j=0;j<256;j++) {Serial.print(channelA[j]); Serial.print(' ');} -  
252 Serial.println(); -  
253   -  
254 digitalWrite(LED1, LOW); // LED OFF 255 digitalWrite(LED1, LOW); // LED OFF
255 digitalWrite(LED2, LOW); // LED OFF 256 digitalWrite(LED2, LOW); // LED OFF
256 digitalWrite(LED3, LOW); // LED OFF 257 digitalWrite(LED3, LOW); // LED OFF
257 digitalWrite(LED4, LOW); // LED OFF 258 digitalWrite(LED4, LOW); // LED OFF
258   259  
Line 305... Line 306...
305 } 306 }
306   307  
307 void loop() 308 void loop()
308 { 309 {
309 //byte msb=0,lsb=0; 310 //byte msb=0,lsb=0;
310 unsigned char val; 311 unsigned int val;
-   312 unsigned int treshold = 1;
311   313
-   314 count = 0;
312 while (true) 315 while (true)
313 { 316 {
314 count++; 317 //count++;
315 digitalWrite(ADSCK, HIGH); 318 digitalWrite(ADSCK, HIGH);
316 digitalWrite(CONV, HIGH); // start AD conversion 319 digitalWrite(CONV, HIGH); // start AD conversion
317 digitalWrite(ADreset, HIGH); // reset Peack Detector 320 digitalWrite(ADreset, HIGH); // reset Peack Detector
318 digitalWrite(CONV, LOW); // start SPI 321 digitalWrite(CONV, LOW); // start SPI
319 digitalWrite(ADreset, LOW); // start Peack Detector 322 digitalWrite(ADreset, LOW); // start Peack Detector
320 val=0; 323 val=0;
321 for (int p=0;p<8;p++) 324 for (int p=0;p<16;p++)
322 { 325 {
323 digitalWrite(ADSCK, LOW); // 1 CLK 326 digitalWrite(ADSCK, LOW); // 1 CLK
324 digitalWrite(ADSCK, HIGH); 327 digitalWrite(ADSCK, HIGH);
325 val= (val<<1)|digitalRead(SDO); 328 val= (val<<1)|digitalRead(SDO);
326 } 329 }
327 digitalWrite(ADSCK, LOW); // 1 CLK 330 digitalWrite(ADSCK, LOW); // 1 CLK
328   331  
329 channelA[val]++; 332 if ((val > treshold) && (count < (CHANNELS-1))) channelA[count++] = val;
330   333  
331 if (rise) // recording time is now 334 if (rise) // recording time is now
332 { 335 {
333 record(); // make record 336 record(); // make record
-   337 if ((count == 255) && (treshold < 0x8000)) treshold <<= 1;
-   338 if ((count == 0) && (treshold > 1)) treshold >>= 1;
-   339 Serial.println(count);
-   340 Serial.println(treshold);
334 digitalWrite(ADreset, HIGH); // reset Peack Detector 341 digitalWrite(ADreset, HIGH); // reset Peack Detector
335 rise = false; 342 rise = false;
336 count = 0; 343 count = 0;
337 digitalWrite(ADreset, LOW); // start Peack Detector 344 digitalWrite(ADreset, LOW); // start Peack Detector
338 continue; // skip this interrupted impuls 345 continue; // skip this interrupted impuls