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

Thread: Teensy 3.6 ADC resolution

  1. #1

    Teensy 3.6 ADC resolution

    Hi,

    i try to read analog values with the analog pins using analogRead. I "only" get 10bit resolution =>0...1023. In the description i read that analog inputs have 13 bit res. => 0...8195...

    Is there a special library command or setting for it ?

    Thank you

    Torsten

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,797
    See this :: https://www.arduino.cc/en/Reference/...ReadResolution

    13 bits is well documented as tough to arrange - but in theory it can be setup - details on the forum somewhere.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    Quote Originally Posted by Spyy View Post
    Is there a special library command or setting for it ?
    Yes, use analogReadResolution(13);

    It defaults to 10 bits for Arduino compatibility.

  4. #4
    Hi Paul,

    thank you found it => Solved

    Torsten

  5. #5
    Senior Member
    Join Date
    Aug 2016
    Posts
    149
    In the description for the teensy 3.6 he says:

    25 Analog Inputs to 2 ADCs with 13 bits resolution

    All the 25 analog inputs they have 13bit resolution or two of them?
    If so what are they?

  6. #6
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    253
    If speed isn't an issue, then setting 16 bits and oversampling/averaging is helpful.

  7. #7
    Senior Member
    Join Date
    Aug 2016
    Posts
    149
    Quote Originally Posted by thanos View Post
    In the description for the teensy 3.6 he says:

    25 Analog Inputs to 2 ADCs with 13 bits resolution

    All the 25 analog inputs they have 13bit resolution or two of them?
    If so what are they?
    Please reply.

  8. #8
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    Quote Originally Posted by thanos View Post
    In the description for the teensy 3.6 he says:

    25 Analog Inputs to 2 ADCs with 13 bits resolution

    All the 25 analog inputs they have 13bit resolution or two of them?
    If so what are they?
    The Teensy 3.6 has 2 ADC's. ADC0 and ADC1, they are multiplexed to 25 pins that we can access. Meaning you can access 2 pins at the exact same time.

    Here is the top side pins, I have not made one for the bottom (yet).
    Click image for larger version. 

Name:	Teensy3_6_AnalogCard.jpg 
Views:	2472 
Size:	140.0 KB 
ID:	10666

  9. #9
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    Quote Originally Posted by PaulStoffregen View Post
    Yes, use analogReadResolution(13);

    It defaults to 10 bits for Arduino compatibility.
    Hmm, may have to request changes to Pedvide's library to do this, if you set it to 13Bit it goes to 12Bit. His library only allows 16, 12, 10, 8. And it rounds down to the nearest value.
    So "adc->setResolution(13, ADC_n);" would produce 12 bit values...

  10. #10
    Senior Member
    Join Date
    Aug 2016
    Posts
    149
    Thanks Donziboy2.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    Quote Originally Posted by Donziboy2 View Post
    Hmm, may have to request changes to Pedvide's library to do this, if you set it to 13Bit it goes to 12Bit. His library only allows 16, 12, 10, 8. And it rounds down to the nearest value.
    Just set it to 16 bits and discard the low 3 bits. Or discard even more, in the very likely case your analog signals aren't that clean and low enough impedance. Or use something like ResponsiveAnalogRead to try cleaning things up a bit in software.

    We publish "13 bits" in the description, even though the hardware actually reads 16, because even the very best case scenario is at most 13 good bits from the 16 the hardware gives. The hardware doesn't actually have any 13 bit mode. The description with 13 is merely an attempt to be honest about what the hardware can really do, rather than telling you it has 16 and then you later find out there's no way to ever get anything but noise in those low 3 bits.

  12. #12
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    Paul, the reason I said that is that it is a trap for new users. They setup Pedvide's library thinking they will get 13 bit values and instead get 12 bit. This leads to them jumping on the forums asking for help.
    I guess the alternative would be for Pedvide to provide details on his ADC Library First post stating what values can be set. (not sure if that is likely, he has not visited the forums in 4 months)

  13. #13
    Senior Member
    Join Date
    Jan 2013
    Posts
    843
    Quote Originally Posted by PaulStoffregen View Post
    We publish "13 bits" in the description, even though the hardware actually reads 16, because even the very best case scenario is at most 13 good bits from the 16 the hardware gives.
    The number of useful (as in not just random) bits can be at least 15. With differential 16-bit mode and 32x hardware averaging, measuring a battery voltage, I get a standard deviation of 1.35. (And that's with using USB power (data disabled).)

    The hardware doesn't actually have any 13 bit mode.
    There is a 13-bit differential mode.

  14. #14
    Member
    Join Date
    Jun 2017
    Location
    Utah, USA
    Posts
    31
    New here and I am having some problems when trying to set the read resolution to 12-bits using the code:

    analogReadResolution(12);

    The Arduino IDE reports an error of:

    expected constructor, destructor, or type conversion before '(' token

    Do I need to have a #include or #define or other code besides the analogReadResolution(12); statement?

    I should add that I get this problem no matter what the resolution I set it to is...


    Brian

  15. #15
    Senior Member
    Join Date
    Dec 2013
    Posts
    225
    Quote Originally Posted by Raptor View Post
    New here and I am having some problems when trying to set the read resolution to 12-bits using the code:

    analogReadResolution(12);

    The Arduino IDE reports an error of:

    expected constructor, destructor, or type conversion before '(' token

    Do I need to have a #include or #define or other code besides the analogReadResolution(12); statement?

    I should add that I get this problem no matter what the resolution I set it to is...


    Brian

    Try it this way if I remember correctly.
    analogReadRes(12);

  16. #16
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,443
    This program builds for me on T3.6:
    Code:
    void setup() {
      Serial.begin(9600);
      analogReadResolution(12);
    }
    
    void loop() {
    }
    Two things I would check

    a) Are you configured for a Teensy 3.x board in the Arduino IDE?

    b) The code line above that line. Is there something wrong with it? Like is there a ; at the end?

    Not sure what else to say as I don't see the code that is not compiling

  17. #17
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    Maybe you don't have Teensy 3.6 selected in Tools > Boards?

    Or maybe you have something else wrong in your code on the line before analogReadResolution?

    Hard to know, since we can't see your screen or your code. But those are the most likely causes.

  18. #18
    Member
    Join Date
    Jun 2017
    Location
    Utah, USA
    Posts
    31
    Yes, tools shows the board as Teensy 3.6 and port is comm 4.

    Also, I tried analogReadRes(12); and no help.

    I'll copy the code and submit in a few...


    Brian

  19. #19
    Member
    Join Date
    Jun 2017
    Location
    Utah, USA
    Posts
    31
    Here's the code that was modified from one of the example programs.

    /*
    ReadAnalogVoltage
    Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
    Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
    Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

    This example code is in the public domain.
    */

    // the setup routine runs once when you press reset:
    void setup() {
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
    }
    float Vave = 0;

    // the loop routine runs over and over again forever:

    unsigned long cnt=1;
    analogReadResolution(16);

    void loop() {

    //unsigned long cnt=1;

    for (int loopCount = 1; loopCount <= 256; loopCount++) {
    // read the input on analog pin 0:
    int sensorValue = analogRead(A0);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage = sensorValue * (3.3 / 1023.0);
    Vave = Vave + voltage;
    // print out the value you read:
    // Serial.println(voltage);
    delay(4);
    }
    Serial.print("Count = ");
    Serial.print(cnt);
    Serial.print(" -- ");
    Serial.print("Average Voltage = ");
    Serial.println(Vave/256);
    Vave = 0;
    cnt++;
    }



    Thanks,

    Brian

  20. #20
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    You need to put analogReadResolution(16) inside setup().

  21. #21
    Member
    Join Date
    Jun 2017
    Location
    Utah, USA
    Posts
    31
    Quote Originally Posted by PaulStoffregen View Post
    You need to put analogReadResolution(16) inside setup().
    Paul, thanks, looks like that worked!

    Yeah, I'm a newb


    Brian

  22. #22
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    Everyone starts from the beginning. That's perfectly fine.

    Just remember to post the code when you have this sort of question (eg, the "Forum Rule"). We can help much more when we can see your code.

Posting Permissions

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