How to change ADC bit?


I'm studying genuino 101

Now I need to use the 12bit ADC, write settings on the file AIN11-14

·5 analog inputs AIN_11 – AIN_14, 11 other possible analog inputs using alternate functions listed below: ADC Resolution set via ADC_RES [1: 0] register; lower bit resolution can be sampled faster then the 12 bit maximum. -11 = 12 bits -10 = 10bit -01 = 8 bits

-00 = 6 bit. Lower number of bits can be sampled quicker in less clock cycle than 12 bit max number of bits

I check datasheet corresponds to the board on the A1-A3(AIN11-13) and SDA(AIN14)

But how do I set up to change 11 into 12bit

I see the official website of this information Speaking of this method

AnalogReadResolution (12);

But how can I verify that the 12bit ADC


I was interested in the answer to this so I did a quick trial. I may want to use something other than the default 10 bit resolution of the Arduino 101 A/D in the future.

I hope this was not a homework assignment of some kind… The method I used to test the analogReadResolution() function on my 101 was to just do it brute force. I set up a Sketch to repeatedly read a pin at different resolutions to see what I get. According to the Reference Link, if you choose a resolution greater than what the hardware supports, low order bits are simply padded with zeros.

That is exactly what I found. Results of 8, 10, and 12 bit resolution tests returned data that always differed a little in the lowest order bits. At 14 bit resolution, the two low order bits were always zeros. At 16 bit resolution, the four low order bits were always zero.

I ran the test measuring a floating pin. As such, I expected some variation from run to run and did see that but the behavior of the low order bits and the normalized results were pretty consistent on my board.

Here is the test code Sketch I threw together.

 * Test of the analogReadResolution() function for the Arduino 101.
 *   The test can be run on a bare board with the analog inputs floating.
 *   This is will give rise to some variation but is good enough to test
 *   out the workings of the analogReadResolution() function.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);                         // Initialize Serial communication
  while(!Serial);                             // Wait for serial port to connect.

  const int  Resolution[5] = {8, 10, 12, 14, 16};
  long SumReadings;
  int  AverageReadings;
  char OutputBuffer[100];
  int  tempResult;

  // Set up the analog input and take a reading that will be thrown away.
  //   This is to just flush the A/D.
  for (int DummyRead = 0; DummyRead < 4; DummyRead++)
    tempResult = analogRead(A0);

  // Run the testing at five different A/D resolutions
  for (int trial = 0; trial < 5; trial++)
    // Set the desired resolution and flush the A/D
    for (int DummyRead = 0; DummyRead < 4; DummyRead++)
      tempResult = analogRead(A0);

    // Clear out the variables for this trial run
    SumReadings = 0;
    AverageReadings = 0;
    memset(OutputBuffer, 0, 100);

    // Take 16 back-to-back readings at the desired resolution
    for (int ReadLoop = 0; ReadLoop < 16; ReadLoop++)
      SumReadings = SumReadings + analogRead(A0);

    // Find the average by dividing by 16      
    AverageReadings = SumReadings >> 4;

    // Output the results for this loop
    sprintf(OutputBuffer, "The Sum of 16 readings at %d bits was 0x%6X and the average was 0x%6X (%d).", 
            Resolution[trial], int(SumReadings), AverageReadings, AverageReadings);
    sprintf(OutputBuffer, "The normalized result is %f at %d bits resolution.\n", 
            AverageReadings/pow(2.0,float(Resolution[trial])), Resolution[trial]);

    // Delay for 100 miliseconds. This should allow the A/D of the floating pin
    //   to stabilize a little before starting the next resolution trial.

void loop() {
  // put your main code here, to run repeatedly:


So, it appears to me that the Arduino 101 does indeed have the capability to use the 12 native resolution of the A/D. You could modify my test code to actually see how much longer it takes to do the analog reads at 12 bit resolution as opposed to the default 10 bits. If you really need the resolution and the longer conversion cycles are not a problem, then go for it…