#include "vbus_sensor.h" #include "bsp/bsp.h" #include "bsp/adc.h" #include "math/fast_math.h" static vbus_t _vbus; void vbus_sensor_init(void){ _vbus.voltage = 0; _vbus.voltage_filted = MAX_VBUS_VOLTAGE; _vbus.avg_count = 5; vbus_sample_voltage(); } void vbus_sample_voltage(void){ u32 vadc = adc_sample_regular_channel(VBUS_V_CHAN, 16); _vbus.voltage = ((float)vadc)/(4096.0f) * ADC_REFERENCE_VOLTAGE * 45 / 1000; //1:44 LowPass_Filter(_vbus.voltage_filted, _vbus.voltage, 0.1f); } float vbus_get_filted_voltage(void){ return _vbus.voltage_filted; }