Memory usage in AnalogBinLogger of SdFat library

Arduino Asked by Harini on September 25, 2021

The AnalogBinLogger.ino file of SdFat library says the following:

Each 512 byte data block in the file has a four byte header followed by up to 508 bytes of data. (508 values in 8-bit mode or 254 values in 10-bit mode).
Each block contains an integral number of samples with unused space at the end of the block.

I was wondering why only 254 values can be stored in 10-bit mode instead of (508*8 bits/ 10 bits ~ 406 values ).

  1. Is this because of the memory being byte-addressable and hence does a 10-bit value take up 2 bytes?
  2. If so, how will a file-reader differentiate between a 10-bit value taking 2 bytes and two 8-bit values?
  3. The AnalogBinLogger.ino says:

The logger will use SdFat’s buffer plus BUFFER_BLOCK_COUNT additional buffers.

BUFFER_BLOCK_COUNT is 1 for the Arduino Uno since it has 2KB of SRAM. Each buffer is 512-byte long. Is SdFat’s internal buffer also in SRAM? If I am not wrong, the libraries the program uses and the program code reside in the Flash memory, can SdFat write into a buffer in Flash memory?

One Answer

how will a file-reader differentiate between a 10-bit value taking 2 bytes and two 8-bit values?

The file AnalogBinLogger.h, which comes with the example sketch you mentioned, contains the following:

// First block of file.
struct metadata_t {
  unsigned long  adcFrequency;     // ADC clock frequency
  unsigned long  cpuFrequency;     // CPU clock frequency
  unsigned long  sampleInterval;   // Sample interval in CPU cycles.
  unsigned long  recordEightBits;  // Size of ADC values, nonzero for 8-bits.
  unsigned long  pinCount;         // Number of analog pins in a sample.
  unsigned long  pinNumber[123];   // List of pin numbers in a sample.

Thus, the file reader just needs to be aware of the format of this first block, and read the recordEightBits field in order to know whether this is 8-bit data or not.

Is SdFat's buffer also in SRAM?

Yes, that's the only sensible place you could have a data buffer. It's allocated on the stack, only during the execution of the logData() function.

Answered by Edgar Bonet on September 25, 2021

Add your own answers!

Related Questions

Ethernet Shield doesn’t work at all

0  Asked on December 30, 2021 by silencefog


Problem with STM32 and SDFat lib on other SPI port

1  Asked on December 28, 2021 by lucasn


Sea level pressure for BMP280

2  Asked on December 28, 2021


Receive an array of characters using SIM900 module

2  Asked on December 24, 2021 by reza-qasemi


Using a template inside a class

1  Asked on December 24, 2021 by guyd


Understanding heap fragmentation

0  Asked on December 19, 2021


Arduino Nano 33 Sense won’t upload

0  Asked on December 14, 2021 by electrouino


Serial port usage in code

2  Asked on December 11, 2021 by joe-mann


Arduino Nano 33 IoT StandardFirmataPlus

0  Asked on December 9, 2021 by girish-ravi


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP