Rev 4487 Rev 4488
Line 25... Line 25...
25 const int chipSelect = 4; // CS is PD4 25 const int chipSelect = 4; // CS is PD4
26 const int CONV = 6; // CONV is PD6 26 const int CONV = 6; // CONV is PD6
27 const int SDO = 5; // SDO is PD5 27 const int SDO = 5; // SDO is PD5
28 const int ADSCK = 7; // SCK is PD7 28 const int ADSCK = 7; // SCK is PD7
29   29  
30 const int CHANNELS=256; // Number of channels 30 const int CHANNELS=512; // 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 char channelA[CHANNELS]; // recordig buffer
34 boolean rise=false; // flag fo recording time 34 boolean rise=false; // flag fo recording time
35 char inChar; // input character from GPS 35 char inChar; // input character from GPS
36 String dataString = ""; // concantenated string with NMEA messages and measured values 36 String dataString = ""; // concantenated string with NMEA messages and measured values
37 int coll = 0; // collons counter in NMEA messages 37 int coll = 0; // collons counter in NMEA messages
38 unsigned int num = 0; // measurements counter 38 unsigned int num = 0; // measurements counter
Line 174... Line 174...
174 break; 174 break;
175 } 175 }
176 } 176 }
177 177
178 dataString = ""; // make a string for assembling the data to log 178 dataString = ""; // make a string for assembling the data to log
-   179 //*
179 //!!!ReadGPRMC(); // read NMEA sentences from GPS 180 ReadGPRMC(); // read NMEA sentences from GPS
180 //!!!ReadGPGGA(); 181 ReadGPGGA();
-   182 //*/
181 // make a string for assembling the data to log: 183 // make a string for assembling the data to log:
182 dataString += String(num++); 184 dataString += String(num++);
183 //dataString += ","; 185 //dataString += ",";
184 //Serial.print(dataString); 186 Serial.print(dataString);
185 187
186 // open the file. note that only one file can be open at a time, 188 // open the file. note that only one file can be open at a time,
187 // so you have to close this one before opening another. 189 // so you have to close this one before opening another.
188 digitalWrite(chipSelect, HIGH); 190 digitalWrite(chipSelect, HIGH);
189 char fileNameCharArray[filename.length()]; 191 char fileNameCharArray[filename.length()];
Line 200... Line 202...
200 else 202 else
201 { 203 {
202 errorLED(); 204 errorLED();
203 } 205 }
204   206  
205 for (int i=0; i<(256/32); i++) 207 for (int i=0; i<(CHANNELS/32); i++)
206 { 208 {
207 dataString = ""; 209 dataString = "";
208 for (int n=0; n<32; n++) 210 for (int n=0; n<32; n++)
209 { 211 {
210 dataString += ","; 212 dataString += ",";
Line 237... Line 239...
237 } 239 }
238   240  
239 241
240 digitalWrite(chipSelect, LOW); 242 digitalWrite(chipSelect, LOW);
241   243  
242 //!!! control print 244 //*!!! control print
243 //TODO print to I2C display 245 //TODO print to I2C display
-   246 Serial.print(":");
244 Serial.print(count); 247 Serial.print(count);
245 Serial.print("*"); 248 Serial.print("*");
246 for(int j=0;j<256;j++) {Serial.print(channelA[j]); Serial.print(' ');} 249 for(int j=0;j<36;j++) {Serial.print(channelA[j]); Serial.print(' ');}
247 Serial.println(); 250 Serial.println();
248   251 //*/
249   252  
250 for (int n=0; n<CHANNELS; n++) // clear recording buffer 253 for (int n=0; n<CHANNELS; n++) // clear recording buffer
251 { 254 {
252 channelA[n]=0; 255 channelA[n]=0;
253 } 256 }
Line 305... Line 308...
305 //Serial.println("#Hmmm"); 308 //Serial.println("#Hmmm");
306 } 309 }
307   310  
308 void loop() 311 void loop()
309 { 312 {
310 //byte msb=0,lsb=0; -  
311 unsigned int val; 313 unsigned int val;
312 unsigned int treshold = 1; 314 unsigned int treshold = 1;
313 315
314 count = 0; 316 count = 0;
315 while (true) 317 while (true)
316 { 318 {
317 //count++; 319 count++;
318 digitalWrite(ADSCK, HIGH); 320 digitalWrite(ADSCK, HIGH);
319 digitalWrite(CONV, HIGH); // start AD conversion 321 digitalWrite(CONV, HIGH); // start AD conversion
320 digitalWrite(ADreset, HIGH); // reset Peack Detector 322 digitalWrite(ADreset, HIGH); // reset Peack Detector
321 digitalWrite(CONV, LOW); // start SPI 323 digitalWrite(CONV, LOW); // start SPI
322 digitalWrite(ADreset, LOW); // start Peack Detector 324 digitalWrite(ADreset, LOW); // start Peack Detector
323 val=0; 325 val=0;
324 for (int p=0;p<16;p++) 326 for (int p=0;p<9;p++)
325 { 327 {
326 digitalWrite(ADSCK, LOW); // 1 CLK 328 digitalWrite(ADSCK, LOW); // 1 CLK
327 digitalWrite(ADSCK, HIGH); 329 digitalWrite(ADSCK, HIGH);
328 val= (val<<1)|digitalRead(SDO); 330 val= (val<<1)|digitalRead(SDO);
329 } 331 }
330 digitalWrite(ADSCK, LOW); // 1 CLK 332 digitalWrite(ADSCK, LOW); // 1 CLK
331   333
332 if ((val > treshold) && (count < (CHANNELS-1))) channelA[count++] = val; 334 if (channelA[val] < 255) channelA[val]++;
333   335  
334 if (rise) // recording time is now 336 if (rise) // recording time is now
335 { 337 {
336 record(); // make record 338 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); -  
341 digitalWrite(ADreset, HIGH); // reset Peack Detector 339 digitalWrite(ADreset, HIGH); // reset Peack Detector
342 rise = false; 340 rise = false;
343 count = 0; 341 count = 0;
344 digitalWrite(ADreset, LOW); // start Peack Detector 342 digitalWrite(ADreset, LOW); // start Peack Detector
345 continue; // skip this interrupted impuls 343 continue; // skip this interrupted impuls