rapidly storing ADC data

Status
Not open for further replies.

powerfly

Active member
I am trying to use a teensy 3.6 or 4.0 (I will be able to use either) to rapidly store (12bit) ADC data. I will be measuring voltage readings at a rate of ~10kHz. the thing is I want to be able to store this data. With an arduino it did not appear to be possible to write data to a micro SD card fast enough. Would it be possible to store data to a card this rapidly with a teensy? I was thinking the 3.6 might be the best for this as it has the native micro SD port.

Alternatively, is there a way of storing data to the flash or RAM and then dumping that to a memory card when the flash/RAM is full? Ideally flash would be better as I would like to store about 1.5Mb of data at the rapid rate before dumping to the SD card and repeating the cycle.

The main thing is to be able to store (ADC) voltage readings at 10kHz for a decent amount of time, help would be much appreciated.
 
Last edited:
The T4 or T_3.6 SDIO interface to an SD card can write perhaps 10 MB per second - depending on the driver library used. Also 5-15 MB/sec writes to disk or flash drive are possible with USB Host device.

How long does it take to accumulate the expected 1.5 MB of data?

The T_3.6 has the ADC library that may continue to read/store data across lag/delay during writes - and there is active work on T4's ADC hardware that provides some degree of lower resolution than the T_3.6 hardware.

The T_3.6 may be more fitting with more complete ADC library and better resolution.
 
The T4 or T_3.6 SDIO interface to an SD card can write perhaps 10 MB per second - depending on the driver library used. Also 5-15 MB/sec writes to disk or flash drive are possible with USB Host device.

How long does it take to accumulate the expected 1.5 MB of data?

The T_3.6 has the ADC library that may continue to read/store data across lag/delay during writes - and there is active work on T4's ADC hardware that provides some degree of lower resolution than the T_3.6 hardware.

The T_3.6 may be more fitting with more complete ADC library and better resolution.

Are you saying that with the 3.6 library it is possible to maintain the 10kHz data rate, whilst transferring data across to the card? If so the problems is solved i think, so if you know how to do this, please let me know.

This could maybe either be done by writing the data directly to the card, or by storing say 0.5 MB chunks of data on the RAM and then transferring those chunks to the card. The thing that seems tricky is maintaining the 10kHz rate whilst doing this.

If I'm doing 8 channels of 12bit (1.5 byte) data at 10 kHz it becomes 8*1.5*10 000 = 120KB/s of data transfer

as I want 20s of data at the 10kHz rate with no drop in the sampling rate, that means just over 2MB of data, which is more than the RAM of any teensy.
 
I just want to point out that in the original post, you mentioned storing 12-bit data sampled at 10Khz, and now in post #4 mention that it is 8 channels.
 
You can use the ADC library on T3.x (and LC), and use DMA operations to collect.

As how fast you can write out to SD Cards... There are several threads and other places on web to find information. For example look for information on the SdFat library

Like: https://forum.pjrc.com/threads/54241-Simple-SdFat-write-benchmark-for-T3-5-3-6

From your description, you wish to collect about 20K worth of data per second, so 1.5mb would take about 75 seconds... If it were me I would do a quick try to see...

As for T4. Full ADC library has not been ported yet. A few of us are working on it (or portions of it). https://github.com/KurtE/ADCL_t4

I am still debugging DMA stuff. SD, is not directly attached to T4, but there are a few breakout boards that work for this. Also at this speed, I would also maybe simply try an SPI connected SDCard...
 
8 channels
12 bit (two bytes, unless data is packed)
10khz sample rate

8*2*10k=160k

Definitely agree, it’s worth some easy testing.
 
You can use the ADC library on T3.x (and LC), and use DMA operations to collect.

As how fast you can write out to SD Cards... There are several threads and other places on web to find information. For example look for information on the SdFat library

Like: https://forum.pjrc.com/threads/54241-Simple-SdFat-write-benchmark-for-T3-5-3-6

From your description, you wish to collect about 20K worth of data per second, so 1.5mb would take about 75 seconds... If it were me I would do a quick try to see...

As for T4. Full ADC library has not been ported yet. A few of us are working on it (or portions of it). https://github.com/KurtE/ADCL_t4

I am still debugging DMA stuff. SD, is not directly attached to T4, but there are a few breakout boards that work for this. Also at this speed, I would also maybe simply try an SPI connected SDCard...

As I understand it, it's not just the write speed of the card, it's rapidly taking incoming newly converted ADC data and putting that on a card in a new file which is slightly different. I didn't mention it in my first comment but I'm using ~8 channels, because of this the data rate will be about 160KB/s. would you recommend using the Arduino IDE?

I've got acess to a T3.6 and T4. the T3.6 seems slightly easier to use as it has the built in card reader.

Is it possible to record the data straight to a micro SD card at the desired rate, and if so how can it be done?
- this is the main question, I checked the other thread you posted, is the write latency+(file size/transfer rate) the time taken to write a chunk of data to the card? if so, it might not be possible to maintain the 10kHz data rate :(, the max write times are in the 10's of ms, over a factor of 100 out

If not, is there a workaround?

I want to try some tests tomorrow but I don't know how to write the code in the best way for high speed as I'm a coding beginner. Also, I was thinking of using the Arduino IDE, is this a good idea?
 
Again others can answer better than I can...

I do very little Analog stuff, and rarely do I need to write stuff to SDCards...

Usually just enough to help other fix problems or testing out new Teensy boards...

So I would look at Bill Greiman's libraries, not sure which is the better one to try at this point between his SDFat or beta version...

There are also many others up here who do loggers...

Again I have no idea how you are collecting data, as you went from one analog to 8? So I don't know anything like are you needing read each of the 8 analog values 10K samples per second? Or can you round robin or ...

With your first description you could simply setup to do on DMA operation with one ADC into a set of buffers, and when each buffer completes reading in data, you could simply start the SDCard to do a write of this data out to the SDCard...

But if instead your buffer needs to be setup with all 8 channels interspersed, then might take more stuff to setup...
 
Again others can answer better than I can...

I do very little Analog stuff, and rarely do I need to write stuff to SDCards...

Usually just enough to help other fix problems or testing out new Teensy boards...

So I would look at Bill Greiman's libraries, not sure which is the better one to try at this point between his SDFat or beta version...

There are also many others up here who do loggers...

Again I have no idea how you are collecting data, as you went from one analog to 8? So I don't know anything like are you needing read each of the 8 analog values 10K samples per second? Or can you round robin or ...

With your first description you could simply setup to do on DMA operation with one ADC into a set of buffers, and when each buffer completes reading in data, you could simply start the SDCard to do a write of this data out to the SDCard...

But if instead your buffer needs to be setup with all 8 channels interspersed, then might take more stuff to setup...

I am hoping to use 8 channels at 10kHz with 12 bit data, this is ~160KB/s. all the data is ADC voltage readings. It seems quite tricky which is why I'm really hoping on some help from someone much better than me at this stuff.
 
Status
Not open for further replies.
Back
Top