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

Thread: PC capture of Analog read data

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    9

    PC capture of Analog read data

    I ran a test to see how fast Teensy 3.0 could take 1,000 analog readings and transfer the data to the Arduino Serial monitor. Teensy 3.0 was over 20 times faster than an Arduino Uno or a Chipkit Uno 32. Now I need suggestions on to capture the data in a file and thereby put Teensy 3.0 speed to good use.

    For reference here is the test code.

    const int Pin = 0;

    void setup()
    {
    Serial.begin(115200);
    }

    void loop()
    {
    unsigned long t1 = millis();
    for (long i=0; i< 1000; i++)
    {
    int val = analogRead(Pin);
    Serial.println(val);
    }
    unsigned long t2 = millis();
    Serial.print("millisec "),
    Serial.println(t2 - t1);
    delay(10000);

    }

    hrh1818

  2. #2
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    Couple of things…

    You can influence the speed of the reads using the resolution and averaging commands. Higher resolution and averaging lead to longer conversion times and vice-versa.
    Depending on what you are sampling, the speed of the sampling vs. the speed of the signal change, you can increase your resolution using decimation.
    IRRC, you can initiate a reading on the ADC and not block the CPU if you don't use the analog read command. However, the downside is the much more complicated /less readable code to get it all done. However, you can have the MCU do useful things while the ADC works away and then wait for the ADC to report it's ready before proceeding with processing the next sample.
    Use the memory… if you need to do matrix math, etc. read it all into a buffer, then do a single block transfer either to the desktop or a SD card.
    I don't know your application, but you may be able to reduce the data transmitted sufficiently to meet your ADC needs without discarding the Desktop connection.

    All that said, Bill Greiman has achieved absolutely amazing transfer speeds with his sdfatlib series of libraries and ADC examples. I'd look there first.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Quote Originally Posted by Constantin View Post
    Couple of things…

    Use the memory… if you need to do matrix math, etc. read it all into a buffer, then do a single block transfer either to the desktop or a SD card.
    I don't know your application, but you may be able to reduce the data transmitted sufficiently to meet your ADC needs without discarding the Desktop connection.

    All that said, Bill Greiman has achieved absolutely amazing transfer speeds with his sdfatlib series of libraries and ADC examples. I'd look there first.
    Thank you for your reply.

    The main application is to sample analog channels at approximately 25,000 samples per second and save the data for analysis by Labview. From what I seen so far the gain obtained by using the fast communication speed of Teensy 3.0 will get us to our goal without needing to use many of the data acquisition optimization techniques you mentioned.

    Originally I was aiming towards directly saving the data in a PC file. But your suggestion of saving the data on s SD card looks very promising. I will definitely look at Bill Greiman's work.

    hrh1818

  4. #4
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    No worries and hope it helps.

    I was using the Teensy 3 for power measurements but later switched to a dedicated analog front end. It ended up being less expensive to implement a true 16-bit measurement of power using that chip than to accommodate the maybe-13bit, unipolar, and one-channel-at-a-time ADC of the Teensy 3.0...

    That's not to say that the ADC in the Teensy 3.0 is junk. Far from it! But for my purposes there was a better alternative. If you need specialized sampling at high speed, do take the time to read and understand the ADC chapter in the Teensy MCU manual. There is a lot of good information in there and it'll give you a sense of what the ADC can and can't do, depending on your operating conditions.

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    8
    Quote Originally Posted by hrh1818 View Post
    Thank you for your reply.

    The main application is to sample analog channels at approximately 25,000 samples per second and save the data for analysis by Labview. From what I seen so far the gain obtained by using the fast communication speed of Teensy 3.0 will get us to our goal without needing to use many of the data acquisition optimization techniques you mentioned.

    Originally I was aiming towards directly saving the data in a PC file. But your suggestion of saving the data on s SD card looks very promising. I will definitely look at Bill Greiman's work.

    hrh1818
    Hi hrh 1818,

    I'am digging out this old thread as I'am doing more or less the same thing than you.
    Did you finally get further with fast analog logging with teensy 3 and an SD card?

    I did a few try, using SDfatlib of course, and didn't get anything better that around 300 hz before dropping samples.
    I'am interested in knowing if you get better results.

    thanks in advance !

    antoine

  6. #6
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    706

    high speed recording with SDFAT

    According to this post http://forum.arduino.cc/index.php?topic=128335.0 by the author of the SDFAT library, Teensy 3 is capable of writing 1776 kByte/sec to a fast SD card. Seems like that ought to handle more than 300 samples per second. You do need to have a fully blank formatted SD card for best results, and note the peak latency was 65 msec so there are some implications on buffering.

    Code:
    File size 5MB
    Buffer size 4096 bytes
    Starting write test.  Please wait up to a minute
    Write 1776.44 KB/sec
    Maximum latency: 65790 usec, Minimum Latency: 2146 usec, Avg Latency: 2300 usec

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    8
    Thanks JBeale,

    I'am indeed using the optimized SDfat lib wich is mentionned in the artduino forum thread.
    I guess the bottleneck is in my code, and I was interested to know the max sampling rate others can achieve.

Tags for this Thread

Posting Permissions

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