Number of ADC bits Adalogger Feather M0

I am using a Feather M0 adalogger.
I am converting analogRead(A0) and according to the M0 cortex spec it can be set to 8, 10, or 12 bits. The default is supposed to be 12 bits (div reading by 4096 for 100%), but the Feather appears to be reading only 10 bits (div value by 1023 for 100%).

Can anyone explain the number of bits in the M0 and how to change it? Here is the circuit and applicable code in case someone asks. I do not want to add a resistor and the accuracy is not critical.

I am using a Vishay BPW96C as the phototransistor with the emitter tied to ground. The collector is tied to A0 and A1. A1 is used as a 20k digital pullup to 3.3V at the time the analog value is read at A0. A1 is usually off except during the read time to minimize power use.

The applicable code follows.


```cpp
//    Included libraries
#include <MillisTimer.h>  // millisecond timer
#include <ArduinoLowPower.h>
#include <SPI.h>
#include <SdFat.h> // SD.h doesn't put SD card to sleep right.  Try SdFat.h card writing header file. Using Arduino version
#include "sdios.h"
#include <Wire.h>
#include <time.h>
#include <RTClib.h>  // works MUCH better than the finicky/difficult DS3231 library.  Also an Arduino supported lib


// // // PIN DEFINITIONS
// photocells-- A1 is power BUT only turn on when reading through a pullup
#define photoQDrivePin A1  // pin to power the phototransistor for reading
#define photoQReadPin A0  // pin to phototransistor to read value when photoCellDrive is on

const int numADbits = 4095;


void setup() {
 // pin setups
  pinMode( photoQDrivePin, INPUT) ; // we use the DI 20kOhm pullup resistor to provide power and Vdrop for the photoSensor. Turned off for powersave unless need to read A0
}

void loop() {
  // plots of other stuff
    serialPort.print( getPhotoCellVal() );
}
// Gets the photocell value and connverts to an integer percentage
int getPhotoCellVal( void) {
  float photoSensorValue;
  
  pinMode(photoQDrivePin, INPUT_PULLUP); // we use the DI 20kOhm pullup resistor to provide power and Vdrop for the photoSensor
  delay ( 10 ); // let output settle (need to ensure this is long enough; was for a photocell and driven high
  photoSensorValue= analogRead(photoQReadPin);
  photoSensorValue = photoSensorMultiplier * 100 * (1 - photoSensorValue/numADbits);  // Convert to % brightness; photo transistor with pullup inverts, min is 1023, so convert to % and reverse. Multiplier set at beginning
  pinMode(photoQDrivePin, INPUT); // turn off pullup to reduce power
  return (int(photoSensorValue));
}  // end getPhotoCellVal

Perhaps the default resolution is 10 bits. Check whether analogReadResolution() is implemented, with what options.

thank you!

Summary:
The default ADC resolution is 10 bits for the Feather M0 Adalogger.

analogReadResolution() can change the ADC (at least for A0- i did not check the others). values were tested with 8, 10, and 12.

The description of analogReadResolution() is given in @jremington's post above.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.