diff --git a/stm-firmware/include/reflow-controller/oven-driver.h b/stm-firmware/include/reflow-controller/oven-driver.h index dacf21f..62825a7 100644 --- a/stm-firmware/include/reflow-controller/oven-driver.h +++ b/stm-firmware/include/reflow-controller/oven-driver.h @@ -41,7 +41,7 @@ void oven_pid_init(struct pid_controller *controller_to_copy); void oven_pid_handle(float target_temp); -void oven_pid_stop(); +void oven_pid_stop(void); void oven_driver_apply_power_level(void); diff --git a/stm-firmware/oven-driver.c b/stm-firmware/oven-driver.c index e108525..8164219 100644 --- a/stm-firmware/oven-driver.c +++ b/stm-firmware/oven-driver.c @@ -1,22 +1,22 @@ /* 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 . -*/ + * + * 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 @@ -28,11 +28,11 @@ #include static struct pid_controller IN_SECTION(.ccm.bss) oven_pid; -static bool oven_pid_running = false; -static bool oven_pid_aborted = false; -static uint8_t IN_SECTION(.ccm.bss) oven_driver_power_level = 0U; +static bool oven_pid_running; +static bool oven_pid_aborted; +static uint8_t IN_SECTION(.ccm.bss) oven_driver_power_level; -void oven_driver_init() +void oven_driver_init(void) { rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(OVEN_CONTROLLER_PORT_RCC_MASK)); rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(OVEN_CONTROLLER_TIM_RCC_MASK)); @@ -50,6 +50,12 @@ void oven_driver_init() OVEN_CONTROLLER_PWM_TIMER->PSC = 42000U - 1U; OVEN_CONTROLLER_PWM_TIMER->CR1 = TIM_CR1_CMS | TIM_CR1_CEN; + + /* Explicitly init global variables */ + oven_pid_aborted = false; + oven_pid_running = false; + + oven_driver_set_power(0U); } void oven_driver_set_power(uint8_t power) @@ -65,7 +71,7 @@ void oven_driver_apply_power_level(void) OVEN_CONTROLLER_PWM_TIMER->CCR3 = oven_driver_power_level * 10; } -void oven_driver_disable() +void oven_driver_disable(void) { OVEN_CONTROLLER_PWM_TIMER->CR1 = 0UL; OVEN_CONTROLLER_PWM_TIMER->CR2 = 0UL; @@ -105,9 +111,10 @@ void oven_pid_handle(float target_temp) } } -void oven_pid_stop() +void oven_pid_stop(void) { oven_pid_running = false; + oven_driver_set_power(0U); safety_controller_enable_timing_mon(ERR_TIMING_PID, false); } diff --git a/stm-firmware/pid-controller.c b/stm-firmware/pid-controller.c index 04eecc3..3113d1f 100644 --- a/stm-firmware/pid-controller.c +++ b/stm-firmware/pid-controller.c @@ -1,27 +1,28 @@ /* 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 . -*/ + * + * 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 -void pid_init(struct pid_controller *pid, float k_deriv, float k_int, float k_p, float output_sat_min, float output_sat_max, float integral_max, float sample_period) +void pid_init(struct pid_controller *pid, float k_deriv, float k_int, float k_p, float output_sat_min, + float output_sat_max, float integral_max, float sample_period) { if (!pid) return; @@ -61,11 +62,10 @@ static void calculate_integral(struct pid_controller *pid, float deviation) pid->integral = pid->integral + pid->k_int_t * (deviation + pid->last_in); /* Saturate integral term to spoecified maximum */ - if (pid->integral > pid->integral_max) { + if (pid->integral > pid->integral_max) pid->integral = pid->integral_max; - } else if (pid->integral < -pid->integral_max){ - pid->integral = - pid->integral_max; - } + else if (pid->integral < -pid->integral_max) + pid->integral = -pid->integral_max; } float pid_sample(struct pid_controller *pid, float deviation)