Writing to SD card, 1 in 7 lines takes a very long time compared to other 6

21 Feb 2012

Hi,

I just noticed a funny pattern where every 7th message takes around 6000us, while every other message takes around 35us when saving GPS strings.

void task1(void) {
    while (1) {
        os.WaitEvent(TIMER0_EVENT);

        if (readLine < printLine) {
            pc.printf("%s\r\n", gpsTEMP[readLine]);
            t.start();
            fprintf(gps, "\n\r%s", gpsTEMP[readLine]);
            //
            readLine++;
            t.stop();
            printf("TIME: %d\r\n", t.read_us());
            t.reset();

            if (readLine == printLine) {
                // pc.printf("\n\n\r RESET COUNTERS \n\n\r");
                readLine =0;
                printLine = 0;
            } else {
                os.SetEvent(TIMER0_EVENT, TASK1_ID);
            }
        }
    }
}

Output:

$GPRMC,054620.293,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*74
TIME: 34
$GPRMC,054620.343,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*78
TIME: 34
$GPRMC,054620.393,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*75
TIME: 5640
$GPRMC,054620.443,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7F
TIME: 34
$GPRMC,054620.493,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*72
TIME: 34
$GPRMC,054620.543,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7E
TIME: 34
$GPRMC,054620.593,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*73
TIME: 34
$GPRMC,054620.643,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7D
TIME: 36
$GPRMC,054620.693,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*70
TIME: 34
$GPRMC,054620.743,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7C
TIME: 6899
$GPRMC,054620.793,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*71
TIME: 34
$GPRMC,054620.843,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*73
TIME: 34
$GPRMC,054620.893,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7E
TIME: 34
$GPRMC,054620.943,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*72
TIME: 35
$GPRMC,054620.993,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7F
TIME: 34
$GPRMC,054621.043,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7A
TIME: 34
$GPVTG,230.5,T,,M,000.0,N,000.0,K,A*09
TIME: 22
$GPRMC,054621.093,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*77
TIME: 5674
$GPRMC,054621.143,A,4517.3282,N,07555.0904,W,000.0,230.5,210212,,,A*7B
TIME: 34

Any ideas as to what could be causing this?

Thanks, Sebastian

21 Feb 2012

My guess is that it fills a buffer on writing. As soon as the buffer is 'at max' it is written to the sd card causing some delay. If you add up the bytes written it might give a clue how large this buffer is (probably 512 or 2048 bytes, aka sector size?)