Fix style

This commit is contained in:
Mario Hüttel 2020-08-31 22:50:39 +02:00
parent 0fd738f37e
commit 03e1ccf97e
3 changed files with 55 additions and 48 deletions

View File

@ -41,7 +41,7 @@ void oven_pid_init(struct pid_controller *controller_to_copy);
void oven_pid_handle(float target_temp); void oven_pid_handle(float target_temp);
void oven_pid_stop(); void oven_pid_stop(void);
void oven_driver_apply_power_level(void); void oven_driver_apply_power_level(void);

View File

@ -1,22 +1,22 @@
/* Reflow Oven Controller /* Reflow Oven Controller
* *
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net> * Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
* *
* This file is part of the Reflow Oven Controller Project. * This file is part of the Reflow Oven Controller Project.
* *
* The reflow oven controller is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, * 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 * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the reflow oven controller project. * along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <reflow-controller/oven-driver.h> #include <reflow-controller/oven-driver.h>
#include <reflow-controller/periph-config/oven-driver-hwcfg.h> #include <reflow-controller/periph-config/oven-driver-hwcfg.h>
@ -28,11 +28,11 @@
#include <reflow-controller/safety/safety-controller.h> #include <reflow-controller/safety/safety-controller.h>
static struct pid_controller IN_SECTION(.ccm.bss) oven_pid; static struct pid_controller IN_SECTION(.ccm.bss) oven_pid;
static bool oven_pid_running = false; static bool oven_pid_running;
static bool oven_pid_aborted = false; static bool oven_pid_aborted;
static uint8_t IN_SECTION(.ccm.bss) oven_driver_power_level = 0U; 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->AHB1ENR, BITMASK_TO_BITNO(OVEN_CONTROLLER_PORT_RCC_MASK));
rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(OVEN_CONTROLLER_TIM_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->PSC = 42000U - 1U;
OVEN_CONTROLLER_PWM_TIMER->CR1 = TIM_CR1_CMS | TIM_CR1_CEN; 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) 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; 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->CR1 = 0UL;
OVEN_CONTROLLER_PWM_TIMER->CR2 = 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_pid_running = false;
oven_driver_set_power(0U);
safety_controller_enable_timing_mon(ERR_TIMING_PID, false); safety_controller_enable_timing_mon(ERR_TIMING_PID, false);
} }

View File

@ -1,27 +1,28 @@
/* Reflow Oven Controller /* Reflow Oven Controller
* *
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net> * Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
* *
* This file is part of the Reflow Oven Controller Project. * This file is part of the Reflow Oven Controller Project.
* *
* The reflow oven controller is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, * 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 * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the reflow oven controller project. * along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <reflow-controller/pid-controller.h> #include <reflow-controller/pid-controller.h>
#include <string.h> #include <string.h>
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) if (!pid)
return; 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); pid->integral = pid->integral + pid->k_int_t * (deviation + pid->last_in);
/* Saturate integral term to spoecified maximum */ /* Saturate integral term to spoecified maximum */
if (pid->integral > pid->integral_max) { if (pid->integral > pid->integral_max)
pid->integral = pid->integral_max; pid->integral = pid->integral_max;
} else if (pid->integral < -pid->integral_max){ else if (pid->integral < -pid->integral_max)
pid->integral = - pid->integral_max; pid->integral = -pid->integral_max;
}
} }
float pid_sample(struct pid_controller *pid, float deviation) float pid_sample(struct pid_controller *pid, float deviation)