CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to save variables in pic using SD card

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
yohis960



Joined: 17 Sep 2011
Posts: 2

View user's profile Send private message

How to save variables in pic using SD card
PostPosted: Sat Sep 17, 2011 3:40 pm     Reply with quote

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 Smile 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! Smile

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???
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Sep 17, 2011 7:54 pm     Reply with quote

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.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Sep 18, 2011 3:38 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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