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:
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!
The last 5 rows of my output in the serial monitor look like that:
(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.
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!
The last 5 rows of my output in the serial monitor look like that:
24 |
58 |
107 |
Rate: 25032 |
Size: 158000 |
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.