AnswerBun.com

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

How I can send data information without work WiFi to LCD?

1  Asked on September 25, 2021 by abuwesam

       

How to wire L293D chip to a nodeMCU?

1  Asked on September 25, 2021

   

Fastest Communication from NodeMCU to Arduino Nano

1  Asked on September 25, 2021 by prikarsartam

       

Is this circuit risky for an Arduino Uno?

1  Asked on September 25, 2021 by j-francis

   

Write a Struct using ArduinoBLE library

1  Asked on September 25, 2021 by sicks

   

Wait between UART frames

2  Asked on September 25, 2021 by martin-g

 

Memory usage in AnalogBinLogger of SdFat library

1  Asked on September 25, 2021 by harini

     

Sim800 FTP Arduino

2  Asked on September 25, 2021

     

ESP-01 + UNO won’t detect gateway

2  Asked on September 25, 2021 by mrcabana

       

Error reading file

1  Asked on September 25, 2021 by yash

   

Reading 4-20ma signal on arduino

1  Asked on September 25, 2021 by sumit-mann

       

How to use tinygps.h library to measure distance? using NEO6mv2

1  Asked on September 25, 2021 by reiniel-cirujano-antonio

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir