Teensy 3.6 ADC resolution

Status
Not open for further replies.

Spyy

Well-known member
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
 
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?
 
If speed isn't an issue, then setting 16 bits and oversampling/averaging is helpful.
 
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).
Teensy3_6_AnalogCard.jpg
 
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...
 
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.
 
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)
 
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.
 
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
 
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);
 
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
 
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.
 
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
 
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
 
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.
 
Status
Not open for further replies.
Back
Top