Rev 4136 Rev 4137
Line 11... Line 11...
11 ** ADCmonoSPI/SDO - pin PD5 11 ** ADCmonoSPI/SDO - pin PD5
12 ** ADCmonoSPI/SCK - pin PD7 shared with LED4 12 ** ADCmonoSPI/SCK - pin PD7 shared with LED4
13 */ 13 */
14   14  
15 #include <SD.h> 15 #include <SD.h>
16 //#include <SPI.h> -  
17   -  
18   16  
19 const String filename = "log.csv "; // filename for logfile 17 const String filename = "log.csv "; // filename for logfile
20   18  
21 const int detector=3; // PD3 19 const int detector=3; // PD3
22 const int eint=2; // PD2 20 const int eint=2; // PD2
Line 228... Line 226...
228 //pinMode(SCK, OUTPUT); 226 //pinMode(SCK, OUTPUT);
229   227  
230 Serial.print("#Initializing SD card..."); // inserting a SD Card always reset the processor and call setup 228 Serial.print("#Initializing SD card..."); // inserting a SD Card always reset the processor and call setup
231 // make sure that the default chip select pin is set to 229 // make sure that the default chip select pin is set to
232 // output, even if you don't use it: 230 // output, even if you don't use it:
233 //pinMode(10, OUTPUT); // PB2 -  
234 //pinMode(LED, OUTPUT); -  
235   231  
236 // see if the card is present and can be initialized: 232 // see if the card is present and can be initialized:
237 if (!SD.begin(chipSelect)) 233 if (!SD.begin(chipSelect))
238 { 234 {
239 Serial.println("Card failed, or not present"); 235 Serial.println("Card failed, or not present");
Line 266... Line 262...
266 unsigned int duration=0; // pulse duration counter 262 unsigned int duration=0; // pulse duration counter
267 263
268 while (!digitalRead(detector)) // waiting for pulse 264 while (!digitalRead(detector)) // waiting for pulse
269 { 265 {
270 if (rise) break; 266 if (rise) break;
271 //digitalWrite(CONV, LOW); -  
272 digitalWrite(CONV, HIGH); // start AD conversion 267 digitalWrite(CONV, HIGH); // start AD conversion
273 } 268 }
274 while (digitalRead(detector)) 269 while (digitalRead(detector))
275 { 270 {
276 if (rise) break; 271 if (rise) break;
277 if (duration < (CHANNELS-1)) duration++; 272 if (duration < (CHANNELS-1)) duration++;
278 } 273 }
279   274  
-   275 digitalWrite(ADSCK, HIGH);
280 digitalWrite(CONV, LOW); // start SPI 276 digitalWrite(CONV, LOW); // start SPI
281 val=0; 277 val=0;
282 for (int p=0;p<8;p++) 278 for (int p=0;p<8;p++)
283 { 279 {
284 digitalWrite(ADSCK, LOW); // 1 CLK 280 digitalWrite(ADSCK, LOW); // 1 CLK
285 digitalWrite(ADSCK, HIGH); 281 digitalWrite(ADSCK, HIGH);
286 val= (val<<1)|digitalRead(SDO); 282 val= (val<<1)|digitalRead(SDO);
287 } 283 }
288 //val = 140 - val; -  
289 //msb = SPI.transfer(0x00); // read ADC -  
290 //lsb = SPI.transfer(0x00); -  
291 //digitalWrite(CONV, HIGH); // stop SPI 284 digitalWrite(ADSCK, LOW); // 1 CLK
292 //val = (msb<<8) + lsb; -  
293 //Serial.println(val); -  
294   285  
295 if (rise) // recording time is now 286 if (rise) // recording time is now
296 { 287 {
297 record(); // make record 288 record(); // make record
298 rise = false; 289 rise = false;