top of page

Software

Public·142 members

Reading the battery voltage

(aside: I think something went south on the first attempt of this post so this may be a duplicate)


I'm writing unit/feature tests of the serial protocol API and I'm working on the analog read command (Ra<pin>). The pin I use (VOLTAGE, pin 4) comes from the lowBattery function in reaction.h and is defined in opencat.h.

The test is performed on a fully changed battery. I'm having difficulty understanding the response:


=
383
R

I expected to get a value between 0 - 4096 but at the high end of the range. The lowBattery code reads the value into a float


bool lowBattery() {
    //...
    float voltage = analogRead(VOLTAGE);

and compares the value with a precalculated low_voltage value:


//...
float vFactor = 4096 / 3.3 / 3;
float low_voltage = LOW_VOLTAGE * vFactor;
//...
if (voltage == 0 || voltage < low_voltage ...)

The value of vFactor should be 413.73..., and thus the value of low_voltage is 2813.41...


This doesn't look right. So, I'm missing something here. Is the command response (383) valid? I expect it to be an integer. I don't understand the calculation in lowBattery.

:

46 Views
Timothy McCarthy
Timothy McCarthy
22 avr. 2024

I want to be sure I understand something. When you say "the pin definition for BiBoard2 has not been released" you mean that the code isn't in production and should not be compiled in the OpenCat32 code base.


bottom of page