Skip to content

Commit

Permalink
hv com fix, ignore fault pin
Browse files Browse the repository at this point in the history
  • Loading branch information
crinq committed Apr 12, 2018
1 parent 2459f40 commit db711ec
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion shared/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef struct {
union {
struct {
uint8_t buf;
uint8_t enable : 1;
uint32_t enable : 1;
enum packet_to_hv_cmd_type_t {
VOLT_MODE = 0,
CURRENT_MODE,
Expand All @@ -80,6 +80,7 @@ typedef struct {
PHASE_180_2PH,
PHASE_180_3PH,
} phase_type : 3;
uint32_t ignore_fault_pin : 1;
} flags;
uint32_t padding;
};
Expand Down
6 changes: 3 additions & 3 deletions shared/f3hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#define HV_EN_PIN GPIO_PIN_15
#define HV_EN_PORT GPIOA
//fault pin cannot be used, as it is sometimes reset by the iram due to 15v ripple
//#define HV_FAULT_PIN GPIO_PIN_7
//#define HV_FAULT_PORT GPIOB
//#define HV_FAULT_POLARITY GPIO_PIN_RESET
#define HV_FAULT_PIN GPIO_PIN_7
#define HV_FAULT_PORT GPIOB
#define HV_FAULT_POLARITY GPIO_PIN_RESET
#define LED_PIN GPIO_PIN_8
#define LED_PORT GPIOA

Expand Down
8 changes: 6 additions & 2 deletions src/comps/hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ HAL_PIN(hv_temp);
HAL_PIN(mot_temp);
HAL_PIN(core_temp);
HAL_PIN(fault); //fault from hv
HAL_PIN(ignore_fault_pin);
HAL_PIN(y);
HAL_PIN(u_fb);
HAL_PIN(v_fb);
Expand Down Expand Up @@ -366,6 +367,7 @@ static void frt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst
ctx->to_hv.packet_to_hv.q_cmd = 0.0;
ctx->to_hv.packet_to_hv.flags.enable = 0;
}
ctx->to_hv.packet_to_hv.flags.ignore_fault_pin = PIN(ignore_fault_pin) > 0.0;
ctx->to_hv.packet_to_hv.flags.cmd_type = PIN(cmd_mode);
ctx->to_hv.packet_to_hv.flags.phase_type = PIN(phase_mode);
ctx->to_hv.packet_to_hv.pos = pos;
Expand Down Expand Up @@ -485,7 +487,9 @@ static void frt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst
}

if(ctx->send_state > 1){
tx_size = 0;
if(flash_state != SLAVE_IN_APP){
tx_size = 0;
}
ctx->send_state = 0;
}
ctx->send_state++;
Expand Down Expand Up @@ -534,7 +538,7 @@ static void nrt_func(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) {
printf("hv_update: status: %i%%\n", (int)(100.0 * ctx->addr * 4. / (float)((uint32_t) & (_binary_obj_hvf3_hvf3_bin_size))));
last_addr = ctx->addr;
}

if(last_flash_state != flash_state) {
switch(flash_state) {
case SLAVE_IN_APP:
Expand Down
8 changes: 5 additions & 3 deletions stm32f303/src/comps/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ HAL_PIN(hv_en);

//fault output
HAL_PIN(fault);
HAL_PIN(ignore_fault_pin);



volatile uint32_t adc_12_buf[6];
Expand Down Expand Up @@ -103,7 +105,7 @@ float r2temp(float r) {
return (-(r - b) / (a - b) * step + i * step + start);
}
}
return (temp[ARRAY_SIZE(temp)] + step); // TODO fix
return (temp[ARRAY_SIZE(temp) - 1] + step); // TODO fix
}

static void nrt_init(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) {
Expand Down Expand Up @@ -241,8 +243,8 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_
if(ctx->fault == NO_ERROR) {
#ifdef HV_FAULT_PIN
//read fault pin from driver
if(err_filter(&(ctx->fault_pin_error), 5.0, 0.01, HAL_GPIO_ReadPin(HV_FAULT_PORT, HV_FAULT_PIN) == HV_FAULT_POLARITY)) {
ctx->fault = HV_HV_FAULT;
if(PIN(ignore_fault_pin) <= 0.0 && err_filter(&(ctx->fault_pin_error), 5.0, 0.01, HAL_GPIO_ReadPin(HV_FAULT_PORT, HV_FAULT_PIN) == HV_FAULT_POLARITY)) {
ctx->fault = HV_FAULT_ERROR;
}
#endif
//Master out enable is cleared by timer break input.
Expand Down
2 changes: 2 additions & 0 deletions stm32f303/src/comps/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ HAL_PIN(hv_temp);
HAL_PIN(mot_temp);
HAL_PIN(core_temp);
HAL_PIN(fault_in); //fault code send to f4
HAL_PIN(ignore_fault_pin);
HAL_PIN(y);
HAL_PIN(u_fb);
HAL_PIN(v_fb);
Expand Down Expand Up @@ -214,6 +215,7 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_
PIN(en) = ctx->packet_to_hv.flags.enable;
PIN(phase_mode) = ctx->packet_to_hv.flags.phase_type;
PIN(cmd_mode) = ctx->packet_to_hv.flags.cmd_type;
PIN(ignore_fault_pin) = ctx->packet_to_hv.flags.ignore_fault_pin;
PIN(d_cmd) = ctx->packet_to_hv.d_cmd;
PIN(q_cmd) = ctx->packet_to_hv.q_cmd;
PIN(pos) = ctx->packet_to_hv.pos;
Expand Down
1 change: 1 addition & 0 deletions stm32f303/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ int main(void) {
hal_parse("curpid0.en = ls0.en");
hal_parse("curpid0.cmd_mode = ls0.cmd_mode");
hal_parse("hv0.arr = ls0.arr");
hal_parse("io0.ignore_fault_pin = ls0.ignore_fault_pin");
hal_parse("debug_level 0");

// hal parse config
Expand Down

0 comments on commit db711ec

Please sign in to comment.