Explorar o código

update 母线电压采集,加一个专门存放低通滤波后的电压

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=4) %!d(string=hai) anos
pai
achega
7d718862b6

+ 0 - 1
Applications/foc/foc_core.c

@@ -253,7 +253,6 @@ static void foc_measure_task(void *args){
 	while(1) {
 		vbus_sample_voltage();
 		ntc_sensor_sample();
-		LowPass_Filter(g_foc.vbus, vbus_get_voltage(), 0.1f);
 		wdog_reload();
 		co_task_yield();
 	}

+ 8 - 1
Applications/foc/vbus_sensor.c

@@ -1,6 +1,8 @@
 #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_avg = 0;
@@ -11,7 +13,12 @@ void vbus_sensor_init(void){
 void vbus_sample_voltage(void){
 	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);
+	}
 }
 
 

+ 1 - 0
Applications/foc/vbus_sensor.h

@@ -9,6 +9,7 @@
 
 typedef struct {
 	float voltage_avg;
+	float voltage_filted;
 	int avg_count;
 }vbus_t;