Question about SdFat-Beta

Status
Not open for further replies.

OJGV24

New member
Good day lovely comunity,

I am sure my question is very simple for some of you, I just wanted to get it out of my head.

I have just started using my Teensy 3.5 and I wanted to save some data into my SD. I also found that Teensy has a faster library (SdFat-beta) so I wanted to test it.

Here is what I want and what I am doing:

I want to write to a file every 20 ms and I want to use the less time possible (to write), so I want to avoid using commands like file.flush() or file.close() until I confirm that I want to stop recording data. However, I am concerned if I don't flush or close, there will be memory leakage.

I made a test code where I am succesfully writing a "message" of a little bit more than 100 bytes (which represents say my data) in less than 100 microseconds. This process maintains fairly stable for 10000 loop iterations with occassional "hangs" between 5-10 ms (5 in 10000, 4 at the very first 10 iterations). My message is stored in a char message[] variable before entering the loop so I am assuming that it is a global variable that consumes some RAM. What I am looking to test here is wheather this message suffers from leakage but I don't know if this is a correct way of checking that. After the 10000 iterations are finished, I open up the file to check if my message is correctly stored all the 10000 times, and it is.

Can anyone confirm if this will not leak? I am not worried about losing the data if the power goes down. I just want the fastest way while power is up and to close the file at the end.

I know I could do something like flush every 500 iterations but I would prefer avoiding it since I don't want the data to suffer from 30-80 ms hangs. Anything that ENSURES me that the data will be written in less the 5 ms CONSTANTLY is acceptable.

I have attached the code. To use it just upload it with your SD Card on, send a 1 to write the "message" and let it run. When it stops, send a 2 to verify the message. Please remember to use the SdFat-beta library given here (https://github.com/greiman/SdFat-beta). To use it I copied the folder SdFat to the C:\Program Files (x86)\Arduino\libraries folder

Thanks in advance.
 

Attachments

  • FastSDWrite.ino
    3.2 KB · Views: 79
Did you post this exact same question yesterday?

Regardless of which library you use, you're probably going to need to use an interrupt (eg, IntervalTimer) to run the code which collects your data and queues it up into an array in RAM. All SD cards occasionally have very long latency.
 
Thank you for your response Paul.

And yes, sorry I reposted it cause I thought the other was in the wrong category. I will delete the other post.

My question was more about not using the comand file.flush() or file.close() until the end. I will consider using the Interval Timer but the problem is I perform A LOT of operations inside it and someone told me interrupt routines should be short. Also, I don't know if I am able to communicate through I2C while on the interrupt.

I already have my data already being collected by a timed loop (not interrupt) at 20 ms in the form of,

void loop(){

if(micros()-timer>20000){
timer=micros();
//Read data
//Perform A LOT of operations
//Save data
}

}

I have 5 ms "free" at the end of my processing and there is where I would like to save my data.

Most of the time is performing admirably (100 microseconds) with 1 ocassionaly hang in 10,000 iterations.... This is absolutely fine for me. I don't care about that particular hang. What I am more worried about is memory leaking because I don't use file.close() or file.flush().

I am working on a UAV, so if my parameters or readings get messed up due to leakage, my UAV will crash.

Thank you in advance.
 
Status
Not open for further replies.
Back
Top