Skip to content

Commit

Permalink
Merge pull request #242 from Jfriesen222/dev_fw_5_02
Browse files Browse the repository at this point in the history
Changed stormcore config to use cleaner turn on routine
  • Loading branch information
vedderb authored Dec 6, 2020
2 parents 7207fce + ba097e1 commit 9c96de5
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 23 deletions.
36 changes: 30 additions & 6 deletions hwconf/hw_stormcore_100d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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 (;;) {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion hwconf/hw_stormcore_100d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 30 additions & 12 deletions hwconf/hw_stormcore_60d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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 (;;) {
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions hwconf/hw_stormcore_60d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 26 additions & 4 deletions hwconf/hw_unity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9c96de5

Please sign in to comment.