Просмотр исходного кода

mc105 油门5v采集,启动autohold点亮刹车灯

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 лет назад
Родитель
Сommit
489c69ee34

+ 26 - 2
Applications/bsp/adc.c

@@ -173,7 +173,7 @@ static void adc0_init(void){
 	adc_regular_channel_config(ADC0, 6, ADC_CHANNEL_10, ADC_REGCHAN_SAMPLE_TIME);
 	adc_regular_channel_config(ADC0, 7, ADC_CHANNEL_17, ADC_REGCHAN_SAMPLE_TIME);
 	adc_tempsensor_vrefint_enable();
-	adc_buffer[7] = VREF_ADC_DATA; //1.21/3.3*4095
+	adc_buffer[VREF_BUFF_IDX] = VREF_ADC_DATA; //1.21/3.3*4095
 #elif (CONFIG_HW_VERSION==3)
 	adc_regular_channel_config(ADC0, 0, MOS_TEMP_ADC_CHAN, ADC_REGCHAN_SAMPLE_TIME);
 	adc_regular_channel_config(ADC0, 1, MOTOR_TEMP_ADC_CHAN, ADC_REGCHAN_SAMPLE_TIME);
@@ -188,7 +188,7 @@ static void adc0_init(void){
 	adc_regular_channel_config(ADC0, 10, ZERO_ADC_CHAN, ADC_REGCHAN_SAMPLE_TIME); //insert zero vol
 	adc_regular_channel_config(ADC0, 11, DC5V_ADC_CHAN, ADC_REGCHAN_SAMPLE_TIME);
 	adc_tempsensor_vrefint_enable();
-	adc_buffer[7] = VREF_ADC_DATA; //1.21/3.3*4095
+	adc_buffer[VREF_BUFF_IDX] = VREF_ADC_DATA; //1.21/3.3*4095
 #endif
 #endif
     /* configure ADC regular channel trigger */
@@ -460,6 +460,30 @@ u16 adc_get_throttle(void) {
 	return adc_buffer[THROTTLE_BUFF_IDX] * VREF_3V3_COMPESTION();
 }
 
+u16 adc_get_throttle2(void) {
+#ifdef THROTTLE2_BUFF_IDX
+	return adc_buffer[THROTTLE2_BUFF_IDX] * VREF_3V3_COMPESTION();
+#else
+	return adc_get_throttle();
+#endif
+}
+
+u16 adc_get_thro_5v(void) {
+#ifdef THROTTLE_5V_BUFF_IDX
+	return adc_buffer[THROTTLE_5V_BUFF_IDX] * VREF_3V3_COMPESTION();
+#else
+	return 0;
+#endif
+}
+
+u16 adc_get_thro2_5v(void) {
+#ifdef THROTTLE2_5V_BUFF_IDX
+	return adc_buffer[THROTTLE2_5V_BUFF_IDX] * VREF_3V3_COMPESTION();
+#else
+	return 0;
+#endif
+}
+
 void adc_get_uvw_phaseV(u16 *uvw) {
 	uvw[0] = adc_buffer[U_VOL_BUFF_IDX];
 	uvw[1] = adc_buffer[V_VOL_BUFF_IDX];

+ 3 - 0
Applications/bsp/adc.h

@@ -177,5 +177,8 @@ void adc_set_vref_calc(float v);
 void adc_vref_filter(void);
 u16 adc_get_5v_ref(void);
 void adc_set_5vref_calc(float v);
+u16 adc_get_throttle2(void);
+u16 adc_get_thro_5v(void);
+u16 adc_get_thro2_5v(void);
 
 #endif /* _ADC_H__ */

+ 5 - 0
Applications/foc/motor/motor.c

@@ -784,6 +784,11 @@ bool mc_auto_hold(bool hold) {
 	}else {
 		PMSM_FOC_AutoHold(hold);
 	}
+	if (motor.b_auto_hold) {
+		gpio_brk_light_enable(true);
+	}else {
+		gpio_brk_light_enable(false);
+	}
 	cpu_exit_critical(mask);
 	return true;
 }

+ 47 - 9
Applications/foc/samples.c

@@ -21,7 +21,7 @@ static u32 sample_task(void *);
 static samples_t _vbus;
 static samples_t _vref;
 #ifdef THROTTLE_CHAN
-static samples_t _throttle;
+static samples_t _throttle[2];
 #endif
 #ifdef U_VOL_ADC_CHAN
 static samples_t _uvw_phase[3];
@@ -54,9 +54,14 @@ void samples_init(void){
 	sample_vbus();
 
 #ifdef THROTTLE_CHAN
-	_throttle.filted_value = (0);
-	_throttle.value = (0);
-	_throttle.lowpass = (0.01f); 
+	_throttle[0].value = (float)adc_get_throttle() * THROTTLE_VOL_CEOF;
+	_throttle[0].filted_value = _throttle[0].value;
+	_throttle[0].lowpass = (0.01f);
+#ifdef THROTTLE2_CHAN
+	_throttle[1].value = (float)adc_get_throttle2() * THROTTLE_VOL_CEOF;
+	_throttle[1].filted_value = _throttle[1].value;
+	_throttle[1].lowpass = (0.01f);
+#endif
 	sample_throttle();
 #endif
 #ifdef U_VOL_ADC_CHAN
@@ -70,12 +75,12 @@ void samples_init(void){
 #endif
 #ifdef MOTOR_TEMP_ADC_CHAN
 	motor_temp.value = motor_temp.filted_value = 0;
-	motor_temp.lowpass = 0.01f;
+	motor_temp.lowpass = 0.1f;
 	sample_motor_temp();
 #endif
 #ifdef MOS_TEMP_ADC_CHAN
 	mos_temp.value = mos_temp.filted_value = 0;
-	mos_temp.lowpass = 0.01f;
+	mos_temp.lowpass = 0.1f;
 	sample_mos_temp();
 #endif
 #ifdef VBUS_I_CHAN
@@ -128,16 +133,42 @@ s16 get_mos_temp(void) {
 
 float get_throttle_float(void) {
 #ifdef THROTTLE_CHAN
-	return _throttle.filted_value;
+	return _throttle[0].filted_value;
 #else
 	return 0.0f;
 #endif
 }
 
+float get_throttle2_float(void) {
+#ifdef THROTTLE2_CHAN
+	return _throttle[1].filted_value;
+#else
+	return get_throttle_float();
+#endif
+}
+
+
 float get_adc_vref(void) {
 	return _vref.filted_value;
 }
 
+float get_thro_5v_float(void) {
+	u16 adc = adc_get_thro_5v();
+	if (adc == 0) {
+		return 5.0f;
+	}
+	return (float)adc * (ADC_REFERENCE_VOLTAGE*(2.0f)/ADC_FULL_MAX);
+}
+
+float get_thro2_5v_float(void) {
+	u16 adc = adc_get_thro2_5v();
+	if (adc == 0) {
+		return 5.0f;
+	}
+	return (float)adc * (ADC_REFERENCE_VOLTAGE*(2.0f)/ADC_FULL_MAX);
+}
+
+
 static u32 sample_task(void *param) {
 	sample_vbus();
 	sample_ibus();
@@ -190,10 +221,17 @@ void sample_ibus_offset(u16 offset) {
 void sample_throttle(void){
 #ifdef THROTTLE_CHAN
 	s16 vadc = adc_get_throttle();
-	_throttle.value = (float)vadc * THROTTLE_VOL_CEOF;
-	LowPass_Filter(_throttle.filted_value, _throttle.value, _throttle.lowpass);
+	_throttle[0].value = (float)vadc * THROTTLE_VOL_CEOF;
+	LowPass_Filter(_throttle[0].filted_value, _throttle[0].value, _throttle[0].lowpass);
 #endif
+#ifdef THROTTLE2_CHAN
+	s16 vadc2 = adc_get_throttle2();
+	_throttle[1].value = (float)vadc2 * THROTTLE_VOL_CEOF;
+	LowPass_Filter(_throttle[1].filted_value, _throttle[1].value, _throttle[1].lowpass);
+#endif
+
 }
+
 void sample_uvw_phase(void) {
 #ifdef U_VOL_ADC_CHAN
 	u16 uvw[3];

+ 2 - 0
Applications/foc/samples.h

@@ -24,6 +24,8 @@ s16 get_mos_temp2(void);
 float get_vbus_current(void);
 void sample_ibus_offset(u16 offset);
 float get_adc_vref(void);
+float get_thro2_5v_float(void);
+float get_thro_5v_float(void);
 
 #endif /* _SAMPLES_H__ */