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

Thread: Teensy 3.6 ~1MHz sampling & DMA to extract data?

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    2

    Teensy 3.6 ~1MHz sampling & DMA to extract data?

    Hi, everyone.

    Thanks to this forum I found out that high speed sampling (with reduced resolution in bit) with more than 1 MHz sampling frequency is possible using a Teensy 3.6.

    First of all: my aim is to take 0.1 s long readings containing signals with frequencies up to 200 kHz. I want to use a Teensy 3.6 to do that.

    So I modified the analogContinuousRead example from the ADC library to that code:

    Code:
     #include <ADC.h>
    
    ADC *adc = new ADC();
    unsigned int rate = 0, i = 0;
    unsigned long int samples = 39500;
    unsigned long int val[39500];
    unsigned long microslast = 0, g = 0;
    unsigned int N;
    
    void setup() {
    
      pinMode(A9, INPUT);
    
      Serial.begin(9600);
    
    
      adc->setAveraging(0);
      adc->setResolution(8);
    
    
      adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED);
    
      adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED);
    
      adc->startContinuous(A9);
    
      delay(500);
    }
    
    void loop() {
    
      i = 0;
      microslast = micros();
      while (i < samples) {
        if ( adc->isComplete()) {
          val[i] = (uint8_t)adc->analogReadContinuous(A9);
          i++;
        }
      }
      rate = micros() - microslast;
      Serial.print("  ");
      for (i = 0; i < samples; i++) {
        Serial.println(val[i]);
      }
      N = sizeof(val);
      Serial.print("Rate: ");
      Serial.println(rate);
      Serial.print("Size: ");
      Serial.println(N);
      delay(5000);
    
    }
    As you can see I print out the result in the serial monitor afterwards. I analyzed the frequency and confirmed the result of a 158 kHz signal. The sine wave does not look that neat but sufficient for my application. I obviously have reached a sampling frequency of 1.58 MHz!

    Click image for larger version. 

Name:	158khz.png 
Views:	39 
Size:	36.8 KB 
ID:	15014
    The last 5 rows of my output in the serial monitor look like that:
    24
    58
    107
    Rate: 25032
    Size: 158000
    (size is in bytes).


    Generally, a measurement would start by telling the Teensy when to start using some kind of triggering. Since I must capture and forward 0.1 s long signals for processing (maybe to a raspberry pi 3) I am now facing the problem of transferring the data quickly and without loss. I looked at the ringBufferDMA example but don't understand how to exctract my array. A measurement of 0.1 s would contain 1,580,000 MSp/s x 8 bit x 0.1 s = 1.264 Mbit, correct? So, if the ADC is continuously sampling into the memory, I would have to extract the data via DMA out of the memory at the same sampling speed? Can someone please point me in the right direction on how to do that? Is what I want to do even possible using the Teensy 3.6?

    Thx.

  2. #2
    Check out https://forum.pjrc.com/threads/45993...ghlight=151962 and search for "Teensy36AdcDmaLogger.ino". Bill Greiman wrote an SDFs library and did an example running the ADC at 3 MHz with 12-bit resolution and recording the result on an SD card in real-time. You should be able to do the same thing to record your data, and then transfer it to some other place when you're not collecting data.

    Good luck! -W

  3. #3
    Junior Member
    Join Date
    Oct 2018
    Posts
    2

    Red face

    Quote Originally Posted by willie.from.texas View Post
    Check out https://forum.pjrc.com/threads/45993...ghlight=151962 and search for "Teensy36AdcDmaLogger.ino". Bill Greiman wrote an SDFs library and did an example running the ADC at 3 MHz with 12-bit resolution and recording the result on an SD card in real-time. You should be able to do the same thing to record your data, and then transfer it to some other place when you're not collecting data.

    Good luck! -W

    Thanks a lot! That might be exactly what I am looking for!

Posting Permissions

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