Skip to content

Fix rak11310 Voltage Read #6618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ class AnalogBatteryLevel : public HasBatteryLevel
raw = raw / BATTERY_SENSE_SAMPLES;
scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / pow(2, BATTERY_SENSE_RESOLUTION_BITS)) * raw;
#endif
#if defined(RAK11310)
float voltage_raw = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / 1023) * raw;

LOG_INFO("[POWER DEBUG] AREF=%.2fV, ADC_RAW=%u, ADC_MULT=%.2f",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't log an info called 'DEBUG' :-)

(double)AREF_VOLTAGE,
raw,
(double)operativeAdcMultiplier);

scaled = (voltage_raw * 1.22f) - 0.1f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.22f seems to be a correction factor. can we make this a generic correction macro and remove the #ifdef bracket? In case we need it on more than the 11310

scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / 4096) * raw;
Copy link
Member

@caveman99 caveman99 Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are computing scaled twice here. either the latter is in here by mistake or you can drop the former one.

LOG_INFO("[POWER CORRECTION] Before=%.2fmV, After=%.2fmV",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop the [POWER CORRECTION] - Log lines will be auto-prefixed with the thread name.

(double)voltage_raw,
(double)scaled);
#else
scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / 1023) * raw;
#endif
adcDisable();

if (!initial_read_done) {
Expand Down