2

I'm writing on a SD card the value of a measured voltage. I've a good sampling/writing frequency but regularly the acquisition take a lot of time (like 4000us instead of 400us). I noticed that this "pause" appears every 85 values (my values are 6 bytes long, so it appears every 510 bytes).

So I have hypothesized that there is a buffer of 512 bytes somewhere which is full and need some times to empty.

But I don't know where is this buffer. In SDcard? in Arduino? And how can I avoid this issue?

Here, my results on 1Hz sinus with a zoom on the "break":enter image description here

And here my loop to read the value and write it on sd card:

enter image description here

Hope you can help me guys !

1

Possibilities:

  • What you can do it measure what you need inside an interrupt routine (I hope the measurement itself does not take too long). Write it to a buffer in the interrupt routine. Your 'normal' loop can do the writing to the SD card.
  • A possible very extensive solution would be to send the sampled data to another Arduino which can store it on an SD without affecting the sampling (since it's done on another Arduino).
  • Using DMA (Direct Memory Access), however afaik this option is not available for an Arduino.
  • 1
    That a good idea thank you, but my measure is did with an external ADC wich communicate in I2C. And I2C use interrupt so i can't communicate in another interrupt. And Sdcard communicate in SPI, so i will probably miss values too while interrupt is disable during SPI communication – bouaaah Aug 3 '17 at 13:33
  • True, to be honest, I don't have experience with interrupts myself, but it seemed appropriate here, but it already uses interrupts. – Michel Keijzers Aug 3 '17 at 14:05
  • Other interrupts are disable during an interrupt vector, maybe i can do a software SPI and software I2C, but i'm thinking it will take a lot of devellopment to finally lost a lot of speed. – bouaaah Aug 3 '17 at 14:13
  • I never tried software SPI or I2C, but tried software UART/Serial for MIDI (which is slow, 31250 baud) and it didn't work at all, so I assume you will not have much luck with software solutions. You might need to use DMA , but afaik the Arduino does not have that. – Michel Keijzers Aug 3 '17 at 14:20
  • A possible very extensive solution would be to send the sampled data to another Arduino which can store it on an SD without affecting the sampling (since it's done on another Arduino). – Michel Keijzers Aug 3 '17 at 14:45
1

The buffer is in the SD card library. It is the size of one block on the SD card. When it is full it needs flushing out to the SD card, which takes time. Once that is done the buffer is then empty again and can be filled back up by your code.

It has to be done this way because SD cards work in blocks of 512 bytes.

  • Thanks a lot, I was confused to don't know where was this buffer. I have to find a solution now to keep the best regular sampling rate. – bouaaah Aug 3 '17 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.