Skip to content

Commit

Permalink
Add initial voltage log.
Browse files Browse the repository at this point in the history
Log in V vs mV.
Add link to help.
  • Loading branch information
erichelgeson committed May 14, 2023
1 parent 77919d1 commit ba4b501
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ static void usb_log_poll()
// Use ADC to implement supply voltage monitoring for the +3.0V rail.
// This works by sampling the temperature sensor channel, which has
// a voltage of 0.7 V, allowing to calculate the VDD voltage.
static bool adc_initial_log = true;
static void adc_poll()
{
#if PLATFORM_VDD_WARNING_LIMIT_mV > 0
Expand Down Expand Up @@ -391,10 +392,16 @@ static void adc_poll()
int vdd_mV = (700 * 4096) / adc_value_max;
if (vdd_mV < lowest_vdd_seen)
{
log("WARNING: Detected supply voltage drop to ", vdd_mV, "mV. Verify power supply is adequate.");
log("WARNING: Detected voltage drop to ", (vdd_mV / 1000.0), "V - See: https://www.github.com/BlueSCSI/BlueSCSI-v2/wiki/Low-Voltage");
lowest_vdd_seen = vdd_mV - 50; // Small hysteresis to avoid excessive warnings
}
}
else if (adc_initial_log && adc_value_max != 0)
{
adc_initial_log = false;
int vdd_mV = (700 * 4096) / adc_value_max;
log("INFO: Pico Voltage: ", (vdd_mV / 1000.0), "V.");
}
#endif
}

Expand Down
7 changes: 7 additions & 0 deletions src/BlueSCSI_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ void log_raw(bytearray array)
}
}

void log_raw(double value)
{
char buffer[6];
snprintf(buffer, sizeof buffer, "%0.3f", value);
log_raw(buffer);
}

uint32_t log_get_buffer_len()
{
return g_logpos;
Expand Down
3 changes: 3 additions & 0 deletions src/BlueSCSI_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ void log_raw(uint64_t value);
// Log integer as decimal
void log_raw(int value);

// Log double
void log_raw(double value);

// Log array of bytes
struct bytearray {
bytearray(const uint8_t *data, size_t len): data(data), len(len) {}
Expand Down

0 comments on commit ba4b501

Please sign in to comment.