HI,
I am building a datalogger using a GPS and writing it as a csv file on an SD card.
The whole program executes in the loop() , where it:
- Reads button state
- Reads serial data from the GPS (9600 baud) via Softwareserial
- Writes a line to the csv file (only every 200ms)
But I am having a bit of an issue with dropped chars on the GPS serial, so I decided to see how long I was using in the write csv function as I suspected that was the culprit.
But the timings for the csv write function varies quite a bit, but in a pattern. Following is the ms it takes to call the function (5 executions pr. second):
166
165
165
165
165
165
164
164
160
149
148
142
136
132
128
125
115
107
105
104
100
21
20
19
20
20
19
22
20
19
52
21
20
19
19
20
19
22
20
20
19
19
20
19
19
20
20
22
19
20
19
19
24
20
19
87
155
Dropped bad nmea frame: $GPGGA,211652.600,5700.7072,N,01002.3501,E,1,9,0.99,-3.9,M,42.5
136
Dropped bad nmea frame: $GPGGA,211652.800,5700.7072,N,01002.3501,E,1,9,0.99,-3.9,M,42.54,031213,,,A*68
135
Dropped bad nmea frame: $GPGGA,211653.000,5700.7072,N,01002.3501,E,1,9,0.99,-3.9,M,42.54,031213,,,A*61
164
164
164
165
164
166
165
169
166
165
165
165
165
155
156
148
140
137
132
131
124
117
115
113
107
102
101
94
92
95
20
19
20
19
19
20
23
19
19
20
19
19
20
20
19
19
23
19
19
The above pattern repeats itself, taking ~160ms, then falling to ~20ms, then rising again resulting in dropped characters on the serial interface.
So it seems that something is slowing my code down and making me miss characters on the serial interface.
The csv function should be quite static in its timing, it just concats some strings together (using char buffers), and writes a line to the SD card.
Any ideas on why the timing is varying to much? Is the CPU off doing something else other than executing my code?