MCU User Forum
  USB datalogger

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   USB datalogger
RaghuDevii
New Member
posted August 11, 2010 10:40 PM     Click Here to See the Profile for RaghuDevii   Click Here to Email RaghuDevii     Edit/Delete Message
I need to build a datalogger to record two analog channles at 10ms intervals with time stamp on to a MMC / SD /CF memory. Iguess I need to start with the C8051F340 mcu and the USB-MSD ref. design.

Question is whether I will be capable of storing data at the required frequency of 10ms and maybe go down to 1ms if required ? I am right now studying the ref. design and would like to get this specific query answered.

IP: Logged

Tsuneo
Member
posted August 12, 2010 04:31 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
For either MMC/SD/CF, quick write response is not always guaranteed.
Requirement of 1 - 10 ms is critical, if you write the data directly to the external memory.

Better approach is,
The firmware has two tasks, one for measurement and logging to RAM cache, another for writing from the RAM cache to the external memory. Both tasks work concurrently.

Usually these external memory has 512 bytes / sector as the unit of single write. Therefore, when you choose RAM cache size as one of multiple of 512 bytes (ie. 512, 1024, ...), you'll get better speed performance as a whole.

Tsuneo

IP: Logged

RaghuDevii
New Member
posted August 12, 2010 05:41 AM     Click Here to See the Profile for RaghuDevii   Click Here to Email RaghuDevii     Edit/Delete Message
Thanks for the clarification. Would it be OK if I dump the logged data to flash once every 20ms ? This means I would need to plan for an XRAM of 20*512 = 10KB ?

Also there are two ref designs AN189 and AN282. Which would fit in my need more closely ? I think AN189 has no means of reading the Flash card through the MCU and save it to PC ? Thanks

IP: Logged

erikm
Member
posted August 12, 2010 08:20 AM     Click Here to See the Profile for erikm   Click Here to Email erikm     Edit/Delete Message
if you write the data directly to the external memory.
I see no mention of an external memory

Erik

IP: Logged

Tsuneo
Member
posted August 12, 2010 12:25 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
> Would it be OK if I dump the logged data to flash once every 20ms ?

Here is an excerpt from a SD card manual.

SanDisk SD Card Product Manual (ProductManualSDCardv2.2final.pdf)
2.5 System Performance
- Block Read Access Time: 0.5 ms (typ), 100 ms (max)
- Block Write Access Time: 0.5 ms (typ), 250 ms (max)

Usually, you can read from /write to SD card very quickly. But in the worst case, Write takes 250 ms. Design should be based on the worst case.


> This means I would need to plan for an XRAM of 20*512 = 10KB ?

No. You don't count in that MMC / SD / CF are block I/O device.
The outline of the process flow is as follows.

1) Just when the data logging starts, your firmware puts a header block (start time, sampling interval, etc) to the RAM cache on the on-chip XRAM.

2) A timer triggers ADC for sampling. The ADC completion ISR appends the ADC data to the header on the RAM cache. Every time ADC completes, the ISR appends data to the RAM cache. At the end of the cache, the write position returns to the head (ring buffer).

3) On the main loop, another task polls the cache size on the RAM. When it goes more than SD sector size, this task writes out one sector (or two) from cache to the SD card.

For two ADC channels, the ADC part should be more elaborated. But the outline of the code flow is same as above.

The RAM cache size is determined by the ADC data size, sampling rate and the Block Write Access Time (worst case) of SD card.

For example,
ADC data size: 4 bytes (2ch)
Sampling rate: 1 ms
SD sector size: 512 bytes
SD Block Write Access Time: 250 ms max

In the worst case, ADC generates 4 x 250 / 1 bytes while the firmware writes to the SD card. RAM cache should hold twice of this size, at least.

(4 * 250 / 1) * 2 = 2000 bytes
2048 bytes of RAM cache fits well.

To keep the throughput even in the worst case, you need to write 2 sectors (1024 bytes) at a time using multi-sector write.

Tsuneo

[This message has been edited by Tsuneo (edited August 12, 2010).]

IP: Logged

TimB27
New Member
posted August 12, 2010 01:51 PM     Click Here to See the Profile for TimB27     Edit/Delete Message
I would also recommend using a "Class 6" SD card, since these typically have the best response times.

Unfortunately the SPI interface for these SD cards is not always well supported and response times can vary from manufacturer to manufacturer.

IP: Logged

erikm
Member
posted August 12, 2010 02:03 PM     Click Here to See the Profile for erikm   Click Here to Email erikm     Edit/Delete Message
Do you NEED that capacity?
You can get much better response with a flash chip, and they are CHEAP (last one I used was 2M*8 and cost ~$2.50). Also that would be wired as memory, not a SPI device keeping everything simpler

Erik

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | MCU User Forum

Have you seen our MCU Knowledge Base?


Ultimate Bulletin Board 5.47b