| Line 36... |
Line 36... |
| 36 |
char inChar; // input character from GPS |
36 |
char inChar; // input character from GPS |
| 37 |
String dataString = ""; // concantenated string with NMEA messages and measured values |
37 |
String dataString = ""; // concantenated string with NMEA messages and measured values |
| 38 |
int coll = 0; // collons counter in NMEA messages |
38 |
int coll = 0; // collons counter in NMEA messages |
| 39 |
unsigned int i = 0; // measurements counter |
39 |
unsigned int i = 0; // measurements counter |
| 40 |
|
40 |
|
| - |
|
41 |
// 1x 100 us per 10 s UTC synchronised; 40 configuration bytes |
| - |
|
42 |
const char cmd[40]={0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0xC6, 0x51}; |
| - |
|
43 |
|
| - |
|
44 |
// GPS setup for frequency measurement (acounter) |
| - |
|
45 |
//const char cmd[40]={0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x84, 0x1E, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x40, 0x42, 0x0F, 0x00, 0xA0, 0x86, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7, 0x00, 0x00, 0x00, 0x12, 0x03}; |
| - |
|
46 |
|
| - |
|
47 |
// configure GPS |
| - |
|
48 |
void setupGPS() |
| - |
|
49 |
{ |
| - |
|
50 |
for (int n=0;n<40;n++) Serial.write(cmd[n]); |
| - |
|
51 |
} |
| - |
|
52 |
|
| - |
|
53 |
void errorLED() |
| - |
|
54 |
{ |
| - |
|
55 |
while(true) |
| - |
|
56 |
{ |
| - |
|
57 |
digitalWrite(LED4, HIGH); // turn the LED on (HIGH is the voltage level) |
| - |
|
58 |
delay(100); // wait for a second |
| - |
|
59 |
digitalWrite(LED4, LOW); // turn the LED off by making the voltage LOW |
| - |
|
60 |
delay(100); // wait for a second |
| - |
|
61 |
} |
| - |
|
62 |
} |
| 41 |
|
63 |
|
| 42 |
// function for reading $GPRMC NMEA message |
64 |
// function for reading $GPRMC NMEA message |
| 43 |
void ReadGPRMC() |
65 |
void ReadGPRMC() |
| 44 |
{ |
66 |
{ |
| 45 |
// $GPRMC,091451.00,A,4915.64143,N,01441.50397,E,0.053,,090215,,,A*74 |
67 |
// $GPRMC,091451.00,A,4915.64143,N,01441.50397,E,0.053,,090215,,,A*74 |
| Line 106... |
Line 128... |
| 106 |
while (coll < 12); // read only 7 coma separated values |
128 |
while (coll < 12); // read only 7 coma separated values |
| 107 |
} |
129 |
} |
| 108 |
|
130 |
|
| 109 |
void isr() // interrupt service routine driven from 1PPS from GPS |
131 |
void isr() // interrupt service routine driven from 1PPS from GPS |
| 110 |
{ |
132 |
{ |
| 111 |
if (++interval == 10) // 10 seconds |
133 |
//if (++interval == 10) // 10 seconds |
| 112 |
{ |
134 |
{ |
| 113 |
rise=true; |
135 |
rise=true; |
| 114 |
interval = 0; |
136 |
//interval = 0; |
| 115 |
} |
137 |
} |
| 116 |
|
138 |
|
| 117 |
} |
139 |
} |
| 118 |
|
140 |
|
| 119 |
void record() |
141 |
void record() |
| Line 184... |
Line 206... |
| 184 |
if (dataFile) |
206 |
if (dataFile) |
| 185 |
{ |
207 |
{ |
| 186 |
dataFile.println(dataString); |
208 |
dataFile.println(dataString); |
| 187 |
dataFile.close(); |
209 |
dataFile.close(); |
| 188 |
// print to the serial port too: |
210 |
// print to the serial port too: |
| 189 |
Serial.println(dataString); |
211 |
//!!!Serial.println(dataString); |
| 190 |
} |
212 |
} |
| 191 |
// if the file isn't open, pop up an error: |
213 |
// if the file isn't open, pop up an error: |
| 192 |
else { |
214 |
else { |
| 193 |
Serial.println("error opening datalog.CSV"); |
215 |
//Serial.println("error opening datalog.CSV"); |
| - |
|
216 |
errorLED(); |
| 194 |
} |
217 |
} |
| 195 |
digitalWrite(chipSelect, LOW); |
218 |
digitalWrite(chipSelect, LOW); |
| 196 |
|
219 |
|
| 197 |
|
220 |
|
| 198 |
for (int n=0; n<CHANNELS; n++) // clear recording buffer |
221 |
for (int n=0; n<CHANNELS; n++) // clear recording buffer |
| Line 211... |
Line 234... |
| 211 |
void setup() |
234 |
void setup() |
| 212 |
{ |
235 |
{ |
| 213 |
// Open serial communications and wait for port to open: |
236 |
// Open serial communications and wait for port to open: |
| 214 |
Serial.begin(9600); |
237 |
Serial.begin(9600); |
| 215 |
while (!Serial) {;} |
238 |
while (!Serial) {;} |
| 216 |
Serial.println("#cvak"); |
239 |
//Serial.println("#cvak"); |
| 217 |
|
240 |
|
| 218 |
pinMode(detector, INPUT); |
241 |
pinMode(detector, INPUT); |
| 219 |
pinMode(eint, INPUT); |
242 |
pinMode(eint, INPUT); |
| 220 |
pinMode(SDO, INPUT); |
243 |
pinMode(SDO, INPUT); |
| 221 |
pinMode(LED1, OUTPUT); |
244 |
pinMode(LED1, OUTPUT); |
| Line 223... |
Line 246... |
| 223 |
pinMode(LED3, OUTPUT); |
246 |
pinMode(LED3, OUTPUT); |
| 224 |
pinMode(LED4, OUTPUT); |
247 |
pinMode(LED4, OUTPUT); |
| 225 |
pinMode(CONV, OUTPUT); |
248 |
pinMode(CONV, OUTPUT); |
| 226 |
//pinMode(SCK, OUTPUT); |
249 |
//pinMode(SCK, OUTPUT); |
| 227 |
|
250 |
|
| - |
|
251 |
setupGPS(); |
| - |
|
252 |
|
| 228 |
Serial.print("#Initializing SD card..."); // inserting a SD Card always reset the processor and call setup |
253 |
//Serial.print("#Initializing SD card..."); // inserting a SD Card always reset the processor and call setup |
| 229 |
// make sure that the default chip select pin is set to |
254 |
// make sure that the default chip select pin is set to |
| 230 |
// output, even if you don't use it: |
255 |
// output, even if you don't use it: |
| 231 |
|
256 |
|
| 232 |
// see if the card is present and can be initialized: |
257 |
// see if the card is present and can be initialized: |
| 233 |
if (!SD.begin(chipSelect)) |
258 |
if (!SD.begin(chipSelect)) |
| 234 |
{ |
259 |
{ |
| 235 |
Serial.println("Card failed, or not present"); |
260 |
//Serial.println("Card failed, or not present"); |
| 236 |
// don't do anything more: |
261 |
// don't do anything more: |
| - |
|
262 |
errorLED(); |
| 237 |
return; |
263 |
return; |
| 238 |
} |
264 |
} |
| 239 |
Serial.println("card initialized."); |
265 |
//Serial.println("card initialized."); |
| 240 |
|
266 |
|
| 241 |
noInterrupts(); // disable all interrupts |
267 |
noInterrupts(); // disable all interrupts |
| 242 |
attachInterrupt(0, isr, RISING); // initialise interrupt from rising edge of 1PPS |
268 |
attachInterrupt(0, isr, RISING); // initialise interrupt from rising edge of 1PPS |
| 243 |
|
269 |
|
| 244 |
for (int n=0; n<CHANNELS; n++) // clear recoding buffer |
270 |
for (int n=0; n<CHANNELS; n++) // clear recoding buffer |
| Line 247... |
Line 273... |
| 247 |
channelA[n]=0; |
273 |
channelA[n]=0; |
| 248 |
} |
274 |
} |
| 249 |
|
275 |
|
| 250 |
interrupts(); // enable all interrupts |
276 |
interrupts(); // enable all interrupts |
| 251 |
|
277 |
|
| 252 |
Serial.println("#Hmmm"); |
278 |
//Serial.println("#Hmmm"); |
| 253 |
} |
279 |
} |
| 254 |
|
280 |
|
| 255 |
void loop() |
281 |
void loop() |
| 256 |
{ |
282 |
{ |
| 257 |
//byte msb=0,lsb=0; |
283 |
//byte msb=0,lsb=0; |