Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Writing to microSD card Teensy 3.6

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    9

    Writing to microSD card Teensy 3.6

    Hello,

    I am new to Teensy and Arduino in general, but am trying to use a Teensy 3.6 to collect data from analog sensors at around 10,000 samples per second per sensor, and write it to a microSD. Since I will have around 10 sensors I am concerned with being able to write the data to the SD quick enough with the 256kB of RAM. I have been browsing and found this data logger: https://github.com/MichaelStetner/TeensyDataLogger but I am unsure if that would be sufficient. For that data logger he was able to sample an analog pin at 25kHz, so I'm not sure if it could handle 10 pins at 10kHz. If anyone has any ideas or suggestions that would be greatly appreciated. Thanks in advance!

    Greg

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,263
    This project should be possible, but it will be pushing the hardware nearly as fast as it can go, which can be challenging.

    You'll definitely need to buffer data while the SD card is busy.

  3. #3
    Senior Member
    Join Date
    Dec 2016
    Location
    Canada
    Posts
    837
    why not split the buffer? write to one buffer in memory, when it reaches end, have it write to the SD, and start writing the 2nd buffer, when thats full, write that to SD and start rewriting the first buffer, no?

  4. #4
    Junior Member
    Join Date
    Sep 2017
    Posts
    9
    Thanks for the replies guys. My knowledge on memory buffering is very limited, so I was hoping to be able to use a data logging sketch that someone had posted to the forums. I have been looking a sketch by tni (https://forum.pjrc.com/threads/43834...-5-3-6-SDIO-SD) that uses FIFO buffering and supposedly has worst case latency of 40ms, which seems like it should be sufficient.

    As it stands right now I am looking at data acquisition at 220kB/s (11 sensors at 10kS/sec and 16 bit), so if I am interpreting everything correctly I should be able to use the sketch by tni and write everything to the microSD with no issues. However, a lot of the coding done in the sketch is over my head so I may be misunderstanding something. With your knowledge does this seem possible? I also bought two Teensy 3.6s so I am thinking of using both to split the sensors across the two, which should help limit the demand on each.

  5. #5
    Only just got my Teensy 3.6 but for SD Card usage this web page (https://github.com/greiman/SdFat-beta) seems to offer some advice on using the inbuilt SD Card.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    5,181
    Note - post #5 links to Beta that is noted as out of date - suggest this is the current version: github.com/greiman/SdFat

    It seems there was more than one fast logger thread - not sure if any page through buffers. There is one sample examples/AnalogBinLogger - but seemed to be __AVR__ ( not Teensy specific for ADC and RAM considerations ) but as far as I read it just filled the buffers - then wrote them all at once - not doing writes while sampling - and it was rather long and used delay() in places to perform that on UNO/MEGA type devices with smaller memory.

  7. #7
    Junior Member
    Join Date
    Jan 2018
    Posts
    1
    This sounds entirely possible to me if you haven't gotten it working already. I have a motor test controller/logger and I'm logging 3 channels at 25khz, 1 channel at 4khz and a handful of other signals at .1-1khz or so. Make use of both of your ADC channels to cut the number of sequential ADC reads in half, use ADC interrupts to allow the SD to be running catchup every spare cycle it can. I use a large ring buffer as my SD write buffer. Log raw ADC readings instead of trying to generate an ascii log on the logger. Should be no trouble at all to get that sort of thing off the ground as long as you are careful about not wasting cycles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •