From a802b5c1b50394da768372b9ad2cbdd108c06d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 19 Aug 2021 21:25:04 +0200 Subject: [PATCH] Add main cylcle counter and increase filter alpha for PT1000 to 0.01 --- .../include/reflow-controller/adc-meas.h | 2 +- .../reflow-controller/main-cycle-counter.h | 32 ++++++++++++ stm-firmware/main-cycle-counter.c | 39 ++++++++++++++ stm-firmware/main.c | 5 +- stm-firmware/safety/safety-controller.c | 1 + stm-firmware/shell.c | 51 ++++++++++++++++++- 6 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 stm-firmware/include/reflow-controller/main-cycle-counter.h create mode 100644 stm-firmware/main-cycle-counter.c diff --git a/stm-firmware/include/reflow-controller/adc-meas.h b/stm-firmware/include/reflow-controller/adc-meas.h index 633fd5b..049c1a8 100644 --- a/stm-firmware/include/reflow-controller/adc-meas.h +++ b/stm-firmware/include/reflow-controller/adc-meas.h @@ -36,7 +36,7 @@ /** * @brief Moving average filter coefficient for PT1000 measurement */ -#define ADC_PT1000_FILTER_WEIGHT 0.005f +#define ADC_PT1000_FILTER_WEIGHT 0.01f /** * @brief Moving average filter weight used for fast regaulation. This is used when the measured resistance diff --git a/stm-firmware/include/reflow-controller/main-cycle-counter.h b/stm-firmware/include/reflow-controller/main-cycle-counter.h new file mode 100644 index 0000000..5fa1836 --- /dev/null +++ b/stm-firmware/include/reflow-controller/main-cycle-counter.h @@ -0,0 +1,32 @@ +/* Reflow Oven Controller +* +* Copyright (C) 2020 Mario Hüttel +* +* This file is part of the Reflow Oven Controller Project. +* +* The reflow oven controller is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with the reflow oven controller project. +* If not, see . +*/ + +#ifndef __MAIN_CYCLE_COUNTER_H__ +#define __MAIN_CYCLE_COUNTER_H__ + +#include + +void main_cycle_counter_init(void); + +void main_cycle_counter_inc(void); + +uint64_t main_cycle_counter_get(void); + +#endif /* __MAIN_CYCLE_COUNTER_H__ */ diff --git a/stm-firmware/main-cycle-counter.c b/stm-firmware/main-cycle-counter.c new file mode 100644 index 0000000..d0b889b --- /dev/null +++ b/stm-firmware/main-cycle-counter.c @@ -0,0 +1,39 @@ +/* Reflow Oven Controller +* +* Copyright (C) 2020 Mario Hüttel +* +* This file is part of the Reflow Oven Controller Project. +* +* The reflow oven controller is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with the reflow oven controller project. +* If not, see . +*/ + +#include +#include + +static uint64_t IN_SECTION(.ccm.bss) main_cycle_counter; + +void main_cycle_counter_init() +{ + main_cycle_counter = 0ULL; +} + +void main_cycle_counter_inc() +{ + main_cycle_counter++; +} + +uint64_t main_cycle_counter_get() +{ + return main_cycle_counter; +} diff --git a/stm-firmware/main.c b/stm-firmware/main.c index ad7876b..95fccd3 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -48,6 +48,7 @@ #include #include #include +#include static void setup_nvic_priorities(void) { @@ -248,6 +249,8 @@ int main(void) shell_handle = shell_init(write_shell_callback); shell_print_motd(shell_handle); + main_cycle_counter_init(); + while (1) { if (systick_ticks_have_passed(quarter_sec_timestamp, 250)) { @@ -285,7 +288,7 @@ int main(void) __WFI(); else __NOP(); - main_loop_iter_count++; + main_cycle_counter_inc(); } return 0; diff --git a/stm-firmware/safety/safety-controller.c b/stm-firmware/safety/safety-controller.c index 84c02d4..27d3bc1 100644 --- a/stm-firmware/safety/safety-controller.c +++ b/stm-firmware/safety/safety-controller.c @@ -1563,6 +1563,7 @@ int safety_controller_set_crc_monitor(enum crc_monitor mon, uint32_t password) if (password != monitor->pw) return -1002; + crc = 0; (void)crc_monitor_calculate_crc(monitor->registers, &crc); monitor->expected_crc = crc; monitor->expected_crc_inv = ~crc; diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 06bb4b8..3b3476d 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include #ifndef GIT_VER #define GIT_VER "VERSION NOT SET" @@ -790,6 +792,43 @@ shellmatta_retCode_t shell_cmd_execute(const shellmatta_handle_t handle, const c return SHELLMATTA_CONTINUE; } +shellmatta_retCode_t shell_cmd_cycle_count (const shellmatta_handle_t handle, const char *args, uint32_t len) +{ + uint64_t counter; + (void)args; + (void)len; + char option; + char *argument; + uint32_t arg_len; + int opt_stat; + bool clear = false; + const shellmatta_opt_long_t options[] = { + {"clear", 'c', SHELLMATTA_OPT_ARG_NONE}, + {NULL, '\0', SHELLMATTA_OPT_ARG_NONE}, + }; + + while (1) { + opt_stat = shellmatta_opt_long(handle, options, &option, &argument, &arg_len); + if (opt_stat != SHELLMATTA_OK) + break; + switch (option) { + case 'c': + clear = true; + break; + default: + break; + } + } + + + counter = main_cycle_counter_get(); + shellmatta_printf(handle, "%"PRIu64"\r\n", counter); + if (clear) + main_cycle_counter_init(); + + return SHELLMATTA_OK; +} + //typedef struct shellmatta_cmd //{ // char *cmd; /**< command name */ @@ -799,7 +838,7 @@ shellmatta_retCode_t shell_cmd_execute(const shellmatta_handle_t handle, const c // shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */ // struct shellmatta_cmd *next; /**< pointer to next command or NULL */ //} shellmatta_cmd_t; -static shellmatta_cmd_t cmd[21] = { +static shellmatta_cmd_t cmd[23] = { { .cmd = "version", .cmdAlias = "ver", @@ -967,8 +1006,16 @@ static shellmatta_cmd_t cmd[21] = { .helpText = "Execute Temp Profile", .usageText = "execute /path/to/script.tpr", .cmdFct = shell_cmd_execute, + .next = &cmd[21], + }, + { + .cmd = "cyclecount", + .cmdAlias = "cc", + .helpText = "Print out the cycle counter of the main loop", + .usageText = "cyclecount [--clear]", + .cmdFct = shell_cmd_cycle_count, .next = NULL, - } + }, }; shellmatta_handle_t shell_init(shellmatta_write_t write_func)