Go Down

Topic: MKRFOX1200 read battery voltage (Read 9695 times) previous topic - next topic

etimou

hi! What  do you mean by correct values?
Are you getting values that are close to 3V? and not always 3.3V as I observed?

miot_es

Hello.
I am really feeding with a power supply with which I can change the voltage if I give it 3V it gives me 3V if it goes down to 2.9V it gives me 2.9V, so I think it is giving the correct values.

Regards.

etimou

#17
May 27, 2020, 04:06 pm Last Edit: May 27, 2020, 04:07 pm by etimou
This is absolutely what it should do. I don't know what I am doing wrong. I tested with a second unit and I got the same problem. Always getting 3.3V when powered from the screw terminal. Is it possible that I have two faulty modules? Or that I did something that damaged them and cause this malfunction?

etimou

#18
May 27, 2020, 04:39 pm Last Edit: May 27, 2020, 04:39 pm by etimou
ok, working better with the 1.1V analog reference.
Now I can see some fluctuation but I am wondering how we shall calculate the theoretical multiplier.


voltage = (1.1/(2^10-1))*(68+33)/33  *  analogRead(ADC_BATTERY)

Is it correct?

miot_es

Since it really is powered by 3v I change

"float voltage = sensorValue * (3.25 / 1023.0);"

by

"float voltage = sensorValue * ( 3/ 1023.0);"


miot_es

These days I plan to do more tests with some modules that I am waiting for.

I will tell you the results.

Regards.
 :)

etimou

Since it really is powered by 3v I change

"float voltage = sensorValue * (3.25 / 1023.0);"

by

"float voltage = sensorValue * ( 3/ 1023.0);"


The measurement should not depend on the nominal voltage since we want to measure this voltage.

I also did more testing and here my conclusions:
- it works using the 1.0V built-in analog reference
- As the reference is 1.0V and not 1.1V as in the AVR boards the theoretical calculation is:
voltage = sensorValue * (1.0/(2^10-1))*(68+33)/33
voltage = sensorValue * (3.061 / 1023.0)
voltage = sensorValue * 0.00299
- The ADC saturates at 3.061V so it will not be possible to measure voltage higher than this value.
- this is theoretical and off course the multiplier can be adjusted to compensate the component tolerance
- For some reason that I can't explain now, it does not work well with the 1.65V internal reference when no power is applied to the micro USB port.

Working code:

Code: [Select]

analogReadResolution(10);//10bits
analogReference(AR_INTERNAL1V0);//1.0V built-in reference
int sensorValue = analogRead(ADC_BATTERY);
float voltage = sensorValue * 0.00299; // (1.0/(2^10-1))*(68+33)/33






miot_es

Thank you very much etimou.
Regards.

Go Up