View previous topic :: View next topic |
Author |
Message |
BM
Joined: 07 Aug 2012 Posts: 1
|
Memory Card slowing down ADC read rate |
Posted: Tue Aug 07, 2012 7:33 am |
|
|
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
|
|
Posted: Tue Aug 07, 2012 6:57 pm |
|
|
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.
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 07, 2012 11:22 pm |
|
|
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: 1635 Location: Perth, Australia
|
|
Posted: Wed Aug 08, 2012 5:20 am |
|
|
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
|
|
Posted: Wed Aug 08, 2012 6:34 am |
|
|
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 |
|
|
|