![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
yohis960
Joined: 17 Sep 2011 Posts: 2
|
How to save variables in pic using SD card |
Posted: Sat Sep 17, 2011 3:40 pm |
|
|
Hello everyone! First of all I don't know how to speak english so I'll try to do my best and make my point hehe sorry The thing is that I have to save every hour 6 variables in pic, then download them to a SD card and watch those numbers in the PC. There are two regular variables and the time and date. I need to know all of them, so for instance:
Data1 Data2 Hour Min Day Month Year
12 50 7 10 17 09 11
The information will be shown in the computer,...but I don't know the most effective way to store them properly in the PIC...that is a device that is in a car, so It's hard to send them directly to the Rs232 port :S...it's in a SD card: (I thought It could be fine if i use like 7 eeprom memories, but I think that is not efficient to that project. Please I need advice and information, I'm still working in the SD card and still is making me go nuts :( PLEASE HELPP!!!!!! Thank you guys!
I thought if it isn't necessary to save them in the eeprom memories and keep the SD card connected all the time to the device...is that better??? So i just work in the SD card??? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sat Sep 17, 2011 7:54 pm |
|
|
Since you need the SD card to transfer the data from the car to the house,just store the data onto the SD card. Setup a file and send the data to it in CSV format. That way it'll be very easy to open the file from the PC using Excel, QuickBasic, etc.
I currently have a project using the 'Vinculum' module which is a very simple way to interface data from a PIC to a USB flashdrive and vice versa. Best $34 I ever spent!
There are SD related programs here, in the code library and elsewhere, but for me it was far easier to use the Vinculum. Less than 3 days the system was up and running. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Sep 18, 2011 3:38 am |
|
|
OK.
Let's go through some of this.
First, you can't just write a byte or a small number of bytes to an SD card. These use _page_ writes. So to write a single byte, you need to read the current page into memory, change the one byte/few bytes, then write the _whole_ page back. Then it gets worse. A SD card _to read in a PC_, also needs a 'file system' maintained on it. So after writing this byte, you then have to update the directory structure to say that the file is now this much bigger.
Now the code to do this is in the FAT library that comes with the compiler, so 90% written for you.
However it does mean that the chip you are using _must_ have enough RAM to hold the whole page from the SD card, while you are working on it.
Absolute minimum of perhaps 600+ bytes of RAM on the chip (512byte page, plus some storage for other things you are doing). This is not a practical project on one of the smaller PIC16 chips with only a few bytes of RAM.
You also need some form of interlock. A button to press on the PIC for example, to say 'don't write', when you want to remove the card. Otherwise, if the PIC starts to write just at the moment you remove the card, data _will_ be corrupted.
This is why on the PC, you are meant to tell the system you want to remove the card. You can 'get away' with not doing this, if you are reading a card only, but if writing to a card, this interlock is necessary, or at some point you _will_ get data being corrupted....
As temtronic says, the simplest way to layout the data to be 'readable', is probably to use a textual representation. CSV (comma separated value), is about the simplest. So you store the data on the card as:
val,val,val,val,val,val<LF>
With the values in text form, commas separating the values, and a line feed after each complete record.
Remember also that the SD card is a 3.3v device, so you either need a 3.3v PIC, or buffering between the card and the PIC.
Plenty of people do this, or systems like it for data logging applications, but it does involve a significant amount of work/care, if it is going to work reliably.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|