0

Feather M0 - Lipo Voltage reading - Bug in tutorial ?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather M0 - Lipo Voltage reading - Bug in tutorial ?

by mchobby on Fri Apr 29, 2016 8:56 am

Hi,

In the M0 tutorial... https://learn.adafruit.com/adafruit-fea ... ng-battery

you are reading the Lipo Voltage and convert the reading to voltage with the following code.

Code: Select all | TOGGLE FULL SIZE
#define VBATPIN A7
float measuredvbat = analogRead(VBATPIN);
measuredvbat *= 2;    // we divided by 2, so multiply back
measuredvbat *= 3.3;  // Multiply by 3.3V, our reference voltage
measuredvbat /= 1024; // convert to voltage
Serial.print("VBat: " ); Serial.println(measuredvbat);


However, the M0 ADC have a resolution of 12 bits so the value should go from 0 to 4095 when reading the voltage.
So the line
Code: Select all | TOGGLE FULL SIZE
measuredvbat /= 1024; // convert to voltage


should become for the feather M0.
Code: Select all | TOGGLE FULL SIZE
measuredvbat /= 4096; // convert to voltage


Am'I right?

mchobby
 
Posts: 70
Joined: Tue Jan 24, 2012 3:14 pm
Location: Belgium

Re: Feather M0 - Lipo Voltage reading - Bug in tutorial ?

by mailhouse on Fri Apr 29, 2016 7:38 pm

I get sane values returned for 1024 but not 4096. I dont have an explanation why your thought process seems correct but the results dont jive, but i'm new to all this.

mailhouse
 
Posts: 107
Joined: Sat Jul 25, 2015 8:06 pm

Re: Feather M0 - Lipo Voltage reading - Bug in tutorial ?

by adafruit_support_mike on Sat Apr 30, 2016 3:23 am

The SAMD21's ADC has configurable resolution. The default is 10-bit to make it compatible with all the other Arduino code that already exists.

You can change it with the analogReadResolution() function: http://www.arduino.cc/en/Reference/AnalogReadResolution

adafruit_support_mike
 
Posts: 54125
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.