Go Down

Topic: Data logging using ChibiOS - weird error after 27 entries in FIFO buffer (Read 12 times) previous topic - next topic

jm7501

I'm trying to write a sketch that will log data from 7 sensors every 2ms, timestamp the observations, and then write them to either the Serial monitor or (ultimately) an SD card. However, I've run into an odd error a few times now. I'm using a fifo buffer to handle the SD writing, and whenever this buffer fills to 27 - EXACTLY 27 - records, everything falls apart. It doesn't matter how long it takes me to get to 27 records, so it isn't the run time. Here is the Serial output for an example (with my annotation):

Input mouse name (Waiting for user input)
Filename: *** (User input)

Type Start to Start (Waiting for user input)
Delay, Sensor 1, Sensor 2, Sensor 3, Sensor 4, Sensor 5, Sensor 6, Sensor 7, Time, Error (Header)
0 (FIFO head counter for debugging)
2162416,1,1,1,1,1,1,1,2,0 (Delay since last sample in micros, state of each sensor, time since start in ms, and number of errors)
1 (FIFO head counter)
1 (FIFO tail)
4050672,1,0,1,1,1,1,1,1890,0
2
2
4169456,1,1,1,1,1,1,1,2009,0
3
3
4191984,1,0,1,1,1,1,1,2032,0
4
4
4439796,1,0,0,1,1,1,1,2280,0
5
5
4593392,1,1,0,1,1,1,1,2433,0
6
6
4693748,1,1,0,0,1,1,1,2534,0
7
7
4828912,1,1,1,0,1,1,1,2669,0
8
8
4951796,1,1,1,0,0,1,1,2792,0
9
9
5160688,1,1,1,1,0,1,1,3000,0
10
10
5795616,1,1,1,0,0,1,1,3635,0
11
11
5943072,1,1,1,0,1,1,1,3783,0
12
12
5994272,1,1,0,0,1,1,1,3834,0
13
13
6024992,1,1,1,0,1,1,1,3865,0
14
14
6035232,1,1,0,0,1,1,1,3875,0
15
15
6145824,1,1,0,1,1,1,1,3986,0
16
16
6233888,1,0,0,1,1,1,1,4074,0
17
17
6520608,1,0,1,1,1,1,1,4360,0
18
18
6709024,0,0,1,1,1,1,1,4549,0
19
19
7135008,1,0,1,1,1,1,1,4975,0
20
20
7218976,1,0,0,1,1,1,1,5059,0
21
21
7425824,1,1,0,1,1,1,1,5266,0
22
22
7530272,1,1,0,0,1,1,1,5370,0
23
23
7716640,1,1,1,0,1,1,1,5556,0
24
24
7845664,1,1,1,0,0,1,1,5685,0
25
25
8068896,1,1,1,1,0,1,1,5909,0
26
26
8220448,1,1,1,1,0,0,1,6060,0
27
27 (27 records)
8539936,1,1,€ (?)

I have had this error now on both an Uno and a Mega. I totally rewrote my code after I got it on the Uno to make sure that I was handling variable sharing appropriately, but I'm back in the same spot.

Here is the code (attached). The general idea is to have 3 threads, 2 semaphores, and a mutex. 1 thread produces the data by reading sensors, 1 thread writes the data to the SD card, and the 3rd main thread keeps a global timer so I can set how long to run for. The mutex locks the data so the producer/consumer cannot be accessing the same data simultaneously. Any help would be greatly appreciated...this is my first time working with ChibiOS and coding something of this scale in the Arduino IDE, so I'll take any help I can get.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy