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 support@ccsinfo.com

Memory Card slowing down ADC read rate

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



Joined: 07 Aug 2012
Posts: 1

View user's profile Send private message

Memory Card slowing down ADC read rate
PostPosted: Tue Aug 07, 2012 7:33 am     Reply with quote

Hi

I have code that reads values from a PIC ADC and the rate at which it read values is set using timer interrupts. I want to save the values to memory card each time they are read (frequency of about 100Hz). I'm using functions from the mmcsd.c library (mmcsd_write_data) to write to the card

Whenever I write data to the card it slows the rate at which I am reading from the ADC. I measured the frequency at which the PIC (SCL pin) is writing to the card and it is of the order of 200kHz which seems more than enough. I don't understand why the read rate of the ADC slows down and is there a way round it?

Compiler: CCS
PIC18F25J11

Thanks
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Aug 07, 2012 6:57 pm     Reply with quote

1- post some code
2- it depends on the SD card - but the card write cycle and overhead surely is responsible for eating those CPU cycles. right ?

Your code may show a way to optimize the delay you are getting from the SD card write cycle.

Be more forthcoming and more help will likely come your way.


Put another way - i don't have time to try to read your mind and guess.


Very Happy Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 11:22 pm     Reply with quote

Search Google for this:
Quote:
"sd card" write block time

and
Quote:
"sd card" data logger slow write

There is a lot of information out there on this topic.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Aug 08, 2012 5:20 am     Reply with quote

I supply a fully functional data logger application with my file system driver. The trick is to decouple data acquisition from the data logging. The way I do this is similar to a ring buffer technique for dealing with serial ports.

In your case you could do something like this (simplified because I do you use your specific PIC variant).

1. Use a timer interrupt to initiate the start of sample (basically starting the ADC process)
2. Use the ADC sample complete interrupt to read the ADC and put the value in a ring buffer.
3. In the mainline check the ring buffer, if not empty, extract values from the ring buffer and write to the media.

Naturally to implement a REAL data logger you also want to time stamp the data - as per my sample application.

Your ring buffer has to be large enough to deal with the latency variation when reading and writing to SD cards. In theory it can take up to 5ms for a general read/write operation to complete. When you are dealing with a files system then a sinple write operation can involve multiple read and write operations as a result of needing to fetch a new sector. In practice I have found a buffer depth of 40ms to be safe when dealing with 1ms samples. Your milage may very.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Aug 08, 2012 6:34 am     Reply with quote

Edit: i miss read your post... seems fast enough...never mind


a way to speed up your write cycles would be to:
read 128 samples and save in ram
save the entire 128 block into the card.

instead of singly byte writes to the card....

the singly byte aproach is what i use for my _slow_ logger.... 1ADC/h....


G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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