Compare commits
No commits in common. "2d3b61550bdded263cd1f33e9ce94fc08a9d7312" and "83978e81885d84267340a4a8b39f1e56d10c7e77" have entirely different histories.
2d3b61550b
...
83978e8188
@ -30,7 +30,7 @@ CFILES += adc-meas.c
|
|||||||
# Shellmatta
|
# Shellmatta
|
||||||
CFILES += shellmatta/src/shellmatta.c shellmatta/src/shellmatta_autocomplete.c shellmatta/src/shellmatta_escape.c shellmatta/src/shellmatta_history.c shellmatta/src/shellmatta_utils.c shellmatta/src/shellmatta_opt.c shell.c
|
CFILES += shellmatta/src/shellmatta.c shellmatta/src/shellmatta_autocomplete.c shellmatta/src/shellmatta_escape.c shellmatta/src/shellmatta_history.c shellmatta/src/shellmatta_utils.c shellmatta/src/shellmatta_opt.c shell.c
|
||||||
INCLUDEPATH += -Ishellmatta/api
|
INCLUDEPATH += -Ishellmatta/api
|
||||||
DEFINES += -DSHELLMATTA_HELP_ALIAS=\"?\"
|
# DEFINES += -DSHELLMATTA_STRIP_PRINTF
|
||||||
|
|
||||||
# RCC Manager
|
# RCC Manager
|
||||||
CFILES += stm-periph/clock-enable-manager.c
|
CFILES += stm-periph/clock-enable-manager.c
|
||||||
@ -53,8 +53,6 @@ CFILES += stack-check.c
|
|||||||
|
|
||||||
CFILES += fatfs/diskio.c fatfs/ff.c fatfs/ffsystem.c fatfs/ffunicode.c fatfs/shimatta_sdio_driver/shimatta_sdio.c
|
CFILES += fatfs/diskio.c fatfs/ff.c fatfs/ffsystem.c fatfs/ffunicode.c fatfs/shimatta_sdio_driver/shimatta_sdio.c
|
||||||
|
|
||||||
CFILES += pid-controller.c oven-driver.c
|
|
||||||
|
|
||||||
DEFINES += -DDEBUGBUILD
|
DEFINES += -DDEBUGBUILD
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
|
@ -36,7 +36,6 @@ static volatile int * volatile streaming_flag_ptr = NULL;
|
|||||||
static uint32_t filter_startup_cnt;
|
static uint32_t filter_startup_cnt;
|
||||||
static volatile float adc_pt1000_raw_reading_hf;
|
static volatile float adc_pt1000_raw_reading_hf;
|
||||||
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
|
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
|
||||||
static volatile uint32_t adc_watchdog_counter = 0UL;
|
|
||||||
|
|
||||||
volatile float * volatile stream_buffer = NULL;
|
volatile float * volatile stream_buffer = NULL;
|
||||||
volatile uint32_t stream_count;
|
volatile uint32_t stream_count;
|
||||||
@ -335,8 +334,6 @@ void ADC_IRQHandler(void)
|
|||||||
|
|
||||||
if (adc1_sr & ADC_SR_AWD) {
|
if (adc1_sr & ADC_SR_AWD) {
|
||||||
ADC1->SR &= ~ADC_SR_AWD;
|
ADC1->SR &= ~ADC_SR_AWD;
|
||||||
adc_watchdog_counter++;
|
|
||||||
if (adc_watchdog_counter >= ADC_PT1000_WATCHDOG_SAMPLE_COUNT)
|
|
||||||
pt1000_error |= ADC_PT1000_WATCHDOG_ERROR;
|
pt1000_error |= ADC_PT1000_WATCHDOG_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,9 +369,6 @@ void DMA2_Stream0_IRQHandler()
|
|||||||
if (streaming_flag_ptr)
|
if (streaming_flag_ptr)
|
||||||
append_stream_buffer(adc_val);
|
append_stream_buffer(adc_val);
|
||||||
|
|
||||||
if (adc_watchdog_counter > 0UL)
|
|
||||||
adc_watchdog_counter--;
|
|
||||||
|
|
||||||
/* Call moving average filter */
|
/* Call moving average filter */
|
||||||
adc_pt1000_filter(adc_val);
|
adc_pt1000_filter(adc_val);
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,6 @@
|
|||||||
*/
|
*/
|
||||||
#define ADC_PT1000_UPPER_WATCHDOG 4000U
|
#define ADC_PT1000_UPPER_WATCHDOG 4000U
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Number of ADC samples the value has to be outside the Watchdog limit (@ref ADC_PT1000_UPPER_WATCHDOG and @ref ADC_PT1000_LOWER_WATCHDOG)
|
|
||||||
* in order to produce a watchdog error
|
|
||||||
*/
|
|
||||||
#define ADC_PT1000_WATCHDOG_SAMPLE_COUNT 25U
|
|
||||||
|
|
||||||
enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1), ADC_PT1000_INACTIVE = (1UL<<2)};
|
enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1), ADC_PT1000_INACTIVE = (1UL<<2)};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,7 +107,7 @@ void adc_pt1000_get_resistance_calibration(float *offset, float *sensitivity_dev
|
|||||||
/**
|
/**
|
||||||
* @brief Get the current reistance value
|
* @brief Get the current reistance value
|
||||||
*
|
*
|
||||||
* If the reistance calibration is enabled, this function applies the calculations of the raw resistance reading and
|
* If the reistance calibration is enabled, this function applies the calculations of the raw reistance reading and
|
||||||
* returns the corrected value.
|
* returns the corrected value.
|
||||||
*
|
*
|
||||||
* If an ADC error is set, the status is negative. The status is 2 during the first measurements with a given filter setting. Technically, the resistance value is
|
* If an ADC error is set, the status is negative. The status is 2 during the first measurements with a given filter setting. Technically, the resistance value is
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __OVEN_DRIVER_H__
|
|
||||||
#define __OVEN_DRIVER_H__
|
|
||||||
|
|
||||||
#endif /* __OVEN_DRIVER_H__ */
|
|
@ -1,44 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __PID_CONTROLLER_H__
|
|
||||||
#define __PID_CONTROLLER_H__
|
|
||||||
|
|
||||||
struct pid_controller {
|
|
||||||
float k_deriv;
|
|
||||||
float k_int;
|
|
||||||
float k_p;
|
|
||||||
float output_sat_max;
|
|
||||||
float output_sat_min;
|
|
||||||
float integral_max;
|
|
||||||
volatile float control_output;
|
|
||||||
volatile float last_in;
|
|
||||||
volatile float integral;
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
void pid_zero(struct pid_controller *pid);
|
|
||||||
|
|
||||||
float pid_sample(struct pid_controller *pid, float deviation);
|
|
||||||
|
|
||||||
float pid_get_control_output(const struct pid_controller *pid);
|
|
||||||
|
|
||||||
#endif /* __PID_CONTROLLER_H__ */
|
|
@ -29,18 +29,6 @@ int32_t stack_check_get_usage();
|
|||||||
|
|
||||||
int32_t stack_check_get_free();
|
int32_t stack_check_get_free();
|
||||||
|
|
||||||
static inline int stack_check_collision()
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
int32_t free_space = stack_check_get_free();
|
|
||||||
|
|
||||||
if ((unsigned int)free_space < STACK_CHECK_MIN_HEAP_GAP) {
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t read_stack_pointer()
|
static inline uint32_t read_stack_pointer()
|
||||||
{
|
{
|
||||||
uint32_t stack_pointer;
|
uint32_t stack_pointer;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* 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,
|
* GDSII-Converter 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.
|
||||||
|
@ -32,9 +32,7 @@
|
|||||||
#include <reflow-controller/systick.h>
|
#include <reflow-controller/systick.h>
|
||||||
#include <reflow-controller/adc-meas.h>
|
#include <reflow-controller/adc-meas.h>
|
||||||
#include <reflow-controller/shell.h>
|
#include <reflow-controller/shell.h>
|
||||||
#include <reflow-controller/pid-controller.h>
|
|
||||||
#include <reflow-controller/digio.h>
|
#include <reflow-controller/digio.h>
|
||||||
#include <reflow-controller/temp-converter.h>
|
|
||||||
#include <reflow-controller/rotary-encoder.h>
|
#include <reflow-controller/rotary-encoder.h>
|
||||||
#include <stm-periph/stm32-gpio-macros.h>
|
#include <stm-periph/stm32-gpio-macros.h>
|
||||||
#include <stm-periph/clock-enable-manager.h>
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
@ -57,8 +55,8 @@ static void setup_nvic_priorities()
|
|||||||
static float pt1000_value;
|
static float pt1000_value;
|
||||||
static volatile int pt1000_value_status;
|
static volatile int pt1000_value_status;
|
||||||
static uint32_t rot;
|
static uint32_t rot;
|
||||||
static volatile float pid_out;
|
|
||||||
static volatile float current_temperature;
|
|
||||||
|
|
||||||
static inline void uart_gpio_config()
|
static inline void uart_gpio_config()
|
||||||
{
|
{
|
||||||
@ -115,9 +113,6 @@ int main()
|
|||||||
shellmatta_handle_t shell_handle;
|
shellmatta_handle_t shell_handle;
|
||||||
int uart_receive_status;
|
int uart_receive_status;
|
||||||
|
|
||||||
static struct pid_controller pid;
|
|
||||||
uint64_t pid_timestamp = 0;
|
|
||||||
|
|
||||||
setup_nvic_priorities();
|
setup_nvic_priorities();
|
||||||
systick_setup();
|
systick_setup();
|
||||||
|
|
||||||
@ -139,20 +134,9 @@ int main()
|
|||||||
f_close(&test_file);
|
f_close(&test_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_init(&pid, 0.1, 0.1, 4.0, 0.0, 100.0, 40.0);
|
|
||||||
pid_zero(&pid);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
||||||
|
|
||||||
if (pt1000_value_status >= 0) {
|
|
||||||
(void)temp_converter_convert_resistance_to_temp(pt1000_value, (float *)¤t_temperature);
|
|
||||||
if ((systick_get_global_tick() - pid_timestamp) >= 250) {
|
|
||||||
pid_out = pid_sample(&pid, 100.0 - current_temperature);
|
|
||||||
pid_timestamp = systick_get_global_tick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rot = rotary_encoder_get_abs_val();
|
rot = rotary_encoder_get_abs_val();
|
||||||
uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len);
|
uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len);
|
||||||
if (uart_receive_status >= 1)
|
if (uart_receive_status >= 1)
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <reflow-controller/oven-driver.h>
|
|
@ -1,90 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <reflow-controller/pid-controller.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)
|
|
||||||
{
|
|
||||||
if (!pid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
pid->k_p = k_p;
|
|
||||||
pid->k_int = k_int;
|
|
||||||
pid->k_deriv = k_deriv;
|
|
||||||
pid->output_sat_max = output_sat_max;
|
|
||||||
pid->output_sat_min = output_sat_min;
|
|
||||||
pid->control_output = 0;
|
|
||||||
pid->integral_max = integral_max;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pid_zero(struct pid_controller *pid)
|
|
||||||
{
|
|
||||||
pid->control_output = 0.0f;
|
|
||||||
pid->last_in = 0.0f;
|
|
||||||
pid->integral = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void calculate_integral(struct pid_controller *pid, float deviation)
|
|
||||||
{
|
|
||||||
pid->integral += deviation * pid->k_int;
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
float output;
|
|
||||||
|
|
||||||
if (!pid)
|
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
output = deviation * pid->k_p;
|
|
||||||
|
|
||||||
if (!(deviation > 0.0f && pid->control_output > pid->output_sat_max - 0.5) &&
|
|
||||||
!(deviation < 0.0f && pid->control_output < pid->output_sat_min + 0.5)) {
|
|
||||||
calculate_integral(pid, deviation);
|
|
||||||
}
|
|
||||||
|
|
||||||
output += pid->integral;
|
|
||||||
output -= (deviation - pid->last_in) * pid->k_deriv;
|
|
||||||
|
|
||||||
pid->last_in = deviation;
|
|
||||||
|
|
||||||
if (output > pid->output_sat_max)
|
|
||||||
output = pid->output_sat_max;
|
|
||||||
if (output < pid->output_sat_min)
|
|
||||||
output = pid->output_sat_min;
|
|
||||||
|
|
||||||
pid->control_output = output;
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
float pid_get_control_output(const struct pid_controller *pid)
|
|
||||||
{
|
|
||||||
if (!pid)
|
|
||||||
return 0.0f;
|
|
||||||
|
|
||||||
return pid->control_output;
|
|
||||||
}
|
|
@ -274,11 +274,8 @@ static shellmatta_retCode_t shell_cmd_pt1000_res_loop(const shellmatta_handle_t
|
|||||||
shellmatta_printf(handle, "\x1b[1A\x1b[150D\x1b[K");
|
shellmatta_printf(handle, "\x1b[1A\x1b[150D\x1b[K");
|
||||||
shell_cmd_pt1000_res(handle, "", 0UL);
|
shell_cmd_pt1000_res(handle, "", 0UL);
|
||||||
|
|
||||||
led_set(1, led_status);
|
led_set(0, led_status);
|
||||||
if (adc_pt1000_check_error() & ADC_PT1000_WATCHDOG_ERROR) {
|
led_set(1, !led_status);
|
||||||
led_set(0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
led_status ^= 0x1;
|
led_status ^= 0x1;
|
||||||
|
|
||||||
systick_wait_ms(150);
|
systick_wait_ms(150);
|
||||||
|
@ -89,12 +89,6 @@ int _write(int fd, const void *buf, int count)
|
|||||||
{
|
{
|
||||||
if (fd == 1)
|
if (fd == 1)
|
||||||
uart_send_array_with_dma(&shell_uart, (char *)buf, count);
|
uart_send_array_with_dma(&shell_uart, (char *)buf, count);
|
||||||
else if (fd == 2) {
|
|
||||||
uart_send_string_with_dma(&shell_uart, "\e[31m");
|
|
||||||
uart_send_array_with_dma(&shell_uart, (char *)buf, count);
|
|
||||||
uart_send_string_with_dma(&shell_uart, "\e[m");
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user