abin.ephrem
Member
Hello all , I have a couple of doubts about the ADC capabilities of Teensy
1) Whats the maximum resolution of the ADC ? Is it 12bit or 16bit ? The datasheet is a bit confusing , (K64P144M120SF5RM) says Teensy have two 16-bit SAR ADC where as (K64P144M120SF5) says The 16-bit accuracy are achievable on the differential pins ADCx_DP0, ADCx_DM0. All other ADC channels meet the 13-bit differential/12-bit single-ended accuracy
specifications. Can someone please explain what it exactly means !
2) Currently working an analog pressure sensor (Honeywell HSC series , Analog output , 3.3V ,HSCDRRN002NDAA3) and a five hole probe. I'm using Teensy analog pins from A0 to A5 and I am able to get 16 bit data on each channel using the ADC Library. But according to the data sheet Teensy have only two ADC channels that support 16bit data . Does that indicates the ADC value I'm getting is wrong or does teensy can actually support 16bit data on all analog pins ?
3) What is the maximum sampling rate that Teensy ADC can give and how can I use it in my code ? According to the datasheet ADC can give up to some 460K samples/sec . But when I try to log the data directly to the teensy SD card I can barely get up to 4Kz per channel.

Using the above sketch and oscilloscope we can see that the loop rate is about 160Kz ( toggling the LED 13 pin without a delay ). How can we increase the loop rate ?
I'm using Tessny 3.5 Analog pins to read the analog voltage of the pressure sensor and then dump the values into the SD card .
If I comment ou file.println() to dump my values to the SD card then the loop ins running only at frequency close to 5Khz which is very very small. And if tried to run the code with file.println() , then the loop rate is close to 1Khz. How can I increase this ? How can I achieve a sampling rate close 200samples/sec per channel and dump that values to the SD card ?

Can someone help me with this . Thanks in advance
1) Whats the maximum resolution of the ADC ? Is it 12bit or 16bit ? The datasheet is a bit confusing , (K64P144M120SF5RM) says Teensy have two 16-bit SAR ADC where as (K64P144M120SF5) says The 16-bit accuracy are achievable on the differential pins ADCx_DP0, ADCx_DM0. All other ADC channels meet the 13-bit differential/12-bit single-ended accuracy
specifications. Can someone please explain what it exactly means !
2) Currently working an analog pressure sensor (Honeywell HSC series , Analog output , 3.3V ,HSCDRRN002NDAA3) and a five hole probe. I'm using Teensy analog pins from A0 to A5 and I am able to get 16 bit data on each channel using the ADC Library. But according to the data sheet Teensy have only two ADC channels that support 16bit data . Does that indicates the ADC value I'm getting is wrong or does teensy can actually support 16bit data on all analog pins ?
3) What is the maximum sampling rate that Teensy ADC can give and how can I use it in my code ? According to the datasheet ADC can give up to some 460K samples/sec . But when I try to log the data directly to the teensy SD card I can barely get up to 4Kz per channel.



Using the above sketch and oscilloscope we can see that the loop rate is about 160Kz ( toggling the LED 13 pin without a delay ). How can we increase the loop rate ?
I'm using Tessny 3.5 Analog pins to read the analog voltage of the pressure sensor and then dump the values into the SD card .
Code:
#include <ADC.h>
#include<math.h>
#include<SPI.h>
#include <SdFat.h>
#define VREF 3.3
#define resolution (VREF/((pow(2,16))-1));
SdFatSdio sd;
File file;
const int readPin1 = A0;
const int readPin2 = A1;
const int readPin3 = A2;
const int readPin4 = A3;
const int readPin5 = A4;
const int LED = 13;
ADC *adc = new ADC(); // adc object
void measure_log();
double voltage1,voltage2,voltage3,voltage4,voltage5;
double adc_value1,adc_value2,adc_value3,adc_value4,adc_value5;
static int ifl = 0;
static uint32_t count = 0;
char filename[32];
static uint32_t MaxCount = 100000;
bool blah=0;
void setup()
{
pinMode(readPin1, INPUT);
pinMode(readPin2, INPUT);
pinMode(readPin3, INPUT);
pinMode(readPin4, INPUT);
pinMode(readPin5, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(115200);
if (!sd.begin())
{
digitalWrite(LED, HIGH);
sd.initErrorHalt();
}
adc->setResolution(16); // set bits of resolution
adc->setConversionSpeed(ADC_MED_SPEED);
adc->setSamplingSpeed(ADC_HIGH_SPEED);
}
void loop()
{
measure_log();
}
void measure_log()
{
// following is for logging
if(count==0)
{
sprintf(filename,"Multiple_Log%04d.txt",ifl); ifl++;
if (!file.open(filename, O_RDWR | O_CREAT))
{
digitalWrite(LED, HIGH);
sd.errorHalt("open failed");
//count=MaxCount+1;
}
}
while(count<=MaxCount)
{
adc_value1=adc->analogRead(readPin1);
voltage1 = adc_value1*resolution;
adc_value2=adc->analogRead(readPin2);
voltage2 = adc_value2*resolution;
adc_value3=adc->analogRead(readPin3);
voltage3 = adc_value3*resolution;
adc_value4=adc->analogRead(readPin4);
voltage4 = adc_value4*resolution;
adc_value5=adc->analogRead(readPin5);
voltage5 = adc_value5*resolution;
file.println(String(millis())+","+String(adc_value1)+","+String(adc_value2)+","+String(adc_value3)+","+String(adc_value4)+","+String(adc_value5)+","+String(voltage1,4)+","+String(voltage2,4)+","+String(voltage3,4)+","+String(voltage4,4)+","+String(voltage5,4));
blah=!blah;
digitalWrite(LED,blah);
count++;
}
count=0;
if(count==0)
{
// close file
file.close();
}
}
If I comment ou file.println() to dump my values to the SD card then the loop ins running only at frequency close to 5Khz which is very very small. And if tried to run the code with file.println() , then the loop rate is close to 1Khz. How can I increase this ? How can I achieve a sampling rate close 200samples/sec per channel and dump that values to the SD card ?


Can someone help me with this . Thanks in advance