diff --git a/hwconf/hw_stormcore_100d.c b/hwconf/hw_stormcore_100d.c index f38c7364..192c87bf 100644 --- a/hwconf/hw_stormcore_100d.c +++ b/hwconf/hw_stormcore_100d.c @@ -354,7 +354,7 @@ static THD_FUNCTION(mux_thread, arg) { ENABLE_V_BATT_DIV(); - chThdSleepMicroseconds(300); + chThdSleepMicroseconds(400); ADC_Value[ADC_IND_V_BATT] = ADC_Value[ADC_IND_ADC_MUX]; } } @@ -371,11 +371,15 @@ void smart_switch_keep_on(void) { } void smart_switch_shut_down(void) { + mc_interface_select_motor_thread(2); + mc_interface_set_current(0); + mc_interface_lock(); + mc_interface_select_motor_thread(1); + mc_interface_set_current(0); + mc_interface_lock(); switch_state = SWITCH_SHUTTING_DOWN; palClearPad(SWITCH_OUT_GPIO, SWITCH_OUT_PIN); -#ifdef HW_HAS_STORMCORE_SWITCH palClearPad(SWITCH_PRECHARGED_GPIO, SWITCH_PRECHARGED_PIN); -#endif return; } @@ -405,7 +409,7 @@ static THD_FUNCTION(switch_color_thread, arg) { utils_fast_sincos_better(angle + 6.28/3.0, &s, &c); switch_red = 0.75* c*c; ledpwm_set_intensity(LED_HW3,switch_bright*switch_red); - chThdSleepMilliseconds(10); + chThdSleepMilliseconds(4); } float switch_red_old = switch_red_old; float switch_green_old = switch_green; @@ -430,7 +434,7 @@ static THD_FUNCTION(switch_color_thread, arg) { ledpwm_set_intensity(LED_HW1, switch_bright*blue_now); ledpwm_set_intensity(LED_HW2, switch_bright*green_now); ledpwm_set_intensity(LED_HW3, switch_bright*red_now); - chThdSleepMilliseconds(10); + chThdSleepMilliseconds(2); } for (;;) { @@ -494,8 +498,28 @@ static THD_FUNCTION(smart_switch_thread, arg) { break; case SWITCH_TURN_ON_DELAY_ACTIVE: switch_state = SWITCH_HELD_AFTER_TURN_ON; - chThdSleepMilliseconds(5000); + mc_interface_select_motor_thread(2); + mc_interface_set_current(0); + mc_interface_lock(); + mc_interface_select_motor_thread(1); + mc_interface_set_current(0); + mc_interface_lock(); + int cts = 0; + while((ADC_Value[ADC_IND_V_BATT] < 1 || ADC_Value[ADC_IND_VIN_SENS] < 1) && (cts < 50)){ + chThdSleepMilliseconds(100); + cts++; + } + cts = 0; + while(((GET_BATT_VOLTAGE() - GET_INPUT_VOLTAGE()) > 8.0) && (cts < 50)){ + chThdSleepMilliseconds(100); + cts++; + } + palSetPad(SWITCH_PRECHARGED_GPIO, SWITCH_PRECHARGED_PIN); + mc_interface_select_motor_thread(2); + mc_interface_unlock(); + mc_interface_select_motor_thread(1); + mc_interface_unlock(); break; case SWITCH_HELD_AFTER_TURN_ON: smart_switch_keep_on(); diff --git a/hwconf/hw_stormcore_100d.h b/hwconf/hw_stormcore_100d.h index 698cde63..331a4543 100644 --- a/hwconf/hw_stormcore_100d.h +++ b/hwconf/hw_stormcore_100d.h @@ -233,9 +233,11 @@ #define CURRENT_SHUNT_RES 0.001 #endif +#define VBATT_R1 360000.0 +#define VBATT_R2 10000.0 // Input voltage #define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2)) -#define GET_BATT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_V_BATT] * ((VIN_R1 + VIN_R2) / VIN_R2)) +#define GET_BATT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_V_BATT] * ((VBATT_R1 + VBATT_R2) / VBATT_R2)) #define GET_VM_SENSE_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VM_SENSE] * ((VIN_R1 + VIN_R2) / VIN_R2)) // Voltage on ADC channel diff --git a/hwconf/hw_stormcore_60d.c b/hwconf/hw_stormcore_60d.c index 90df3f08..79ac74d9 100644 --- a/hwconf/hw_stormcore_60d.c +++ b/hwconf/hw_stormcore_60d.c @@ -357,21 +357,19 @@ static THD_FUNCTION(mux_thread, arg) { void smart_switch_keep_on(void) { palSetPad(SWITCH_OUT_GPIO, SWITCH_OUT_PIN); - //#ifdef HW_HAS_RGB_SWITCH - // LED_SWITCH_B_ON(); - // ledpwm_set_intensity(SWITCH_LED_B, 1.0); - //#else - // ledpwm_set_intensity(SWITCH_LED, 1.0); - // ledpwm_set_switch_intensity(0.6); - //#endif + } void smart_switch_shut_down(void) { + mc_interface_select_motor_thread(2); + mc_interface_set_current(0); + mc_interface_lock(); + mc_interface_select_motor_thread(1); + mc_interface_set_current(0); + mc_interface_lock(); switch_state = SWITCH_SHUTTING_DOWN; palClearPad(SWITCH_OUT_GPIO, SWITCH_OUT_PIN); -#ifdef HW_HAS_STORMCORE_SWITCH palClearPad(SWITCH_PRECHARGED_GPIO, SWITCH_PRECHARGED_PIN); -#endif return; } @@ -401,7 +399,7 @@ static THD_FUNCTION(switch_color_thread, arg) { utils_fast_sincos_better(angle + 6.28/3.0, &s, &c); switch_red = 0.75* c*c; ledpwm_set_intensity(LED_HW3,switch_bright*switch_red); - chThdSleepMilliseconds(10); + chThdSleepMilliseconds(4); } float switch_red_old = switch_red_old; float switch_green_old = switch_green; @@ -426,7 +424,7 @@ static THD_FUNCTION(switch_color_thread, arg) { ledpwm_set_intensity(LED_HW1, switch_bright*blue_now); ledpwm_set_intensity(LED_HW2, switch_bright*green_now); ledpwm_set_intensity(LED_HW3, switch_bright*red_now); - chThdSleepMilliseconds(10); + chThdSleepMilliseconds(2); } for (;;) { @@ -491,8 +489,28 @@ static THD_FUNCTION(smart_switch_thread, arg) { break; case SWITCH_TURN_ON_DELAY_ACTIVE: switch_state = SWITCH_HELD_AFTER_TURN_ON; - chThdSleepMilliseconds(5000); + mc_interface_select_motor_thread(2); + mc_interface_set_current(0); + mc_interface_lock(); + mc_interface_select_motor_thread(1); + mc_interface_set_current(0); + mc_interface_lock(); + int cts = 0; + while((ADC_Value[ADC_IND_V_BATT] < 1 || ADC_Value[ADC_IND_VIN_SENS] < 1) && (cts < 50)){ + chThdSleepMilliseconds(100); + cts++; + } + cts = 0; + while(((GET_BATT_VOLTAGE() - GET_INPUT_VOLTAGE()) > 8.0) && (cts < 50)){ + chThdSleepMilliseconds(100); + cts++; + } + palSetPad(SWITCH_PRECHARGED_GPIO, SWITCH_PRECHARGED_PIN); + mc_interface_select_motor_thread(2); + mc_interface_unlock(); + mc_interface_select_motor_thread(1); + mc_interface_unlock(); break; case SWITCH_HELD_AFTER_TURN_ON: smart_switch_keep_on(); diff --git a/hwconf/hw_stormcore_60d.h b/hwconf/hw_stormcore_60d.h index 3f7a038c..38d5497b 100644 --- a/hwconf/hw_stormcore_60d.h +++ b/hwconf/hw_stormcore_60d.h @@ -378,6 +378,9 @@ #ifndef MCCONF_M_DRV8301_OC_ADJ #define MCCONF_M_DRV8301_OC_ADJ 14 #endif +#ifndef MCCONF_L_DUTY_START +#define MCCONF_L_DUTY_START 0.9 // Start limiting current at this duty cycle +#endif #ifndef MCCONF_L_MAX_ABS_CURRENT #define MCCONF_L_MAX_ABS_CURRENT 200.0 // The maximum absolute current above which a fault is generated #endif diff --git a/hwconf/hw_unity.h b/hwconf/hw_unity.h index 24c6c5d8..9b68d5b1 100644 --- a/hwconf/hw_unity.h +++ b/hwconf/hw_unity.h @@ -17,9 +17,18 @@ #ifndef HW_UNITY_H_ #define HW_UNITY_H_ -#define HW_NAME "UNITY" - +#ifdef HW_DUAL_CONFIG_PARALLEL +#define HW_HAS_DUAL_PARALLEL +#else #define HW_HAS_DUAL_MOTORS +#endif + +#ifdef HW_HAS_DUAL_PARALLEL +#define HW_NAME "UNITY_PARALLEL" +#else +#define HW_NAME "UNITY" +#endif + #define HW_HAS_DRV8301 //#define HW_HAS_3_SHUNTS //#define HW_HAS_PHASE_SHUNTS @@ -305,9 +314,22 @@ #endif // Setting limits -#define HW_LIM_CURRENT -150.0, 150.0 -#define HW_LIM_CURRENT_IN -120.0, 120.0 +#ifdef HW_HAS_DUAL_PARALLEL +#define HW_LIM_CURRENT -300.0, 300.0 +#define HW_LIM_CURRENT_ABS 800.0, 804.0 +#define HW_LIM_CURRENT_IN -200.0, 200.0 +#ifndef MCCONF_L_MAX_ABS_CURRENT +#define MCCONF_L_MAX_ABS_CURRENT 400.0 // The maximum absolute current above which a fault is generated +#endif +#else +#define HW_LIM_CURRENT -150.0, 150.0 #define HW_LIM_CURRENT_ABS 400.0, 402.0 +#define HW_LIM_CURRENT_IN -100.0, 100.0 +#ifndef MCCONF_L_MAX_ABS_CURRENT +#define MCCONF_L_MAX_ABS_CURRENT 200.0 // The maximum absolute current above which a fault is generated +#endif +#endif + #define HW_LIM_VIN 6.0, 59.0 #define HW_LIM_ERPM -200e3, 200e3 #define HW_LIM_DUTY_MIN 0.0, 0.1