From ffaa78798ec47faee2c0c44db397c01d44bf6b4e Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 18 Sep 2023 18:30:42 +0200 Subject: [PATCH] stop at set volume --- Core/Inc/PSE_unit.h | 17 +++++++++++------ Core/Src/PSE_unit_edit_screen.c | 7 +++++++ Core/Src/home_screen.c | 3 ++- Core/Src/pse_stepper_planer.c | 4 +++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Core/Inc/PSE_unit.h b/Core/Inc/PSE_unit.h index b32d8d4..07213f6 100644 --- a/Core/Inc/PSE_unit.h +++ b/Core/Inc/PSE_unit.h @@ -14,37 +14,42 @@ #include "lvgl.h" +// syringe definition typedef struct{ char name[16]; // brand / name uint16_t diameter; // diameter (in µm) } pse_syringe; +// Ports available typedef enum {PORT_X, PORT_Y, PORT_Z, PORT_E} pse_ports; +// stepper controller definitions typedef struct{ - uint16_t tim_presc; - uint16_t tim_period; + uint16_t tim_presc; // timer prescaler + uint16_t tim_period; // timer period - uint32_t tick_counter; int32_t steps_counter; - uint8_t stopAtHome; + uint8_t stop_at_limit; // boolean to stop at stop_steps + int32_t stop_steps; // position to stop at - GPIO_TypeDef* EN_GPIO_Port; + GPIO_TypeDef* EN_GPIO_Port; // Pin definitions uint16_t EN_GPIO_Pin; GPIO_TypeDef* DIR_GPIO_Port; uint16_t DIR_GPIO_Pin; GPIO_TypeDef* STEP_GPIO_Port; uint16_t STEP_GPIO_Pin; - TIM_HandleTypeDef* tim; + TIM_HandleTypeDef* tim; // timer assigned to this unit } pse_stepper_conf; +// readout widgets associated with this unit typedef struct{ lv_obj_t* flow; lv_obj_t* volume; lv_obj_t* enabled; } pse_home_display; +// unit definition typedef struct{ uint8_t enabled; pse_ports port; // physical port on which this unit is connected diff --git a/Core/Src/PSE_unit_edit_screen.c b/Core/Src/PSE_unit_edit_screen.c index bd43e7d..2511aaa 100644 --- a/Core/Src/PSE_unit_edit_screen.c +++ b/Core/Src/PSE_unit_edit_screen.c @@ -36,6 +36,13 @@ static void back_button_handler(lv_event_t * e){ // compute volume delivered per steps pse_unit_compute_volume_per_step(c_pse_unit); + // set limit if volume defined + if(c_pse_unit->set_volume != 0){ + c_pse_unit->stepper_conf->stop_at_limit = 1; + c_pse_unit->stepper_conf->stop_steps = (uint64_t)1000 * c_pse_unit->set_volume / c_pse_unit->nL_per_step; } + else + c_pse_unit->stepper_conf->stop_at_limit = 0; + // go back to the main menu Home_Screen_Gen(c_pse_units, c_pse_units_num, true); } diff --git a/Core/Src/home_screen.c b/Core/Src/home_screen.c index 97dba8f..4f80bdb 100644 --- a/Core/Src/home_screen.c +++ b/Core/Src/home_screen.c @@ -96,7 +96,8 @@ static void unit_home_handler(lv_event_t * e){ pse_unit* unit = lv_event_get_user_data(e); pse_stepper_conf* c = unit->stepper_conf; if(c->steps_counter == 0) return; - c->stopAtHome = 1; + c->stop_at_limit = 1; + c->stop_steps = 0; pse_sp_jog_speed(c, 1); pse_sp_set_dir(c, c->steps_counter < 0); pse_sp_start_axis(c); diff --git a/Core/Src/pse_stepper_planer.c b/Core/Src/pse_stepper_planer.c index 2b87a5f..1e45fe7 100644 --- a/Core/Src/pse_stepper_planer.c +++ b/Core/Src/pse_stepper_planer.c @@ -18,13 +18,15 @@ void pse_stepper_planer_tick(pse_unit* unit){ HAL_GPIO_TogglePin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin); c->steps_counter += (pse_sp_get_dir(c)?1:-1) * HAL_GPIO_ReadPin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin); - if(c->stopAtHome && c->steps_counter == 0){ + if(c->stop_at_limit && c->steps_counter == c->stop_steps){ pse_sp_jog_speed(c, 0); pse_sp_stop_axis(c); } } void pse_sp_start_axis(pse_stepper_conf* conf){ + if(conf->stop_at_limit && conf->steps_counter == conf->stop_steps) return; + HAL_GPIO_WritePin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin, GPIO_PIN_RESET); HAL_TIM_Base_Start_IT(conf->tim); }