From 401ddcf991e4fcd460dc8b4257cb594a06a4c267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 26 Nov 2021 13:27:19 +0000 Subject: [PATCH 1/8] [fw] update registers.xls with Protocol Direction --- Firmware/Pump/registers.xls | Bin 59392 -> 59392 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Firmware/Pump/registers.xls b/Firmware/Pump/registers.xls index b166fc036a049376ba700f6e3469728aabe14d8c..00be1e53bd83c444953a3cc5b6fe0acbd55cfdcb 100644 GIT binary patch delta 812 zcmb7>QAkr^6vzMHy?1l>-tC%AY{{|>BPb{uMu^aC&Ol|j9D|@e$kHK`wF}o(BFH9X z4@nk%$cP@YUV8As(M^dA=|zYl7`;eXz1UMv`KTH8eRtOO+Pz%9bN=U?-~aI4LRl=7 z#ZpGH`(7qiyi3%O?vO=uTUrt2LR(+nyR=S3Ij+-VYv&a zq>a^-qt5>2PcX8d@SY~8fJ42 zx2_7Fd)975y&6ZdaT>Iu9*sASYNsr`hnBc%zSgErbj%L$Ta;m>M$%)slrc7q288Zb z#A~Ts(l?yUC8wc6o#mp4w9b0!F+#7m$Lk)sciE5lWtQ7V-6szMmtxU)G#rf#cK60E zhU2}_el8k%P9M@UzTvcy8p@^htl1IiuRr`M2J~G8zGZ>qH-PLUuzVYMXg*EMc?W+( zL6BL7m^nZMJIe^VP|*d1;beLx6IoX6lF+@c+t7pUe_eLA_YTWeaR8lk>ZZG)6LpLq zVpJLHY$`%;jfcn;b8UR9nbVnJ&{~3?**r=YicR#$hN3uF;qnYnyhpc+JEm>!z2HB8 zANcSDn0XGk7lFsiK~v= DB_G1* delta 702 zcmb7>O=uHQ6ot>589RCNSEVHmqt=GjMG*z1Xi*5Jbs<>PN^xTsjU-5FZ6HmdF49!6 zLWP#fMF@fz+_(@VIw1I01hI&?h`LayE=ugiO>k8zmipdANw)G9bKbe#JYtL1VJ9c!+`^;2&ROx%nI}}!>PBU`8x`oA%K?-q<;s89n z1+bZ4VB!J%*R%~^!4Sd=MQkdlQqhcvmXhTfoB0OQrQaqOgQDruF{@E+NYCI1+7;BU zt@W!!b^qgU2y%qUOxRMey`B;V8MYaWT-tB*K($i8ZU0qcfs(XCb(-X8XbU(@mcO!V zc-h(bMzqtBNU=`QK%H=8aKzac;9V+7*MH_*?K+Yeke`twlf0N3&n7eDGuVce*_wGd znT@w6;@S8NOgxyArixTrWSXJVM9-j}ZdnsQV%;zIjI{WP{!`7~{8^y=0x&fOEKLAT z4mfuWI5@K5>pi!y+u<>B5sPr>B!$EKHTj80+-+T>0r) zTr4mViGp)lsO%=Q5T@L+VT8nB?FMjoE@(*JdZ$Fb%>$S20( Date: Fri, 26 Nov 2021 13:30:10 +0000 Subject: [PATCH 2/8] [fw] add Protocol Direction register --- Firmware/Pump/app_funcs.c | 23 +++++++++++++++++++++-- Firmware/Pump/app_funcs.h | 2 ++ Firmware/Pump/app_ios_and_regs.c | 5 ++++- Firmware/Pump/app_ios_and_regs.h | 6 ++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Firmware/Pump/app_funcs.c b/Firmware/Pump/app_funcs.c index ba11a9b..043ff44 100644 --- a/Firmware/Pump/app_funcs.c +++ b/Firmware/Pump/app_funcs.c @@ -34,7 +34,8 @@ void (*app_func_rd_pointer[])(void) = { &app_read_REG_CALIBRATION_VALUE_2, &app_read_REG_EVT_ENABLE, &app_read_REG_SET_BOARD_TYPE, - &app_read_REG_PROTOCOL_STATE + &app_read_REG_PROTOCOL_STATE, + &app_read_REG_PROTOCOL_DIRECTION }; bool (*app_func_wr_pointer[])(void*) = { @@ -60,7 +61,8 @@ bool (*app_func_wr_pointer[])(void*) = { &app_write_REG_CALIBRATION_VALUE_2, &app_write_REG_EVT_ENABLE, &app_write_REG_SET_BOARD_TYPE, - &app_write_REG_PROTOCOL_STATE + &app_write_REG_PROTOCOL_STATE, + &app_write_REG_PROTOCOL_DIRECTION }; @@ -582,4 +584,21 @@ bool app_write_REG_PROTOCOL_STATE(void *a) core_func_send_event(ADD_REG_PROTOCOL_STATE, true); return true; +} + +/************************************************************************/ +/* REG_PROTOCOL_DIRECTION */ +/************************************************************************/ +void app_read_REG_PROTOCOL_DIRECTION(void) +{ + //app_regs.REG_PROTOCOL_DIRECTION = 0; + +} + +bool app_write_REG_PROTOCOL_DIRECTION(void *a) +{ + uint8_t reg = *((uint8_t*)a); + + app_regs.REG_PROTOCOL_DIRECTION = reg; + return true; } \ No newline at end of file diff --git a/Firmware/Pump/app_funcs.h b/Firmware/Pump/app_funcs.h index faf5955..7525173 100644 --- a/Firmware/Pump/app_funcs.h +++ b/Firmware/Pump/app_funcs.h @@ -43,6 +43,7 @@ void app_read_REG_CALIBRATION_VALUE_2(void); void app_read_REG_EVT_ENABLE(void); void app_read_REG_SET_BOARD_TYPE(void); void app_read_REG_PROTOCOL_STATE(void); +void app_read_REG_PROTOCOL_DIRECTION(void); bool app_write_REG_ENABLE_MOTOR_DRIVER(void *a); bool app_write_REG_START_PROTOCOL(void *a); @@ -67,6 +68,7 @@ bool app_write_REG_CALIBRATION_VALUE_2(void *a); bool app_write_REG_EVT_ENABLE(void *a); bool app_write_REG_SET_BOARD_TYPE(void *a); bool app_write_REG_PROTOCOL_STATE(void *a); +bool app_write_REG_PROTOCOL_DIRECTION(void *a); #endif /* _APP_FUNCTIONS_H_ */ \ No newline at end of file diff --git a/Firmware/Pump/app_ios_and_regs.c b/Firmware/Pump/app_ios_and_regs.c index efb9926..0a360fd 100644 --- a/Firmware/Pump/app_ios_and_regs.c +++ b/Firmware/Pump/app_ios_and_regs.c @@ -83,6 +83,7 @@ uint8_t app_regs_type[] = { TYPE_U8, TYPE_U8, TYPE_U8, + TYPE_U8, TYPE_U8 }; @@ -109,6 +110,7 @@ uint16_t app_regs_n_elements[] = { 1, 1, 1, + 1, 1 }; @@ -135,5 +137,6 @@ uint8_t *app_regs_pointer[] = { (uint8_t*)(&app_regs.REG_CALIBRATION_VALUE_2), (uint8_t*)(&app_regs.REG_EVT_ENABLE), (uint8_t*)(&app_regs.REG_SET_BOARD_TYPE), - (uint8_t*)(&app_regs.REG_PROTOCOL_STATE) + (uint8_t*)(&app_regs.REG_PROTOCOL_STATE), + (uint8_t*)(&app_regs.REG_PROTOCOL_DIRECTION) }; \ No newline at end of file diff --git a/Firmware/Pump/app_ios_and_regs.h b/Firmware/Pump/app_ios_and_regs.h index 961397b..5a14c2b 100644 --- a/Firmware/Pump/app_ios_and_regs.h +++ b/Firmware/Pump/app_ios_and_regs.h @@ -136,6 +136,7 @@ typedef struct uint8_t REG_EVT_ENABLE; uint8_t REG_SET_BOARD_TYPE; uint8_t REG_PROTOCOL_STATE; + uint8_t REG_PROTOCOL_DIRECTION; } AppRegs; /************************************************************************/ @@ -165,6 +166,7 @@ typedef struct #define ADD_REG_EVT_ENABLE 52 // U8 Enable the Events #define ADD_REG_SET_BOARD_TYPE 53 // U8 Type of the board #define ADD_REG_PROTOCOL_STATE 54 // U8 State of the protocol (running or stopped) +#define ADD_REG_PROTOCOL_DIRECTION 55 // U8 Protocol direction /************************************************************************/ /* PWM Generator registers' memory limits */ @@ -174,8 +176,8 @@ typedef struct /************************************************************************/ /* Memory limits */ #define APP_REGS_ADD_MIN 0x20 -#define APP_REGS_ADD_MAX 0x36 -#define APP_NBYTES_OF_REG_BANK 31 +#define APP_REGS_ADD_MAX 0x37 +#define APP_NBYTES_OF_REG_BANK 32 /************************************************************************/ /* Registers' bits */ From 095d2af2d2c73d7402ad88cc650efeb03c27149c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 26 Nov 2021 13:31:19 +0000 Subject: [PATCH 3/8] [fw] update default direction --- Firmware/Pump/app.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/Pump/app.c b/Firmware/Pump/app.c index 1c5045b..afb088e 100644 --- a/Firmware/Pump/app.c +++ b/Firmware/Pump/app.c @@ -68,6 +68,9 @@ void core_callback_catastrophic_error_detected(void) /************************************************************************/ /* User functions */ /************************************************************************/ +#define DIR_FORWARD 1 +#define DIR_REVERSE 0 + uint16_t inactivity_counter = 0; uint8_t but_push_counter_ms = 0; @@ -84,16 +87,13 @@ bool but_reset_dir_change = false; bool switch_f_active = false; bool switch_r_active = false; -uint8_t curr_dir = 0; +uint8_t curr_dir = DIR_FORWARD; uint16_t step_period_counter = 0; bool running_protocol = false; uint16_t prot_remaining_steps = 0; uint16_t prot_step_period = 0; -#define DIR_FORWARD 1 -#define DIR_REVERSE 0 - void stop_and_reset_protocol() { From 45f10c9061f2522b96901a72abdbff413c8319f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 26 Nov 2021 13:33:06 +0000 Subject: [PATCH 4/8] [fw] update direction when running and stopping the protocol --- Firmware/Pump/app.c | 5 +++++ Firmware/Pump/app_funcs.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Firmware/Pump/app.c b/Firmware/Pump/app.c index afb088e..0de6fef 100644 --- a/Firmware/Pump/app.c +++ b/Firmware/Pump/app.c @@ -88,6 +88,7 @@ bool switch_f_active = false; bool switch_r_active = false; uint8_t curr_dir = DIR_FORWARD; +uint8_t prev_dir = DIR_FORWARD; uint16_t step_period_counter = 0; bool running_protocol = false; @@ -102,6 +103,9 @@ void stop_and_reset_protocol() prot_remaining_steps = app_regs.REG_PROTOCOL_NUMBER_STEPS + 1; prot_step_period = app_regs.REG_PROTOCOL_PERIOD * 2; app_regs.REG_START_PROTOCOL = 0; + + // revert direction + app_write_REG_DIR_STATE(&prev_dir); } void switch_pressed(uint8_t direction) @@ -220,6 +224,7 @@ void core_callback_reset_registers(void) app_regs.REG_DI0_CONFIG = GM_DI0_SYNC; app_regs.REG_MOTOR_MICROSTEP = GM_STEP_FULL; + app_regs.REG_PROTOCOL_DIRECTION = DIR_FORWARD; app_regs.REG_PROTOCOL_NUMBER_STEPS = 15; app_regs.REG_PROTOCOL_FLOWRATE = 0.5; app_regs.REG_PROTOCOL_PERIOD = 10; diff --git a/Firmware/Pump/app_funcs.c b/Firmware/Pump/app_funcs.c index 043ff44..42458fa 100644 --- a/Firmware/Pump/app_funcs.c +++ b/Firmware/Pump/app_funcs.c @@ -7,6 +7,7 @@ /************************************************************************/ extern AppRegs app_regs; extern uint8_t curr_dir; +extern uint8_t prev_dir; extern uint8_t step_period_counter; extern bool running_protocol; extern void stop_and_reset_protocol(); @@ -102,6 +103,14 @@ bool app_write_REG_START_PROTOCOL(void *a) stop_and_reset_protocol(); running_protocol = reg > 0; + + // set current direction to the one defined in the protocol_direction reg + if( running_protocol ) + { + prev_dir = curr_dir; + //FIXME: seems that the first event is not triggered + app_write_REG_DIR_STATE(&app_regs.REG_PROTOCOL_DIRECTION); + } app_regs.REG_START_PROTOCOL = reg; app_regs.REG_PROTOCOL_STATE = reg; @@ -175,6 +184,11 @@ bool app_write_REG_DIR_STATE(void *a) core_func_send_event(ADD_REG_DIR_STATE, true); } + if(!running_protocol) + { + prev_dir = curr_dir; + } + if(curr_dir) set_DIR; else From 884139922169b4d8e16802cfe4e44b3355043f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 26 Nov 2021 13:34:07 +0000 Subject: [PATCH 5/8] [fw] update how the protocol is activated when triggered by the DI0 --- Firmware/Pump/interrupts.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Firmware/Pump/interrupts.c b/Firmware/Pump/interrupts.c index 481ed01..5a5a4b7 100644 --- a/Firmware/Pump/interrupts.c +++ b/Firmware/Pump/interrupts.c @@ -57,19 +57,21 @@ ISR(PORTB_INT0_vect, ISR_NAKED) app_regs.REG_STEP_STATE = aux; app_write_REG_STEP_STATE(&app_regs.REG_STEP_STATE); } - - previous_in0 = aux; } if((app_regs.REG_DI0_CONFIG & MSK_DI0_CONF) == GM_DI0_RISE_START_PROTOCOL) { // transition from low to high if(previous_in0 == 0 && aux == 1) - running_protocol = true; + app_regs.REG_START_PROTOCOL = 1; else - running_protocol = false; + app_regs.REG_START_PROTOCOL = 0; + + app_write_REG_START_PROTOCOL(&app_regs.REG_START_PROTOCOL); } + previous_in0 = aux; + reti(); } From 1a3759d5fd2d6029beba20c920b8cd2e8c20fbf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 26 Nov 2021 13:34:48 +0000 Subject: [PATCH 6/8] [fw] fix issue when starting protocol if the switches are pressed --- Firmware/Pump/app_funcs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Firmware/Pump/app_funcs.c b/Firmware/Pump/app_funcs.c index 42458fa..8aaff6d 100644 --- a/Firmware/Pump/app_funcs.c +++ b/Firmware/Pump/app_funcs.c @@ -102,6 +102,22 @@ bool app_write_REG_START_PROTOCOL(void *a) // will only be updated after stopping and starting the protocol again stop_and_reset_protocol(); + // prevent activating protocol if the switch for the same direction is active + if( reg > 0 ) + { + // forward switch and forward direction + if(read_SW_F && app_regs.REG_PROTOCOL_DIRECTION) + { + return true; + } + + // reverse switch and reverse direction + if(read_SW_R && !app_regs.REG_PROTOCOL_DIRECTION) + { + return true; + } + } + running_protocol = reg > 0; // set current direction to the one defined in the protocol_direction reg From 08bf91958f09d2248578c535fc0f424d7696a2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 26 Nov 2021 13:35:28 +0000 Subject: [PATCH 7/8] [fw] fix issue with steps beings allowed when the switches are pressed --- Firmware/Pump/app_funcs.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Firmware/Pump/app_funcs.c b/Firmware/Pump/app_funcs.c index 8aaff6d..5c5b600 100644 --- a/Firmware/Pump/app_funcs.c +++ b/Firmware/Pump/app_funcs.c @@ -149,7 +149,7 @@ bool app_write_REG_STEP_STATE(void *a) { uint8_t reg = *((uint8_t*)a); - if(reg) + if( reg > 0 ) { // force starting counting from the start step_period_counter = 0; @@ -160,10 +160,22 @@ bool app_write_REG_STEP_STATE(void *a) app_write_REG_ENABLE_MOTOR_DRIVER(&app_regs.REG_ENABLE_MOTOR_DRIVER); } - set_STEP; - if((app_regs.REG_DO1_CONFIG & MSK_OUT1_CONF) == GM_OUT1_STEP_STATE) + // only allow steps if the switch on the same direction is not active + if(!read_SW_F && curr_dir == 1) { - set_OUT01; + set_STEP; + if((app_regs.REG_DO1_CONFIG & MSK_OUT1_CONF) == GM_OUT1_STEP_STATE) + { + set_OUT01; + } + } + if(!read_SW_R && curr_dir == 0) + { + set_STEP; + if((app_regs.REG_DO1_CONFIG & MSK_OUT1_CONF) == GM_OUT1_STEP_STATE) + { + set_OUT01; + } } } From 78d0dfeabaefe58671b68282d408d3c94218c6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 26 Nov 2021 13:46:20 +0000 Subject: [PATCH 8/8] [fw] update firmware version --- Firmware/Pump/app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Pump/app.c b/Firmware/Pump/app.c index 0de6fef..be01cb7 100644 --- a/Firmware/Pump/app.c +++ b/Firmware/Pump/app.c @@ -30,7 +30,7 @@ void hwbp_app_initialize(void) uint8_t hwH = 1; uint8_t hwL = 1; uint8_t fwH = 0; - uint8_t fwL = 2; + uint8_t fwL = 3; uint8_t ass = 0; /* Start core */