What causes an SD Card to hang?
Philldapill
Posts: 1,283
I'm writting some code to grab an accelerometer sample, write it to an SD Card, and display the sample info on the screen using Parallax Serial Terminal and a slightly modified FullDuplex Serial.
My problem, is that as the program runs, it eventually hangs up until cnt rolls back around. Essentially, sometimes my repeat loop takes waaaay longer than it should, which causes my calculated waitcnt() time to be before the cnt time once the code hits the waitcnt() command. So, because of this, the program has to wait until the counter rolls all the way back around to my calculated time, then it proceeds as normal - until the glitch happens again.
I've narrowed my code down to the root cause. It's something in the SD code that hangs up for longer than expected, around 1/10th of a second. I can post code if needed, but this seems like more of a general question.
So, why would the SD Card hang and take longer than expected to write?
My problem, is that as the program runs, it eventually hangs up until cnt rolls back around. Essentially, sometimes my repeat loop takes waaaay longer than it should, which causes my calculated waitcnt() time to be before the cnt time once the code hits the waitcnt() command. So, because of this, the program has to wait until the counter rolls all the way back around to my calculated time, then it proceeds as normal - until the glitch happens again.
I've narrowed my code down to the root cause. It's something in the SD code that hangs up for longer than expected, around 1/10th of a second. I can post code if needed, but this seems like more of a general question.
So, why would the SD Card hang and take longer than expected to write?
Comments
Is this also true for SD cards?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
EDIT: Yes, it does hang after the 512th byte. It takes around 15,884,784(give or take due to spin) clock cycles to write that to the card. That's just shy of·200ms...·Is this just a crappy, slow card?
Post Edited (Philldapill) : 5/26/2009 6:03:26 PM GMT
With this additional file system overhead, I guess it could easily take 100-200ms to do a write if a new file extent has to be allocated.
Are you using sdspiqasm? Are you using fsrw?
It's worth digging into this and figuring out what's up.
-tom
Is there a faster version out there?
What I'm thinking, is to write to a buffer in another cog, and the buffer cog is just devoted to writing everything in the buffer. This way, if there is a long hang-up, the buffer cog can wait until SD is finished doing it's business. Or is there a better way?
To implement your own buffering will be a bit painful, I'm afraid. The same cog that opens the file needs to be the one that writes
the data, so you'll need to use another cog that interacts with fsrw entirely, and get some sort of interface into that. Simplest
would probably be a shared buffer (maybe 1024 bytes is enough) and a pair of pointers (usual producer/consumer setup).
At what rate are the samples coming in?
-tom
Would you be willing to:
1. Stub out your code so you don't need the accelerometer (just make it return a random number, say)
2. Make sure it's got the tick timing in there that reports 15M or something
3. Post the resulting archive.zip with all needed files?
I can test it out on my card set and figure out what's up.
-tom