Teensy 4 ADC hole of 7bits every 256 bit

Lapasuc

Member
Hello,

I'm using ADC on Teensy4. I read data on adc0 at 12bit resolution. Conseguently the readen integer range is 0-4095. I saw that every 256bit there's an hole in reading of 7bit. For example bit from 505 to 511 are missing. any help?

The same is at 10bit of resolution using pedvide adc library and arduino adc library.
 
Hello Pete, sorry for the crosspost but I wasn't able to delete the first post.

Anyway for reproducing the problem you can put a DC signal of 413mV in A9 and run the following code.

I think the problem is Pedvide library but I'm not sure.

Code:
#include <ADC.h>
ADC *adc = new ADC();

int ADCLibrary=0; //0=Arduino 1=Pedvide

const int readPin = A9;
long int sensorValue=0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(readPin, INPUT);

  if(ADCLibrary==0){

    analogReadAveraging(0);
    analogReadRes(12);

  }
  else{


    adc->adc0->setAveraging(0);
    adc->adc0->setResolution(12);
    adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED);
    adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED);
    adc->adc0->setReference(ADC_REFERENCE::REF_3V3);

  }

}

void loop() {
  // put your main code here, to run repeatedly:
  sensorValue = analogRead(readPin);

  if(ADCLibrary==0){

    sensorValue = analogRead(readPin);

  }
  else{

    sensorValue = adc->adc0->analogRead(readPin);
  }

  if(sensorValue==504){Serial.print(String("504")+"\n");} //si
  if(sensorValue==505){Serial.print(String("505")+"\n");} 
  if(sensorValue==506){Serial.print(String("506")+"\n");} 
  if(sensorValue==507){Serial.print(String("507")+"\n");} 
  if(sensorValue==508){Serial.print(String("508")+"\n");}  
  if(sensorValue==509){Serial.print(String("509")+"\n");}  
  if(sensorValue==510){Serial.print(String("510")+"\n");}  
  if(sensorValue==511){Serial.print(String("511")+"\n");}  
  if(sensorValue==512){Serial.print(String("512")+"\n");} //si    
 
  delay(500);
  //Serial.println(sensorValue);

}
 
I put a 25k ohm potentiometer on A9 and your code prints values in the range 504 to 512 with ADCLibrary = 0 or 1.
Code:
510
509
511
510
509
509
510
510
509
510
508
510
509
510
510
509
510
509
510

What device do you have on A9?

Pete
 
Hello Pete and the other hepled me. The versiono of TeensyDuino is 1.51 and Arduino 1.8.12. I simply connect a dc signal generator to A9 and GND. All oter pins are disconnected. I've tried to use only the arduino laibrary in e separated sketch and is working fine. In the evening I'll post oter tests and I'll use the potentiometer as well to make all reproducible.
 
My previous test was done on a T3.2 - my bad, sorry.

I've now repeated the test using a T4 and a 10-turn 1k trimpot.
With the Arduino code, I can get values from 504 to 512 but with Pedvide it will only infrequently print 504 or 512 but nothing in between. Without touching the trimpot, I can switch back and forth between Arduino and Pedvide and it reliably shows values such as 505,506,507 for Arduino and between 497 and 500 for Pedvide.
It does exactly the same thing if I switch conversion and sampling speeds to LOW_SPEED.

Pete
 
Hello Pete and Paul,

I just do the test using a 25K potentiometer to divide the 3.3V. I can confirm that if I use Arduino library I can detect values from 504 to 512. If I use Pedvide Library I can detect only 504 and 512. Pete can you confirm what I saw?

pinMode(23, INPUT_DISABLE); don't helped me.

Anyway in the mean time I'll use Arduino Library because some micros of time of conversion aren't critical. I didn't saw the same problem on T3.6 but I've to repeat tests because I don't remember exactly.
 
Yes you can probably generate an issue up on his github project.

If it were me, I might try playing around with some of your settings to see if it makes a difference:
Code:
adc->adc0->setAveraging(0);
    adc->adc0->setResolution(12);
    [COLOR="#FF0000"]adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED);
    adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED);[/COLOR]
    adc->adc0->setReference(ADC_REFERENCE::REF_3V3);
For example I am assuming the setAveraing and setResolution will be the same with the core analogRead, so probably the main difference is the conversion speed and sampling speed.
What happens if you change these from VERY_HIGH_SPEED to just HIGH_SPEED, do you still see the same issue?
 
Back
Top