From 4f1ad7b2023e325c0ff208d9f4be69a03f5c64ad Mon Sep 17 00:00:00 2001 From: Carlos Augusto Porto Freitas Date: Mon, 15 Jul 2024 14:47:04 -0300 Subject: [PATCH] firmware: devices: voltage_sensor: Change filter first sample --- firmware/devices/voltage_sensor/voltage_sensor.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/firmware/devices/voltage_sensor/voltage_sensor.c b/firmware/devices/voltage_sensor/voltage_sensor.c index 646af43d..53873428 100644 --- a/firmware/devices/voltage_sensor/voltage_sensor.c +++ b/firmware/devices/voltage_sensor/voltage_sensor.c @@ -37,7 +37,8 @@ #include "voltage_sensor.h" -#define ALPHA_ (0.05) +#define ALPHA_ (0.01) +#define VOLTAGE_INIT (3300U) static uint16_t voltage; @@ -59,20 +60,17 @@ int voltage_sensor_init(void) if (adc_init() == 0) { - uint16_t volt = 0; + uint16_t volt = 0U; - if (voltage_sensor_read_raw(&volt) == 0) + voltage = VOLTAGE_INIT; + + if (voltage_sensor_read_mv(&volt) == 0) { - volt = voltage_sensor_raw_to_mv(volt); - sys_log_print_event_from_module(SYS_LOG_INFO, VOLTAGE_SENSOR_MODULE_NAME, "Current input voltage: "); sys_log_print_uint(volt); sys_log_print_msg(" mV"); sys_log_new_line(); - - /* First sample for the filter */ - voltage = volt; - + err = 0; } else