View Full Version : SD Card Problem - Simple Code
07-18-2009, 02:30 AM
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.
files := 1
r := sdfat.popen(numtostring.ToStr(files, %000_000_000_0_1_000100_01010), "w")
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.
07-18-2009, 02:47 AM
Regarding the robust saving of data, as you know you can not yank the card while the file is open for write. However, rather than do N files, you could use just 2 files. Whenever you have data to log, do a
- 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?
Piranha are people too.
07-18-2009, 02:52 AM
The problem is likely in what you're not showing.
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.
07-18-2009, 03:19 AM
I'll grab the laptop and post my whole code in a bit. But is using the same object in multiple cogs really bad? So if I want to use floating point, numbers, etc. I have to do multiple instances like.
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!
07-18-2009, 03:45 AM
lonesock that is awesome I went with your idea. However it kept randomly rebooting or just going black still.
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!
07-18-2009, 11:43 AM
Another possibility which will not lose any data, except perhaps corrupt the block being written. Place an existing huge blank file on the SD and just update each successive sector. This how we are using ZiCog CPM files (disks)
Links to other interesting threads:
· Home of the MultiBladeProps: TriBladeProp (http://forums.parallax.com/showthread.php?p=786418), RamBlade (http://forums.parallax.com/showthread.php?p=810753), TwinBlade (http://forums.parallax.com/showthread.php?p=806697),·SixBlade (http://forums.parallax.com/showthread.php?p=780033), website (http://bluemagic.biz/cluso.htm)
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator) (http://forums.parallax.com/showthread.php?p=790917)
· Prop Tools under Development or Completed (Index) (http://forums.parallax.com/showthread.php?p=753439)
· Emulators: Micros eg Altair, and Terminals eg VT100 (Index (http://forums.parallax.com/showthread.php?p=778427)) ZiCog (Z80), MoCog (6809)
· Search the Propeller forums (via Google) (http://search.parallax.com/search?site=parallax&client=parallax&output=xml_no_dtd&proxystylesheet=parallax&proxycustom=<HOME/>&ie=&oe=&lr=)
My cruising website is: ·www.bluemagic.biz (http://www.bluemagic.biz)·· MultiBladeProp is: www.bluemagic.biz/cluso.htm (http://www.bluemagic.biz/cluso.htm)
07-18-2009, 12:03 PM
You don't need a separate instance for each cog. The LOCKxxx instructions are provided to make one of the cogs wait for the other cog to finish with the shared variables. If the timing works out in your favor, the two cogs will rarely have to wait to use the common floating point (or whatever) object, yet you can be certain that two cogs will not try to use a common resource at the same time.
Read the chapters in the Propeller Manual on the LOCKxxx instructions and Spin statements.