SD Card Problem - Simple Code
SuperCricket
Posts: 17
This was just a test of using an SD card to log things with the FSRW object.
If I let the program log infinitely to a file, whenever I turn the Propeller off and eject the card the file is corrupt.
My idea was to log to a file for a bit, close the file, and open a new one. In this way I could remove the card at any time and still have files of data. So this code writes to files "1", "2", "3" and so on. I can turn off the Prop and while the last file is corrupt, I have many other files of useful data.
However after a random time period, maybe a minute or 3 minutes, the screen goes black and the Prop reboots. Sometimes sucessfully and sometimes not. So sometimes I may have 3 files, sometimes I may have 6 good files of data. Sometimes 1. It is completely random.
One cog is running this code while the main cog is running the TV terminal simply outputting the value of "stuff." The above cog is running with a stack of like 300 longs to make sure that wasn't the problem.
Any ideas?
If I let the program log infinitely to a file, whenever I turn the Propeller off and eject the card the file is corrupt.
My idea was to log to a file for a bit, close the file, and open a new one. In this way I could remove the card at any time and still have files of data. So this code writes to files "1", "2", "3" and so on. I can turn off the Prop and while the last file is corrupt, I have many other files of useful data.
However after a random time period, maybe a minute or 3 minutes, the screen goes black and the Prop reboots. Sometimes sucessfully and sometimes not. So sometimes I may have 3 files, sometimes I may have 6 good files of data. Sometimes 1. It is completely random.
PUB logger sdfat.mount(16) files := 1 repeat r := sdfat.popen(numtostring.ToStr(files, %000_000_000_0_1_000100_01010), "w") repeat 10 sdfat.SDstr(fs.FloatToString(stuff)) sdfat.pclose files += 1
One cog is running this code while the main cog is running the TV terminal simply outputting the value of "stuff." The above cog is running with a stack of like 300 longs to make sure that wasn't the problem.
Any ideas?
Comments
- popen "file1" for append
- pwrite your logging data
- pclose "file1"
- popen "file2" for append
- pwrite your logging data
- pclose "file2
This way, both files should be identical. If the system loses power during a write the other file is still in good condition. This is not the fastest solution, of course, but it is really easy to implement.
Regarding the reboot, I've had trouble when I had the USB cable plugged in to the PropPlug, but not to my PC. Could you describe the system setup you are using in more detail?
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
From your description, it sounds like both cogs are using the floating point library, possibly at the same time. That's dangerous.
Without a complete copy of your code, it's impossible to tell what's going on. Use the ARCHIVE feature of the Propeller Tool to make a file that you can attach to your next message. Indicate which "library" objects you're using. If you've changed them in any way, include them as well.
cog1_numero : "numbers"
cog1_floating : "FloatMath"
cog1_FS : "FloatString"
cog1_BS2 : "BS2_Functions"
cog2_numero : "numbers"
cog2_floating : "FloatMath"
cog2_FS : "FloatString"
cog2_BS2 : "BS2_Functions"
cog3_numero : "numbers"
cog3_floating : "FloatMath"
cog3_FS : "FloatString"
cog3_BS2 : "BS2_Functions"
Seems like I will be out of memory damn quick like that!
Sure enough I just gave the floating point another instance for that 2nd cog.
So the first cog converts the value to a floating point for display on the screen and the 2nd cog converts it to write to the file.
It's been running for 10 minutes now no problems.
In a year of programming the Propeller I had no idea you needed an instance of a library file for each cog. Insane.
Thanks for the help Mike!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBladeProp, RamBlade, TwinBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80), MoCog (6809)
· Search the Propeller forums (via Google)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Read the chapters in the Propeller Manual on the LOCKxxx instructions and Spin statements.