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

Thread: Teensy 4 ADC hole of 7bits every 256 bit

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    6

    Teensy 4 ADC hole of 7bits every 256 bit

    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.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,321
    Post some code which demonstrates the problem (and don't crosspost)

    Pete

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    6
    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);
    
    }

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,321
    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

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,555
    What version of TeensyDuino is in use? TD 1.51 is the current version.

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,891
    Remove the pinMode for readPin - it is not a digital input.

  7. #7
    Junior Member
    Join Date
    Feb 2019
    Posts
    6
    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.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,857
    Try adding this:

    pinMode(23, INPUT_DISABLE);

    Does it help?

  9. #9
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,321
    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

  10. #10
    Junior Member
    Join Date
    Feb 2019
    Posts
    6
    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.

  11. #11
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,321
    @Lapasuc
    Yes, that's what I saw.

    Pete

  12. #12
    Junior Member
    Join Date
    Feb 2019
    Posts
    6
    @el_supremo

    Do you think I've to write an issue in pedvide/ADC GIT hub?

  13. #13
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,678
    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);
        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);
    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?

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,891
    Is there any pinMode() ? If yes try to change it to pinMode(xxx,INPUT_DISABLE);

Posting Permissions

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