ADC0 teensy 3.2

Status
Not open for further replies.

paul_H

Member
HELLO all
I am trying to read a differential signal using ADC0 of teensy 3.2 (pin10+,pin11-), but unfortunately i hav'nt get the right signal, I have used a sine wave with 1KHz as an input, I have compiled the following code:

HTML:
#include <ADC.h>
ADC *adc = new ADC(); // adc object
float Sensor_voltage0;
float max_value0;

int Gain=1;
void setup() {
   
    pinMode(A10, INPUT); //Diff Channel 0 Positive ADC0
    pinMode(A11, INPUT); //Diff Channel 0 Negative


    Serial.begin(9600);

    adc->setReference(ADC_REFERENCE::REF_1V2, ADC_0);
 //should be 1.2V because of PGA using
 //teensy 3.1 and 3.2 have an internal 1.2v reference
 //ADC1 used to read signals higher than 1.2 less than or equal 3.3
    ///// ADC0 ////

   adc->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED); // change the sampling speed
//ADC_SAMPLING_SPEED::VERY_LOW_SPEED is the lowest possible sampling speed (+24 ADCK). (ADCK is the ADC clock speed, see below).
//ADC_SAMPLING_SPEED::LOW_SPEED adds +16 ADCK.
//ADC_SAMPLING_SPEED::MED_SPEED adds +10 ADCK.
//ADC_SAMPLING_SPEED::HIGH_SPEED adds +6 ADCK.
//ADC_SAMPLING_SPEED::VERY_HIGH_SPEED is the highest possible sampling speed (0 ADCK added).

//    adc->enablePGA(Gain, ADC_0);  // gain can be 1,2,4,8,16,32,64
       
                             // Use only for signals lower than 1.2 V and only in differential mode
  adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED); // change the conversion speed                           
     delay(500);
}


void loop() {
  // put your main code here, to run repeatedly:
max_value0= adc->getMaxValue(ADC_0);

Sensor_voltage0= (adc->analogReadDifferential(A10, A11, ADC_0))*1.2/max_value0;


Serial.print("Sensor_voltage0=");
Serial.println(Sensor_voltage0);



// analogWrite(A14, (int)adc->analogReadDifferential(A10, A11, ADC_0));



}

can anyone help please?

thanks in advance.
 
HELLO all
I am trying to read a differential signal using ADC0 of teensy 3.2 (pin10+,pin11-), but unfortunately i hav'nt get the right signal, I have used a sine wave with 1KHz as an input, I have compiled the following code:
What do you expect to see, and what do you get? (IOW, what is exactly the problem?)

Otherwise, you should be aware that a ADC AND Serial.print statements in the same loop calls for problems

Edit: did you consider to use the Audio Library with GUI?
 
Last edited:
thanks, WMXZ for replying
before doing anything, I would like to check my teensy board, if its work properly or not, especially ADC0 and ADC1, TO DO that I have compiled the following:
Code:
// Simple DAC sine wave test on Teensy 3.1
#include <ADC.h>
ADC *adc = new ADC(); // adc object

float phase = 0.0;
float twopi = 3.14159 * 2;
elapsedMicros usec = 0;

void setup() {
  analogWriteResolution(12);
  adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED);
  adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED); // change the conversion speed                           
     delay(500);
  Serial.begin(9600);
}

void loop() {
  float val = sin(phase) * 2000.0 + 2050.0;
  analogWrite(A14, (int)val);
  phase = phase + 0.02;
  if (phase >= twopi) phase = 0;
  while (usec < 500) ; // wait
  usec = usec - 500;

int value = adc->analogRead(A9);
Serial.println(value);

}

the freq of signal out of DAC read 6Hz on oscilloscope, its should be 1KHz!
to test ADC I connect a sine wave with different freqs to A9 and read the signal on serial plotter

with this simple code, I get a clear signal just up to 100Hz!
at 1000Hz the signal has been unclear although the sampling freq is very high!
is this mean that the ADC0 of my teensy board have damaged??
or what do you suggest??

thanks in advance
 
What do you mean by "signal is unclear"? You send values to the DAC with a period of 500us which corresponds to a sampling rate of 2000Hz (No, that's not very high!). Thus, if you have studied and understood the Nyquist theorem, the maximum frequency which can be correctly reproduced at any sample rate fs is < fs/2. So, trying to output a 1kHz signal with 2kHz sampling frequency is already difficult. That's why digital audio systems use sampling frequencies above 44kHz to make sure that the audio band up to 20kHz will be correctly reproduced.

Second, any sampling process generates sidebands which are called aliasing. That's why behind every DAC, there must be a reconstruction filter, especially if you are working at high frequencies, relative to the sampling frequency. Simple digital audio systems using a DAC and no oversampling or any other digital technology for signal optimization need at least a 18dB/octave Bessel (linear phase) low pass filter to eliminate quantization noise (the famous DAC step edges) and intermodulation products.

Third, your simple example code (sampling period = 500us + CPU loop and calculation time, phase step= 0.02) is expected to show a frequency slightly below fs * 0.02 / (2 * pi) which corresponds perfectly to a result of around 6Hz.

I'd suggest that you study digital audio basics first before you complain about hardware or code not giving you the desired results...

Afterwards, we might talk about the ADC side, where you need either to use a synchronized sampling process or additional filtering to re-sample a just reconstructed signal.
 
Status
Not open for further replies.
Back
Top