SD card and FAT system - again

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are a lot of forum posts about this but none that fits my usage.

- I am making another data logger.
- I can use FAT
- I can also use directly access (no file system) and use a special PC software to reads out the data.
- I use a ATmega168, to less RAM to fit most FAT drivers. I also need much of the RAM for my application.
- I sample to fast to be able to read and update the FAT system. I need to run on a pre-formated card.
- I need it to consume very little power.

If I use directly access, I need to write my own PC read software. This will take more time than I have. Anyone knows about any free code that does it? C# or java is prefered.

As the data are written in 512 blocks, I must have at least that size of my buffer or wasting some data space. An alternative is to hold the SD card open (chip select active) continously and only buffer data while it is writing the block. The obvious problem is power. How much current will the card consume if I hold the chip select active all the time?

If I use FAT, I need to find a driver that is small in FLASH and that is proper for use without having all of the FAT table in RAM but to work directly with the prerequisite that the card is formated. With this method I do not need to find a place for my files, I can just put them after each other.

Finally, if FAT is used, I need to update the FAT now and then or I will loose my file at power of.

I problem is that I am not familiar with FAT and do not know about the commands. If I do not find the information I need I plan to buy this from a company I worked with before. It's just that I would like to learn about this as it can be useful in the future.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I have about the same problem, not sure if I will need it yet but here is some study I did :
* Make a batch file containing :

@cls
@dir g:
@hpusbf g: -FS:FAT -A:512
@md g:\dsmall             >NUL
@md g:\dbig               >NUL
@md g:\dhuge              >NUL
@md g:\dall               >NUL
@copy small.txt g:\dsmall >NUL
@copy big.txt g:\dbig     >NUL
@copy huge.txt g:\dhuge   >NUL
@copy small.txt g:\dall   >NUL
@copy big.txt g:\dall     >NUL
@copy huge.txt g:\dall    >NUL
@tree g: /f

By the way g: is my smartdrive on the PC. The small.txt, big.txt and huge.txt are sample text files.
Then use the program tinyhexer from www.mirkes.de to view the raw data on the card.
What I was thinking that is to pre-load the card with a batchfile like above, reserve space for all the information I want to read/store on the card and then using it without modifying the fat. Probably no that difficult. Keep in mind - using short filenames (<8 characters) makes it much more easyer.

I was also thinking to use small bootloader, which gets the .hex file also from the sd-card.

This tinyhexer program might even fit your needs as it has scripting possibilities.

Good luck,
Patrick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Presumably you already looked at Chan's FatFs ??

http://elm-chan.org/fsw/ff/00ind...
http://elm-chan.org/docs/mmc/mmc...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I have. I have not yet been able to find out how much resources the package will need.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bengr: I am running the tiny-fatfs package on a Mega168, and that works well :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great! Could you please tell me if you know how much resources it need? RAM and FLASH. Also if you know anything about if it possible to reduce the RAM usage, for example like if you can deside that the card is empty when you start so you can just write your file addresses to the FAT. Any hints you have is useful.

Maybe you know something about power consumtions of SD cards also?

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know about C# or Java, but I experimented in C with opening the whole block device instead of a file. No problems there, so I suppose you can use that in C# or Java too. Problem is that you need to know what physical drive number the attached memory card has, but you could write some kind of signature to the card so you can identify your card by reading the first sector of all raw physical devices.

But you have forgotten one more option. You could fill the FAT formatted card with a single contiguous file (or make the file as big as you need, of course). Then you know that you can safely write the sectors of the file with whatever data you wish and it does not mess the FAT filesystem. Basically this is a variant of using the card as raw blocks but you just use the raw blocks in the data area which have been previously allocated to a file. You need some bookkeeping of your own like you would by using the card as raw blocks. And you need to understand FAT filesystem only enough to find the sectors the file uses (starting sector and size, you get the ending sector. Search directory by file name "RAW_DATA.BIN" or first file or something.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bengtr wrote:
Yes I have. I have not yet been able to find out how much resources the package will need.

You could try to look at the appnote page , located on elm-chan's page

http://elm-chan.org/fsw/ff/en/ap...

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There did you find that? I can't see it on the main page. Very well, it did helped.

As for power consumption I have found 30-45 mA in active mode and 150-500 µA in inactive mode but nothere have I been able to find any information about how to find out what they actually mean with active mode. I know thatthe falsh will consume a lot of power if writing the flash and as 30-45 mA is very much I think this current is while writing to flash.

To clear the fog I checked the datasheet of a Atmel DataFlash, I think they should be basically the same in function.
Deep power down is 9µA and Standby is 25 µA. Read operation is 10 mA and write max 25 mA, both at33 MHz. Unforturnately there is no current given at slower (or stopped) clock.

Anyway, I can see a big problem here for fast sampling speeds. If the card will spend much of its time writing my power consumption will be very high, tens of mA. Therefore I will have to use a larger battery for my fast sampling application. For slow sampling speeds, it should be no problems but probably it is much better to put the card in sleep mode between writes.

I think I will have to test the power consumtion myself. It should be rather easy, maybe just an active chip select compared to an inactive chip select. That will give me the numbers I need.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A Google for "mmc site:elm-chan.org" or "avr site:elm-chan.org" actually shows quuite a lot of pages on that site mentioning MMC or AVR (though clearly some in his Japanese mother tongue)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is japanese, just try the babelfish, it works well enough to able to read the pages. (I use Altavista toolbar just because it has the babelfish on it). Thanks for the Google tip, I forget about that possibility sometimes despite that the option is in the search field.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bengtr: I have not tested power consumption yet, but I agree that it would be interesting.

I was not quite happy with the SPI interface of our japaneese friend, so I am using other SPI code. I have a basic shell on the uart and some test code, and it uses about 14000 bytes of flash and the fat-code itself needs a bit more than 512 bytes of ram (enough to hold one sector of 512 bytes + some working variables).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks! 512 bytes + is not much. That means it does not read in any FAT file system that many other drivers need to. But 14kb (13,7) is very much. Are you sure it is so much? In that case it would be impossible to put it in a ATmega88 and if you are running it in a mega168 you will only have 2 k for your own app. But maybe it is possible to remove some functions that you don't need.

Do you have any possibility to test the power consumtion? Easiest is to use a simple multimeter in series with you power supply and read the difference. Will work for static at least. Better is a small resistor and a scope so you can read power during a write and so on. I am mostly interseted in static consumtion with no activity but chip select active as you may have understood.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To compare... I just looked how much Flash the FAT code takes on my project, 3770 bytes. But this is a read-only system, but with directory/FAT12/second FAT supported turned on.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bentr:
I will not be able to fit my stack on an mega88.

I did a small test with a small main that only mounts the fs and lists the contents of a directory. Compiled with -Os it gives:

AVR Memory Usage
----------------
Device: atmega168

Program:   12106 bytes (73.9% Full)
(.text + .data + .bootloader)

Data:        558 bytes (54.5% Full)
(.data + .bss + .noinit)

I will see if I can test the power consumption in the next few days.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I started thinking that I do have lots of unused functions, so I did another test. I used EW's tips for removing unused functions shown here:

https://www.avrfreaks.net/index.p...

And I get a much better result :-D

AVR Memory Usage
----------------
Device: atmega168

Program:    4776 bytes (29.2% Full)
(.text + .data + .bootloader)

Data:        556 bytes (54.3% Full)
(.data + .bss + .noinit)