|
@@ -1,6 +1,8 @@
|
|
|
#include "vbus_sensor.h"
|
|
#include "vbus_sensor.h"
|
|
|
#include "bsp/bsp.h"
|
|
#include "bsp/bsp.h"
|
|
|
#include "bsp/adc.h"
|
|
#include "bsp/adc.h"
|
|
|
|
|
+#include "math/fast_math.h"
|
|
|
|
|
+
|
|
|
static vbus_t _vbus;
|
|
static vbus_t _vbus;
|
|
|
void vbus_sensor_init(void){
|
|
void vbus_sensor_init(void){
|
|
|
_vbus.voltage_avg = 0;
|
|
_vbus.voltage_avg = 0;
|
|
@@ -11,7 +13,12 @@ void vbus_sensor_init(void){
|
|
|
void vbus_sample_voltage(void){
|
|
void vbus_sample_voltage(void){
|
|
|
u32 vadc = adc_sample_regular_channel(VBUS_V_CHAN, 16);
|
|
u32 vadc = adc_sample_regular_channel(VBUS_V_CHAN, 16);
|
|
|
|
|
|
|
|
- //_vbus.voltage_avg = ((float)vadc)/(65536.0f) * ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR;
|
|
|
|
|
|
|
+ _vbus.voltage_avg = ((float)vadc)/(65536.0f) * ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR;
|
|
|
|
|
+ if (_vbus.voltage_filted == 0.0f) {
|
|
|
|
|
+ _vbus.voltage_filted = _vbus.voltage_avg;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ LowPass_Filter(_vbus.voltage_filted, _vbus.voltage_avg, 0.1f);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|