Compare commits
21 Commits
40093322c3
...
f8076920fe
Author | SHA1 | Date | |
---|---|---|---|
f8076920fe | |||
9629c08da2 | |||
a35f66f2cd | |||
6fa071e1d1 | |||
47daf495bd | |||
7ade829a70 | |||
1d62bc22b8 | |||
6ed7a4886d | |||
3781ecb669 | |||
4c5b3add1d | |||
c3be39b4e5 | |||
43473efcdd | |||
7df97831be | |||
92526e71b2 | |||
b13b3b4377 | |||
c568b95cf2 | |||
c565dab3ad | |||
5a00950589 | |||
b497537a78 | |||
723afd9f56 | |||
ebb95b902c |
@ -10,12 +10,12 @@ INCLUDEPATH = -Icmsis -Iinclude
|
|||||||
OBJDIR = obj
|
OBJDIR = obj
|
||||||
target = reflow-controller
|
target = reflow-controller
|
||||||
LIBRARYPATH = -L. -Lmathlib
|
LIBRARYPATH = -L. -Lmathlib
|
||||||
LIBRARIES = -larm_cortexM4lf_math
|
LIBRARIES = -larm_cortexM4lf_math -lm
|
||||||
|
|
||||||
DEFINES = -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DHSE_VALUE=8000000UL
|
DEFINES = -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DHSE_VALUE=8000000UL
|
||||||
mapfile = memory-mapping
|
mapfile = memory-mapping
|
||||||
|
|
||||||
GIT_VER := $(shell git describe --always --dirty --tags)
|
export GIT_VER = $(shell git describe --always --dirty --tags)
|
||||||
DEFINES += -DGIT_VER=$(GIT_VER)
|
DEFINES += -DGIT_VER=$(GIT_VER)
|
||||||
|
|
||||||
ifneq ($(VERBOSE),true)
|
ifneq ($(VERBOSE),true)
|
||||||
@ -41,6 +41,12 @@ CFILES += digio.c
|
|||||||
|
|
||||||
CFILES += stm-periph/unique-id.c
|
CFILES += stm-periph/unique-id.c
|
||||||
|
|
||||||
|
CFILES += calibration.c
|
||||||
|
|
||||||
|
CFILES += temp-converter.c
|
||||||
|
|
||||||
|
CFILES += rotary-encoder.c
|
||||||
|
|
||||||
DEFINES += -DDEBUGBUILD
|
DEFINES += -DDEBUGBUILD
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
@ -56,7 +62,7 @@ LFLAGS += -Tstm32f407vet6_flash.ld -Wl,-Map=$(mapfile).map
|
|||||||
|
|
||||||
CFLAGS = -c -fmessage-length=0 -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
|
CFLAGS = -c -fmessage-length=0 -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
|
||||||
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -O0 -g
|
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -O0 -g
|
||||||
CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter
|
CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter -Wimplicit-fallthrough=3 -Wsign-compare
|
||||||
####################################################################################
|
####################################################################################
|
||||||
|
|
||||||
OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o)
|
OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o)
|
||||||
@ -75,6 +81,7 @@ $(target).elf: $(OBJ) $(ASOBJ)
|
|||||||
@echo [LD] $@
|
@echo [LD] $@
|
||||||
$(QUIET)$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES)
|
$(QUIET)$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES)
|
||||||
$(QUIET)$(SIZE) $@
|
$(QUIET)$(SIZE) $@
|
||||||
|
@echo "Built Version $(GIT_VER)"
|
||||||
|
|
||||||
#Compiling
|
#Compiling
|
||||||
$(OBJ):
|
$(OBJ):
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/adc-meas.h>
|
#include <reflow-controller/adc-meas.h>
|
||||||
#include <stm32/stm32f4xx.h>
|
#include <stm32/stm32f4xx.h>
|
||||||
#include <cmsis/core_cm4.h>
|
#include <cmsis/core_cm4.h>
|
||||||
@ -11,13 +31,16 @@ static bool calibration_active;
|
|||||||
static float filter_alpha;
|
static float filter_alpha;
|
||||||
static volatile float pt1000_res_raw_lf;
|
static volatile float pt1000_res_raw_lf;
|
||||||
static volatile bool filter_ready;
|
static volatile bool filter_ready;
|
||||||
static volatile enum adc_pt1000_error pt1000_error;
|
static volatile enum adc_pt1000_error pt1000_error = ADC_PT1000_INACTIVE;
|
||||||
static volatile uint8_t * volatile streaming_flag_ptr = NULL;
|
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 bool pt1000_measurement_active = false;
|
|
||||||
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
|
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
|
||||||
|
|
||||||
|
volatile float * volatile stream_buffer = NULL;
|
||||||
|
volatile uint32_t stream_count;
|
||||||
|
volatile uint32_t stream_pos;
|
||||||
|
|
||||||
#define ADC_TO_RES(adc) ((float)(adc) / 4096.0f * 2500.0f)
|
#define ADC_TO_RES(adc) ((float)(adc) / 4096.0f * 2500.0f)
|
||||||
|
|
||||||
static inline void adc_pt1000_stop_sample_frequency_timer()
|
static inline void adc_pt1000_stop_sample_frequency_timer()
|
||||||
@ -49,7 +72,7 @@ static inline void adc_pt1000_disable_adc()
|
|||||||
ADC1->CR2 &= ~ADC_CR2_ADON;
|
ADC1->CR2 &= ~ADC_CR2_ADON;
|
||||||
DMA2_Stream0->CR = 0;
|
DMA2_Stream0->CR = 0;
|
||||||
|
|
||||||
pt1000_measurement_active = false;
|
pt1000_error |= ADC_PT1000_INACTIVE;
|
||||||
|
|
||||||
rcc_manager_disable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(RCC_APB2ENR_ADC1EN));
|
rcc_manager_disable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(RCC_APB2ENR_ADC1EN));
|
||||||
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ADC_PT1000_PORT_RCC_MASK));
|
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ADC_PT1000_PORT_RCC_MASK));
|
||||||
@ -88,7 +111,7 @@ static inline void adc_pt1000_enable_dma_stream()
|
|||||||
* Todo: Maybe use twice as big of a buffer and also use half-fill interrupt in order to prevent overruns
|
* Todo: Maybe use twice as big of a buffer and also use half-fill interrupt in order to prevent overruns
|
||||||
*/
|
*/
|
||||||
DMA2_Stream0->CR = DMA_SxCR_PL_1 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC |
|
DMA2_Stream0->CR = DMA_SxCR_PL_1 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC |
|
||||||
DMA_SxCR_CIRC | DMA_SxCR_TCIE | DMA_SxCR_EN;
|
DMA_SxCR_CIRC | DMA_SxCR_TCIE | DMA_SxCR_TEIE | DMA_SxCR_EN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void adc_pt1000_disable_dma_stream()
|
static inline void adc_pt1000_disable_dma_stream()
|
||||||
@ -142,7 +165,7 @@ void adc_pt1000_setup_meas()
|
|||||||
|
|
||||||
adc_pt1000_setup_sample_frequency_timer();
|
adc_pt1000_setup_sample_frequency_timer();
|
||||||
|
|
||||||
pt1000_measurement_active = true;
|
pt1000_error &= ~ADC_PT1000_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adc_pt1000_set_moving_average_filter_param(float alpha)
|
void adc_pt1000_set_moving_average_filter_param(float alpha)
|
||||||
@ -201,17 +224,40 @@ return_value:
|
|||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int adc_pt1000_stream_raw_value_to_memory(volatile float *adc_array, uint32_t length, volatile int *flag_to_set)
|
||||||
int adc_pt1000_stream_raw_value_to_memory(float *adc_array, uint32_t length, volatile uint8_t *flag_to_set)
|
|
||||||
{
|
{
|
||||||
return -1;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (!flag_to_set)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
stream_buffer = adc_array;
|
||||||
|
stream_count = length;
|
||||||
|
stream_pos = 0U;
|
||||||
|
|
||||||
|
if (adc_array) {
|
||||||
|
*flag_to_set = 0;
|
||||||
|
streaming_flag_ptr = flag_to_set;
|
||||||
|
} else {
|
||||||
|
ret = -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count)
|
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count)
|
||||||
{
|
{
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
if (!resistance_dest)
|
||||||
|
resistance_dest = raw_source;
|
||||||
|
|
||||||
|
if (!raw_source || !count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
resistance_dest[i] = ADC_TO_RES(raw_source[i]);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
enum adc_pt1000_error adc_pt1000_check_error()
|
enum adc_pt1000_error adc_pt1000_check_error()
|
||||||
{
|
{
|
||||||
@ -220,7 +266,7 @@ enum adc_pt1000_error adc_pt1000_check_error()
|
|||||||
|
|
||||||
void adc_pt1000_clear_error()
|
void adc_pt1000_clear_error()
|
||||||
{
|
{
|
||||||
pt1000_error = ADC_PT1000_NO_ERR;
|
pt1000_error &= ~ADC_PT1000_OVERFLOW & ~ADC_PT1000_WATCHDOG_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adc_pt1000_disable()
|
void adc_pt1000_disable()
|
||||||
@ -231,6 +277,7 @@ void adc_pt1000_disable()
|
|||||||
|
|
||||||
filter_ready = false;
|
filter_ready = false;
|
||||||
pt1000_res_raw_lf = 0.0f;
|
pt1000_res_raw_lf = 0.0f;
|
||||||
|
pt1000_error |= ADC_PT1000_INACTIVE;
|
||||||
|
|
||||||
if (streaming_flag_ptr) {
|
if (streaming_flag_ptr) {
|
||||||
*streaming_flag_ptr = -3;
|
*streaming_flag_ptr = -3;
|
||||||
@ -283,10 +330,6 @@ void ADC_IRQHandler(void)
|
|||||||
pt1000_error |= ADC_PT1000_OVERFLOW;
|
pt1000_error |= ADC_PT1000_OVERFLOW;
|
||||||
/* Disable ADC in case of overrrun*/
|
/* Disable ADC in case of overrrun*/
|
||||||
adc_pt1000_disable();
|
adc_pt1000_disable();
|
||||||
if (streaming_flag_ptr) {
|
|
||||||
*streaming_flag_ptr = -1;
|
|
||||||
streaming_flag_ptr = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adc1_sr & ADC_SR_AWD) {
|
if (adc1_sr & ADC_SR_AWD) {
|
||||||
@ -295,6 +338,21 @@ void ADC_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void append_stream_buffer(float val)
|
||||||
|
{
|
||||||
|
if (!stream_buffer || !streaming_flag_ptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (stream_pos < stream_count)
|
||||||
|
stream_buffer[stream_pos++] = val;
|
||||||
|
|
||||||
|
if (stream_pos >= stream_count) {
|
||||||
|
*streaming_flag_ptr = 1;
|
||||||
|
streaming_flag_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void DMA2_Stream0_IRQHandler()
|
void DMA2_Stream0_IRQHandler()
|
||||||
{
|
{
|
||||||
uint32_t lisr;
|
uint32_t lisr;
|
||||||
@ -308,13 +366,15 @@ void DMA2_Stream0_IRQHandler()
|
|||||||
adc_val = adc_pt1000_dma_avg_pre_filter();
|
adc_val = adc_pt1000_dma_avg_pre_filter();
|
||||||
adc_pt1000_raw_reading_hf = adc_val;
|
adc_pt1000_raw_reading_hf = adc_val;
|
||||||
|
|
||||||
|
if (streaming_flag_ptr)
|
||||||
|
append_stream_buffer(adc_val);
|
||||||
|
|
||||||
/* Call moving average filter */
|
/* Call moving average filter */
|
||||||
adc_pt1000_filter(adc_val);
|
adc_pt1000_filter(adc_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lisr & DMA_LISR_TEIF0) {
|
if (lisr & DMA_LISR_TEIF0) {
|
||||||
/* Wait for watchdog to kick in */
|
adc_pt1000_disable();
|
||||||
while(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
171
stm-firmware/calibration.c
Normal file
171
stm-firmware/calibration.c
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/calibration.h>
|
||||||
|
#include <reflow-controller/adc-meas.h>
|
||||||
|
#include <stm-periph/uart.h>
|
||||||
|
#include <helper-macros/helper-macros.h>
|
||||||
|
#include <arm_math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
void calibration_calculate(float low_measured, float low_setpoint, float high_measured, float high_setpoint,
|
||||||
|
float *sens_deviation, float *sens_corrected_offset)
|
||||||
|
{
|
||||||
|
if (!sens_deviation || !sens_corrected_offset)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float delta_y;
|
||||||
|
float delta_x;
|
||||||
|
float sens_corr_mult;
|
||||||
|
|
||||||
|
delta_y = high_measured - low_measured;
|
||||||
|
delta_x = high_setpoint - low_setpoint;
|
||||||
|
|
||||||
|
sens_corr_mult = delta_x / delta_y;
|
||||||
|
*sens_deviation = sens_corr_mult - 1.0f;
|
||||||
|
|
||||||
|
*sens_corrected_offset = low_setpoint - low_measured * sens_corr_mult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int calibration_acquire_data(float *mu, float *max_dev, uint32_t count)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
float *stream_mem;
|
||||||
|
float min_val = FLT_MAX;
|
||||||
|
float max_val = -FLT_MAX;
|
||||||
|
uint32_t i;
|
||||||
|
int ret_val = 0;
|
||||||
|
|
||||||
|
static volatile int flag = 0;
|
||||||
|
|
||||||
|
if (!mu || !max_dev || !count)
|
||||||
|
return -1000;
|
||||||
|
|
||||||
|
stream_mem = (float *)calloc(count, sizeof(float));
|
||||||
|
if (!stream_mem)
|
||||||
|
return -2;
|
||||||
|
|
||||||
|
status = adc_pt1000_stream_raw_value_to_memory(stream_mem, count, &flag);
|
||||||
|
if (status)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
/* Wait for data to be transferred */
|
||||||
|
while (flag == 0);
|
||||||
|
|
||||||
|
if (flag != 1) {
|
||||||
|
/* Error */
|
||||||
|
ret_val = -1;
|
||||||
|
goto ret_free_mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the stream memory to Ohm readings */
|
||||||
|
adc_pt1000_convert_raw_value_array_to_resistance(NULL, stream_mem, count);
|
||||||
|
|
||||||
|
/* Do not compute std-deviation. Too imprecise
|
||||||
|
* arm_std_f32(stream_mem, count, sigma);
|
||||||
|
*/
|
||||||
|
arm_mean_f32(stream_mem, count, mu);
|
||||||
|
|
||||||
|
/* Find min and max values of array */
|
||||||
|
for (i = 0U; i < count; i++) {
|
||||||
|
min_val = MIN(min_val, stream_mem[i]);
|
||||||
|
max_val = MAX(max_val, stream_mem[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute maximum deviation range */
|
||||||
|
*max_dev = max_val - min_val;
|
||||||
|
|
||||||
|
ret_free_mem:
|
||||||
|
free(stream_mem);
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wait_for_uart_enter()
|
||||||
|
{
|
||||||
|
int enter_received = 0;
|
||||||
|
const char *recv_data;
|
||||||
|
size_t recv_len;
|
||||||
|
size_t iter;
|
||||||
|
int uart_recv_status;
|
||||||
|
|
||||||
|
do {
|
||||||
|
uart_recv_status = uart_receive_data_with_dma(&recv_data, &recv_len);
|
||||||
|
if (uart_recv_status >= 1) {
|
||||||
|
for (iter = 0; iter < recv_len; iter++) {
|
||||||
|
if (recv_data[iter] == '\n' || recv_data[iter] == '\r')
|
||||||
|
enter_received = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (enter_received == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int calibration_sequence_shell_cmd(shellmatta_handle_t shell)
|
||||||
|
{
|
||||||
|
float mu, mu2, dev, dev2;
|
||||||
|
float sens_dev, offset;
|
||||||
|
|
||||||
|
/* Clear errors of PT1000 reading */
|
||||||
|
adc_pt1000_clear_error();
|
||||||
|
|
||||||
|
shellmatta_printf(shell, "Starting calibration: Insert 1000 Ohm calibration resistor and press ENTER\r\n");
|
||||||
|
wait_for_uart_enter();
|
||||||
|
shellmatta_printf(shell, "Measurement...\r\n");
|
||||||
|
|
||||||
|
/* Clear errors of PT1000 reading */
|
||||||
|
adc_pt1000_clear_error();
|
||||||
|
calibration_acquire_data(&mu, &dev, 512UL);
|
||||||
|
shellmatta_printf(shell, "R=%.2f, Noise peak-peak: %.2f\r\n", mu, dev);
|
||||||
|
if (adc_pt1000_check_error() != ADC_PT1000_NO_ERR) {
|
||||||
|
shellmatta_printf(shell, "Error in resistance measurement: %d", adc_pt1000_check_error());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Measure 2nd calibration point */
|
||||||
|
shellmatta_printf(shell, "Insert 2000 Ohm calibration resistor and press ENTER\r\n");
|
||||||
|
wait_for_uart_enter();
|
||||||
|
shellmatta_printf(shell, "Measurement...\r\n");
|
||||||
|
|
||||||
|
/* Clear errors of PT1000 reading */
|
||||||
|
adc_pt1000_clear_error();
|
||||||
|
calibration_acquire_data(&mu2, &dev2, 512UL);
|
||||||
|
shellmatta_printf(shell, "R=%.2f, Noise peak-peak: %.2f\r\n", mu2, dev2);
|
||||||
|
if (adc_pt1000_check_error() != ADC_PT1000_NO_ERR) {
|
||||||
|
shellmatta_printf(shell, "Error in resistance measurement: %d", adc_pt1000_check_error());
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check noise values */
|
||||||
|
if (dev > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM || dev2 > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM) {
|
||||||
|
shellmatta_printf(shell, "Calibration failed! Too much noise. Check you're hardware.\r\n");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate calibration */
|
||||||
|
calibration_calculate(mu, 1000.0f, mu2, 2000.0f, &sens_dev, &offset);
|
||||||
|
|
||||||
|
shellmatta_printf(shell, "Calibration done:\r\n\tSENS_DEVIATION: %.4f\r\n\tOFFSET_CORR: %.2f\r\n", sens_dev, offset);
|
||||||
|
adc_pt1000_set_resistance_calibration(offset, sens_dev, true);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
61
stm-firmware/create-c-file-with-header.py
Executable file
61
stm-firmware/create-c-file-with-header.py
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
license_header = """/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
project_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
include_prefix = 'reflow-controller'
|
||||||
|
module_include_dir = os.path.join(project_dir, os.path.join('include', include_prefix))
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print('Supply module name')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
cpath = os.path.join(project_dir, sys.argv[1]+'.c')
|
||||||
|
hfile = sys.argv[1]+'.h'
|
||||||
|
hpath = os.path.join(module_include_dir, hfile)
|
||||||
|
|
||||||
|
h_define = '__'+hfile.replace('.', '_').replace('-', '_').upper()+'__'
|
||||||
|
|
||||||
|
if os.path.exists(cpath) or os.path.exists(hpath):
|
||||||
|
print("File already exists! Abort!")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
print('Creating C file: %s' % (cpath))
|
||||||
|
with open(cpath, 'x') as f:
|
||||||
|
f.write(license_header)
|
||||||
|
f.write('\n')
|
||||||
|
f.write('#include <%s>' % (os.path.join(include_prefix, hfile)))
|
||||||
|
|
||||||
|
print('Creating H file: %s' % (hpath))
|
||||||
|
with open(hpath, 'x') as f:
|
||||||
|
f.write(license_header)
|
||||||
|
f.write('\n')
|
||||||
|
f.write('#ifndef %s\n' % h_define)
|
||||||
|
f.write('#define %s\n' % h_define)
|
||||||
|
f.write('\n')
|
||||||
|
f.write('#endif /* %s */\n' % h_define)
|
||||||
|
|
||||||
|
|
74
stm-firmware/create-temp-lookup-table.py
Executable file
74
stm-firmware/create-temp-lookup-table.py
Executable file
@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
license_header = """/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
hfile="temp-converter-data.h"
|
||||||
|
|
||||||
|
project_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
include_prefix = 'reflow-controller'
|
||||||
|
module_include_dir = os.path.join(project_dir, os.path.join('include', include_prefix))
|
||||||
|
include_file = os.path.join(module_include_dir, hfile)
|
||||||
|
|
||||||
|
h_define = '__'+hfile.replace('.', '_').replace('-', '_').upper()+'__'
|
||||||
|
|
||||||
|
min_res = 1000
|
||||||
|
max_res = 2200
|
||||||
|
res_step = 20
|
||||||
|
|
||||||
|
R_zero = 1000.0
|
||||||
|
A = 3.9083E-3
|
||||||
|
B = -5.7750E-7
|
||||||
|
|
||||||
|
def calc_temp(resistance):
|
||||||
|
temp = (-R_zero * A + np.sqrt(R_zero*R_zero * A * A - 4* R_zero * B * (R_zero - resistance)))/(2*R_zero*B)
|
||||||
|
return temp
|
||||||
|
|
||||||
|
if ((max_res-min_res) % res_step) != 0:
|
||||||
|
print('Resistance range must be a multiple of res_step!')
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
print('Calculating temperature table for %f Ohm to %f Ohm in %f Ohm steps' % (min_res, max_res, res_step))
|
||||||
|
|
||||||
|
temp_array = ''
|
||||||
|
|
||||||
|
for res in range(min_res, max_res+res_step, res_step):
|
||||||
|
temp = calc_temp(res)
|
||||||
|
temp_array = temp_array+ ',%.2ff' % temp
|
||||||
|
|
||||||
|
temp_array = temp_array[1:]
|
||||||
|
|
||||||
|
with open(include_file, 'x') as f:
|
||||||
|
f.write(license_header)
|
||||||
|
f.write('\n')
|
||||||
|
f.write('#ifndef %s\n' % h_define)
|
||||||
|
f.write('#define %s\n\n' % h_define)
|
||||||
|
f.write('#define TEMP_CONVERSION_ARRAY_DATA %s\n' % temp_array)
|
||||||
|
f.write('#define TEMP_CONVERSION_MIN_RES %d\n' % min_res)
|
||||||
|
f.write('#define TEMP_CONVERSION_MAX_RES %d\n' % max_res)
|
||||||
|
f.write('#define TEMP_CONVERSION_RES_STEP %d\n' % res_step)
|
||||||
|
f.write('\n')
|
||||||
|
f.write('#endif /* %s */\n' % h_define)
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/digio.h>
|
#include <reflow-controller/digio.h>
|
||||||
#include <stm32/stm32f4xx.h>
|
#include <stm32/stm32f4xx.h>
|
||||||
#include <stm-periph/clock-enable-manager.h>
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
|
2551
stm-firmware/doxygen/Doxyconfig
Normal file
2551
stm-firmware/doxygen/Doxyconfig
Normal file
File diff suppressed because it is too large
Load Diff
20
stm-firmware/doxygen/build-doxygen.sh
Executable file
20
stm-firmware/doxygen/build-doxygen.sh
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
|
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||||
|
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
|
||||||
|
SOURCE="$(readlink "$SOURCE")"
|
||||||
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||||
|
done
|
||||||
|
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
|
||||||
|
cd "$DIR"
|
||||||
|
|
||||||
|
export PROJECT_NUMBER=`git describe --always --tags --dirty`
|
||||||
|
|
||||||
|
if [ $# != 1 ]; then
|
||||||
|
export OUTPUT_DIRECTORY="./output"
|
||||||
|
else
|
||||||
|
export OUTPUT_DIRECTORY="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
doxygen Doxyconfig
|
3
stm-firmware/doxygen/output/.gitignore
vendored
Normal file
3
stm-firmware/doxygen/output/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*
|
||||||
|
*/
|
||||||
|
!.gitignore
|
@ -267,7 +267,7 @@
|
|||||||
#define __CMSIS_GENERIC /* disable NVIC and Systick functions */
|
#define __CMSIS_GENERIC /* disable NVIC and Systick functions */
|
||||||
|
|
||||||
#if defined (ARM_MATH_CM4)
|
#if defined (ARM_MATH_CM4)
|
||||||
#include "core_cm4.h"
|
#include <cmsis/core_cm4.h>
|
||||||
#elif defined (ARM_MATH_CM3)
|
#elif defined (ARM_MATH_CM3)
|
||||||
#include "core_cm3.h"
|
#include "core_cm3.h"
|
||||||
#elif defined (ARM_MATH_CM0)
|
#elif defined (ARM_MATH_CM0)
|
||||||
@ -282,8 +282,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef __CMSIS_GENERIC /* enable NVIC and Systick functions */
|
#undef __CMSIS_GENERIC /* enable NVIC and Systick functions */
|
||||||
#include "string.h"
|
#include <string.h>
|
||||||
#include "math.h"
|
#include <math.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __HELPER_MACROS_H__
|
#ifndef __HELPER_MACROS_H__
|
||||||
#define __HELPER_MACROS_H__
|
#define __HELPER_MACROS_H__
|
||||||
|
|
||||||
@ -11,4 +31,7 @@
|
|||||||
|
|
||||||
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
|
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
|
||||||
|
|
||||||
|
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
|
||||||
#endif /* __HELPER_MACROS_H__ */
|
#endif /* __HELPER_MACROS_H__ */
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __ADCMEAS_H__
|
#ifndef __ADCMEAS_H__
|
||||||
#define __ADCMEAS_H__
|
#define __ADCMEAS_H__
|
||||||
|
|
||||||
@ -39,7 +59,7 @@
|
|||||||
*/
|
*/
|
||||||
#define ADC_PT1000_UPPER_WATCHDOG 4000U
|
#define ADC_PT1000_UPPER_WATCHDOG 4000U
|
||||||
|
|
||||||
enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1)};
|
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)};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function sets up the ADC measurement fo the external PT1000 temperature sensor
|
* @brief This function sets up the ADC measurement fo the external PT1000 temperature sensor
|
||||||
@ -102,16 +122,12 @@ int adc_pt1000_get_current_resistance(float *resistance);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stream the raw ADC data to an array in memory.
|
* @brief Stream the raw ADC data to an array in memory.
|
||||||
*
|
|
||||||
* Streaming is done using DMA2 Stream0.
|
|
||||||
* This function is used for gathering fullspeed sampling data for external interfaces or calibration
|
|
||||||
*
|
|
||||||
* @param adc_array Array to stream data to
|
* @param adc_array Array to stream data to
|
||||||
* @param length Amount of data points to be measured
|
* @param length Amount of data points to be measured
|
||||||
* @param flag_to_set This flag is set to 1 once the data has been measured and is transferred. A negative value indicates an error
|
* @param flag_to_set This flag is set to 1 once the data has been measured and is transferred. A negative value indicates an error
|
||||||
* @return 0 if measurement could be started
|
* @return 0 if measurement could be started
|
||||||
*/
|
*/
|
||||||
int adc_pt1000_stream_raw_value_to_memory(float *adc_array, uint32_t length, volatile uint8_t *flag_to_set);
|
int adc_pt1000_stream_raw_value_to_memory(volatile float *adc_array, uint32_t length, volatile int *flag_to_set);
|
||||||
|
|
||||||
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count);
|
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count);
|
||||||
|
|
||||||
|
36
stm-firmware/include/reflow-controller/calibration.h
Normal file
36
stm-firmware/include/reflow-controller/calibration.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __CALIBRATION_H__
|
||||||
|
#define __CALIBRATION_H__
|
||||||
|
|
||||||
|
#define CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM 8.0f
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <shellmatta.h>
|
||||||
|
|
||||||
|
void calibration_calculate(float low_measured, float low_setpoint, float high_measured, float high_setpoint,
|
||||||
|
float *sens_deviation, float *sens_corrected_offset);
|
||||||
|
|
||||||
|
int calibration_acquire_data(float *mu, float *max_dev, uint32_t count);
|
||||||
|
|
||||||
|
int calibration_sequence_shell_cmd(shellmatta_handle_t shell);
|
||||||
|
|
||||||
|
#endif /* __CALIBRATION_H__ */
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __DIGIO_H__
|
#ifndef __DIGIO_H__
|
||||||
#define __DIGIO_H__
|
#define __DIGIO_H__
|
||||||
|
|
||||||
|
42
stm-firmware/include/reflow-controller/rotary-encoder.h
Normal file
42
stm-firmware/include/reflow-controller/rotary-encoder.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __ROTARY_ENCODER_H__
|
||||||
|
#define __ROTARY_ENCODER_H__
|
||||||
|
|
||||||
|
#include <stm32/stm32f4xx.h>
|
||||||
|
|
||||||
|
#define ROTARY_ENCODER_TIMER TIM5
|
||||||
|
#define ROTARY_ENCODER_TIMER_RCC_MASK RCC_APB1ENR_TIM5EN
|
||||||
|
#define ROTARY_ENCODER_PIN1 0
|
||||||
|
#define ROTARY_ENCODER_PIN2 1
|
||||||
|
#define ROTARY_ENCODER_PORT GPIOA
|
||||||
|
#define ROTARY_ENCODER_PORT_ALTFUNC 2
|
||||||
|
#define ROTARY_ENCODER_RCC_MASK RCC_AHB1ENR_GPIOAEN
|
||||||
|
|
||||||
|
void rotary_encoder_setup(void);
|
||||||
|
|
||||||
|
uint32_t rotary_encoder_get_abs_val(void);
|
||||||
|
|
||||||
|
int32_t rotary_encoder_get_chage_val(void);
|
||||||
|
|
||||||
|
void rotary_encoder_stop(void);
|
||||||
|
|
||||||
|
#endif /* __ROTARY_ENCODER_H__ */
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __SHELL_H__
|
#ifndef __SHELL_H__
|
||||||
#define __SHELL_H__
|
#define __SHELL_H__
|
||||||
|
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file systick.h
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __SYSTICK_H__
|
#ifndef __SYSTICK_H__
|
||||||
#define __SYSTICK_H__
|
#define __SYSTICK_H__
|
||||||
|
|
||||||
|
29
stm-firmware/include/reflow-controller/temp-converter-data.h
Normal file
29
stm-firmware/include/reflow-controller/temp-converter-data.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __TEMP_CONVERTER_DATA_H__
|
||||||
|
#define __TEMP_CONVERTER_DATA_H__
|
||||||
|
|
||||||
|
#define TEMP_CONVERSION_ARRAY_DATA -0.00f,5.12f,10.25f,15.39f,20.53f,25.68f,30.84f,36.01f,41.19f,46.37f,51.57f,56.77f,61.98f,67.19f,72.42f,77.65f,82.89f,88.14f,93.40f,98.67f,103.94f,109.23f,114.52f,119.82f,125.13f,130.45f,135.77f,141.11f,146.45f,151.81f,157.17f,162.54f,167.92f,173.31f,178.71f,184.11f,189.53f,194.96f,200.39f,205.84f,211.29f,216.75f,222.22f,227.71f,233.20f,238.70f,244.21f,249.73f,255.26f,260.80f,266.35f,271.91f,277.48f,283.06f,288.65f,294.25f,299.86f,305.48f,311.11f,316.75f,322.40f
|
||||||
|
#define TEMP_CONVERSION_MIN_RES 1000
|
||||||
|
#define TEMP_CONVERSION_MAX_RES 2200
|
||||||
|
#define TEMP_CONVERSION_RES_STEP 20
|
||||||
|
|
||||||
|
#endif /* __TEMP_CONVERTER_DATA_H__ */
|
32
stm-firmware/include/reflow-controller/temp-converter.h
Normal file
32
stm-firmware/include/reflow-controller/temp-converter.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __TEMP_CONVERTER_H__
|
||||||
|
#define __TEMP_CONVERTER_H__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert PT1000 resistance to temperature in degrees celsius
|
||||||
|
* @param resistance PT1000 resistance value
|
||||||
|
* @param[out] temp_out Temperature output
|
||||||
|
* @return 0 if ok, -1 if value is below conversion range, 1 if value is above conversion range,-1000 in case of pointer error
|
||||||
|
*/
|
||||||
|
int temp_converter_convert_resistance_to_temp(float resistance, float *temp_out);
|
||||||
|
|
||||||
|
#endif /* __TEMP_CONVERTER_H__ */
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __CLOCK_ENABLE_MANAGER_H__
|
#ifndef __CLOCK_ENABLE_MANAGER_H__
|
||||||
#define __CLOCK_ENABLE_MANAGER_H__
|
#define __CLOCK_ENABLE_MANAGER_H__
|
||||||
|
|
||||||
|
@ -1,3 +1,32 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file dma-ring-buffer.h
|
||||||
|
* @brief Header for DMA Ring buffer implemenation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup dma-ring-buffer DMA Ring Buffers from and to Peripherals
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __DMA_RING_BUFFER_H__
|
#ifndef __DMA_RING_BUFFER_H__
|
||||||
#define __DMA_RING_BUFFER_H__
|
#define __DMA_RING_BUFFER_H__
|
||||||
|
|
||||||
@ -5,11 +34,16 @@
|
|||||||
#include <stm32/stm32f4xx.h>
|
#include <stm32/stm32f4xx.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup dma-ring-buffer
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DMA ring buffer for data transfer from peripheral to memory
|
* @brief DMA ring buffer for data transfer from peripheral to memory
|
||||||
*/
|
*/
|
||||||
struct dma_ring_buffer_to_mem {
|
struct dma_ring_buffer_to_mem {
|
||||||
void *data_ptr; /**< @brief Ring buffer */
|
volatile void *data_ptr; /**< @brief Ring buffer */
|
||||||
size_t buffer_count; /**< @brief Size of buffer in multiples of elements */
|
size_t buffer_count; /**< @brief Size of buffer in multiples of elements */
|
||||||
DMA_Stream_TypeDef *dma; /**< @brief DMA Stream used to transfer data */
|
DMA_Stream_TypeDef *dma; /**< @brief DMA Stream used to transfer data */
|
||||||
size_t get_idx; /**< @brief Get index for SW. Indicates the next element to be read */
|
size_t get_idx; /**< @brief Get index for SW. Indicates the next element to be read */
|
||||||
@ -21,7 +55,7 @@ struct dma_ring_buffer_to_mem {
|
|||||||
* @brief DMA ring buffer for data transfer from memory to peripheral
|
* @brief DMA ring buffer for data transfer from memory to peripheral
|
||||||
*/
|
*/
|
||||||
struct dma_ring_buffer_to_periph {
|
struct dma_ring_buffer_to_periph {
|
||||||
void *src_buffer; /**< @brief Ring buffer */
|
volatile void *src_buffer; /**< @brief Ring buffer */
|
||||||
size_t buffer_count; /**< @brief Size of buffer in multiples of elements */
|
size_t buffer_count; /**< @brief Size of buffer in multiples of elements */
|
||||||
DMA_Stream_TypeDef *dma; /**< @brief DMA Stream used to transfer data */
|
DMA_Stream_TypeDef *dma; /**< @brief DMA Stream used to transfer data */
|
||||||
volatile size_t dma_get_idx_current; /**< @brief Current get index of the (not yet) running DMA Stream. */
|
volatile size_t dma_get_idx_current; /**< @brief Current get index of the (not yet) running DMA Stream. */
|
||||||
@ -44,16 +78,16 @@ struct dma_ring_buffer_to_periph {
|
|||||||
* @note The ring buffers do not have an overrun detection. You have to make sure to empty the buffer in time.
|
* @note The ring buffers do not have an overrun detection. You have to make sure to empty the buffer in time.
|
||||||
* @return Status (0 is ok)
|
* @return Status (0 is ok)
|
||||||
*/
|
*/
|
||||||
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, void *src_reg, uint8_t dma_trigger_channel);
|
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, void *src_reg, uint8_t dma_trigger_channel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get data from a peripheral to memory ring buffer
|
* @brief Get data from a peripheral to memory ring buffer
|
||||||
* @param[in] buff Ring buffer structure
|
* @param[in] buff Ring buffer structure
|
||||||
* @param[out] data_buff Pointer to set to new data. This must not be modified!
|
* @param[out] data_buff Pointer to set to new data. This must not be modified!
|
||||||
* @param[out] len Length in elements
|
* @param[out] len Length in elements
|
||||||
* @return 0 if successful (data, no data), -1 if error, and 1 if data with wrap around. Call function again in this case to retrieve rest after wrap around.
|
* @return 0 if successful, but no data), -1 if error, 1 if data, and 2 if data with wrap around. Call function again in this case to retrieve rest after wrap around.
|
||||||
*/
|
*/
|
||||||
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const void **data_buff, size_t *len);
|
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const volatile void **data_buff, size_t *len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stop the ring buffer operation.
|
* @brief Stop the ring buffer operation.
|
||||||
@ -74,7 +108,7 @@ void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff);
|
|||||||
* @param[in] dest_reg Destination register to stream data to
|
* @param[in] dest_reg Destination register to stream data to
|
||||||
* @return 0 if successful
|
* @return 0 if successful
|
||||||
*/
|
*/
|
||||||
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg);
|
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Insert data into the ring buffer
|
* @brief Insert data into the ring buffer
|
||||||
@ -104,6 +138,8 @@ void dma_ring_buffer_mem_to_periph_int_callback(struct dma_ring_buffer_to_periph
|
|||||||
*/
|
*/
|
||||||
void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff);
|
void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff);
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
#endif /* __DMA_RING_BUFFER_H__ */
|
#endif /* __DMA_RING_BUFFER_H__ */
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __STM32GPIOMACROS_H__
|
#ifndef __STM32GPIOMACROS_H__
|
||||||
#define __STM32GPIOMACROS_H__
|
#define __STM32GPIOMACROS_H__
|
||||||
|
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 __UNIQUE_ID_H__
|
#ifndef __UNIQUE_ID_H__
|
||||||
#define __UNIQUE_ID_H__
|
#define __UNIQUE_ID_H__
|
||||||
|
|
||||||
|
@ -1,3 +1,28 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file main.c
|
||||||
|
* @brief Main file for firmware
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
/* #include <arm_math.h> */
|
/* #include <arm_math.h> */
|
||||||
@ -8,6 +33,7 @@
|
|||||||
#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/digio.h>
|
#include <reflow-controller/digio.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>
|
||||||
#include <stm-periph/uart.h>
|
#include <stm-periph/uart.h>
|
||||||
@ -25,12 +51,15 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const char *uart_input;
|
const char *uart_input;
|
||||||
size_t uart_input_len;
|
size_t uart_input_len;
|
||||||
shellmatta_handle_t shell_handle;
|
shellmatta_handle_t shell_handle;
|
||||||
|
int uart_receive_status;
|
||||||
|
|
||||||
setup_nvic_priorities();
|
setup_nvic_priorities();
|
||||||
systick_setup();
|
systick_setup();
|
||||||
@ -40,6 +69,7 @@ int main()
|
|||||||
digio_setup_default_all();
|
digio_setup_default_all();
|
||||||
led_setup();
|
led_setup();
|
||||||
loudspeaker_setup();
|
loudspeaker_setup();
|
||||||
|
rotary_encoder_setup();
|
||||||
|
|
||||||
uart_init_with_dma();
|
uart_init_with_dma();
|
||||||
|
|
||||||
@ -47,11 +77,10 @@ int main()
|
|||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
||||||
|
rot = rotary_encoder_get_abs_val();
|
||||||
if (uart_receive_data_with_dma(&uart_input, &uart_input_len) >= 0) {
|
uart_receive_status = uart_receive_data_with_dma(&uart_input, &uart_input_len);
|
||||||
|
if (uart_receive_status >= 1)
|
||||||
shell_handle_input(shell_handle, uart_input, uart_input_len);
|
shell_handle_input(shell_handle, uart_input, uart_input_len);
|
||||||
}
|
|
||||||
//systick_wait_ms(300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
8
stm-firmware/program-device.gdb
Normal file
8
stm-firmware/program-device.gdb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
target extended-remote :2331
|
||||||
|
monitor speed 4000
|
||||||
|
monitor reset
|
||||||
|
load
|
||||||
|
monitor reset
|
||||||
|
kill
|
||||||
|
quit
|
||||||
|
|
18
stm-firmware/program-device.sh
Executable file
18
stm-firmware/program-device.sh
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
JLinkGDBServer -if SWD -device STM32F407VE &
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# Check if GDB server is still running
|
||||||
|
gdbpid=`pidof JLinkGDBServer`
|
||||||
|
|
||||||
|
if [[ $gdbpid == "" ]]; then
|
||||||
|
echo ""
|
||||||
|
echo "GDB Server not running! Check target connection."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
arm-none-eabi-gdb -x program-device.gdb reflow-controller.elf
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
kill $gdbpid
|
78
stm-firmware/rotary-encoder.c
Normal file
78
stm-firmware/rotary-encoder.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/rotary-encoder.h>
|
||||||
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
|
#include <stm-periph/stm32-gpio-macros.h>
|
||||||
|
|
||||||
|
static inline void rotary_encoder_setup_pins(void)
|
||||||
|
{
|
||||||
|
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
|
||||||
|
ROTARY_ENCODER_PORT->MODER &= MODER_DELETE(ROTARY_ENCODER_PIN1) & MODER_DELETE(ROTARY_ENCODER_PIN2);
|
||||||
|
ROTARY_ENCODER_PORT->MODER |= ALTFUNC(ROTARY_ENCODER_PIN1) | ALTFUNC(ROTARY_ENCODER_PIN2);
|
||||||
|
SETAF(ROTARY_ENCODER_PORT, ROTARY_ENCODER_PIN1, ROTARY_ENCODER_PORT_ALTFUNC);
|
||||||
|
SETAF(ROTARY_ENCODER_PORT, ROTARY_ENCODER_PIN2, ROTARY_ENCODER_PORT_ALTFUNC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rotary_encoder_setup(void)
|
||||||
|
{
|
||||||
|
rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_TIMER_RCC_MASK));
|
||||||
|
rotary_encoder_setup_pins();
|
||||||
|
|
||||||
|
ROTARY_ENCODER_TIMER->ARR = 0xFFFF;
|
||||||
|
ROTARY_ENCODER_TIMER->CNT = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->CR2 = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->SMCR = TIM_SMCR_SMS_0 | TIM_SMCR_SMS_1;
|
||||||
|
ROTARY_ENCODER_TIMER->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
|
||||||
|
ROTARY_ENCODER_TIMER->CCER = TIM_CCER_CC1P | TIM_CCER_CC2P;
|
||||||
|
ROTARY_ENCODER_TIMER->PSC = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->CR1 = TIM_CR1_CEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t rotary_encoder_get_abs_val(void)
|
||||||
|
{
|
||||||
|
return (uint32_t)ROTARY_ENCODER_TIMER->CNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t rotary_encoder_get_chage_val(void)
|
||||||
|
{
|
||||||
|
static uint32_t last_val = 0;
|
||||||
|
uint32_t val;
|
||||||
|
int32_t diff;
|
||||||
|
|
||||||
|
val = rotary_encoder_get_abs_val();
|
||||||
|
|
||||||
|
diff = val - last_val;
|
||||||
|
|
||||||
|
if (diff > 0xEFFF) {
|
||||||
|
diff = 0xFFFF - diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rotary_encoder_stop(void)
|
||||||
|
{
|
||||||
|
ROTARY_ENCODER_TIMER->CR1 = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->CR2 = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->ARR = 0;
|
||||||
|
rcc_manager_disable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_TIMER_RCC_MASK));
|
||||||
|
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
|
||||||
|
}
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/shell.h>
|
#include <reflow-controller/shell.h>
|
||||||
#include <stm-periph/uart.h>
|
#include <stm-periph/uart.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -7,6 +27,8 @@
|
|||||||
#include <helper-macros/helper-macros.h>
|
#include <helper-macros/helper-macros.h>
|
||||||
#include <reflow-controller/systick.h>
|
#include <reflow-controller/systick.h>
|
||||||
#include <stm-periph/unique-id.h>
|
#include <stm-periph/unique-id.h>
|
||||||
|
#include <reflow-controller/calibration.h>
|
||||||
|
#include <reflow-controller/temp-converter.h>
|
||||||
|
|
||||||
#ifndef GIT_VER
|
#ifndef GIT_VER
|
||||||
#define GIT_VER "VERSION NOT SET"
|
#define GIT_VER "VERSION NOT SET"
|
||||||
@ -103,25 +125,46 @@ static shellmatta_retCode_t shell_cmd_pt1000_res(const shellmatta_handle_t han
|
|||||||
(void)length;
|
(void)length;
|
||||||
float resistance;
|
float resistance;
|
||||||
int pt1000_status;
|
int pt1000_status;
|
||||||
const char *display_status;
|
|
||||||
enum adc_pt1000_error pt1000_flags;
|
enum adc_pt1000_error pt1000_flags;
|
||||||
const char *status_text[] = {"VALID", "WATCHDOG", "DATA-OVERFLOW", "UNSTABLE"};
|
char display_status[100];
|
||||||
|
float temp;
|
||||||
|
int temp_conv_status;
|
||||||
|
const char *temp_prefix;
|
||||||
|
|
||||||
|
display_status[0] = 0;
|
||||||
|
|
||||||
display_status = status_text[0];
|
|
||||||
pt1000_status = adc_pt1000_get_current_resistance(&resistance);
|
pt1000_status = adc_pt1000_get_current_resistance(&resistance);
|
||||||
|
|
||||||
if (pt1000_status == 2) {
|
if (pt1000_status == 2) {
|
||||||
display_status = status_text[3];
|
strcat(display_status, " UNSTABLE ");
|
||||||
} else if (pt1000_status) {
|
} else if (pt1000_status) {
|
||||||
pt1000_flags = adc_pt1000_check_error();
|
pt1000_flags = adc_pt1000_check_error();
|
||||||
if (pt1000_flags & ADC_PT1000_WATCHDOG_ERROR)
|
if (pt1000_flags & ADC_PT1000_INACTIVE)
|
||||||
display_status = status_text[1];
|
strcat(display_status, " DEACTIVATED ");
|
||||||
|
else if (pt1000_flags & ADC_PT1000_WATCHDOG_ERROR)
|
||||||
|
strcat(display_status, " WATCHDOG ");
|
||||||
else if (pt1000_flags & ADC_PT1000_OVERFLOW)
|
else if (pt1000_flags & ADC_PT1000_OVERFLOW)
|
||||||
display_status = status_text[2];
|
strcat(display_status, " OVERFLOW ");
|
||||||
|
} else {
|
||||||
|
strcpy(display_status, "VALID");
|
||||||
}
|
}
|
||||||
|
|
||||||
shellmatta_printf(handle, "PT1000 resistance: %.2f Ohm [%s]\r\n", resistance, display_status);
|
temp_conv_status = temp_converter_convert_resistance_to_temp(resistance, &temp);
|
||||||
|
switch (temp_conv_status) {
|
||||||
|
case 1:
|
||||||
|
temp_prefix = ">";
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
temp_prefix = "<";
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
/* FALLTHRU */
|
||||||
|
default:
|
||||||
|
temp_prefix = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
shellmatta_printf(handle, "PT1000 resistance: %.2f Ohm (%s%.1f °C) [%s]\r\n", resistance, temp_prefix,temp, display_status);
|
||||||
|
|
||||||
return SHELLMATTA_OK;
|
return SHELLMATTA_OK;
|
||||||
}
|
}
|
||||||
@ -147,6 +190,17 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
|
|||||||
shellmatta_printf(handle, "Uptime: %llu secs", global_tick_ms/1000);
|
shellmatta_printf(handle, "Uptime: %llu secs", global_tick_ms/1000);
|
||||||
return SHELLMATTA_OK;
|
return SHELLMATTA_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
|
||||||
|
const char *arguments,
|
||||||
|
uint32_t length)
|
||||||
|
{
|
||||||
|
(void)arguments;
|
||||||
|
(void)length;
|
||||||
|
|
||||||
|
calibration_sequence_shell_cmd(handle);
|
||||||
|
return SHELLMATTA_OK;
|
||||||
|
}
|
||||||
//typedef struct shellmatta_cmd
|
//typedef struct shellmatta_cmd
|
||||||
//{
|
//{
|
||||||
// char *cmd; /**< command name */
|
// char *cmd; /**< command name */
|
||||||
@ -157,7 +211,7 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
|
|||||||
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
||||||
//} shellmatta_cmd_t;
|
//} shellmatta_cmd_t;
|
||||||
|
|
||||||
static shellmatta_cmd_t cmd[6] = {
|
static shellmatta_cmd_t cmd[7] = {
|
||||||
{
|
{
|
||||||
.cmd = "version",
|
.cmd = "version",
|
||||||
.cmdAlias = "ver",
|
.cmdAlias = "ver",
|
||||||
@ -204,8 +258,16 @@ static shellmatta_cmd_t cmd[6] = {
|
|||||||
.helpText = "Get uptime in seconds",
|
.helpText = "Get uptime in seconds",
|
||||||
.usageText = "",
|
.usageText = "",
|
||||||
.cmdFct = shell_cmd_uptime,
|
.cmdFct = shell_cmd_uptime,
|
||||||
.next = NULL,
|
.next = &cmd[6],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.cmd = "calibrate",
|
||||||
|
.cmdAlias = "cal",
|
||||||
|
.helpText = "Calibrate resistance measurement",
|
||||||
|
.usageText = "",
|
||||||
|
.cmdFct = shell_cmd_cal,
|
||||||
|
.next = NULL,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
shellmatta_handle_t shell_init(void)
|
shellmatta_handle_t shell_init(void)
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 <stm-periph/clock-enable-manager.h>
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
#include <helper-macros/helper-macros.h>
|
#include <helper-macros/helper-macros.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -1,3 +1,33 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file dma-ring-buffer.c
|
||||||
|
* @brief DMA Ring buffer implemenation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup dma-ring-buffer
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stm-periph/dma-ring-buffer.h>
|
#include <stm-periph/dma-ring-buffer.h>
|
||||||
#include <stm-periph/clock-enable-manager.h>
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -30,7 +60,7 @@ static int dma_ring_buffer_switch_clock_enable(uint8_t base_dma, bool clk_en)
|
|||||||
|
|
||||||
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id,
|
int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_buffer, uint8_t base_dma_id,
|
||||||
DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size,
|
DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size,
|
||||||
void *data_buffer, void* src_reg, uint8_t dma_trigger_channel)
|
volatile void *data_buffer, void* src_reg, uint8_t dma_trigger_channel)
|
||||||
{
|
{
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
|
|
||||||
@ -63,7 +93,7 @@ int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const void **data_buff, size_t *len)
|
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const volatile void **data_buff, size_t *len)
|
||||||
{
|
{
|
||||||
int ret_code = 0;
|
int ret_code = 0;
|
||||||
uint32_t ndtr;
|
uint32_t ndtr;
|
||||||
@ -72,20 +102,22 @@ int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff,
|
|||||||
if (!buff || !data_buff || !len)
|
if (!buff || !data_buff || !len)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
ndtr = buff->dma->NDTR;
|
ndtr = buff->dma->NDTR;
|
||||||
put_idx = buff->buffer_count - ndtr;
|
put_idx = buff->buffer_count - ndtr;
|
||||||
|
|
||||||
/* Check if wrap around */
|
/* Check if wrap around */
|
||||||
if (put_idx < buff->get_idx) {
|
if (put_idx < buff->get_idx) {
|
||||||
|
/* Available data wraps around end of buffer: Return first part upt to the end of the ring buffer */
|
||||||
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
|
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
|
||||||
*len = buff->buffer_count - buff->get_idx;
|
*len = buff->buffer_count - buff->get_idx;
|
||||||
buff->get_idx = 0;
|
buff->get_idx = 0;
|
||||||
ret_code = 1;
|
ret_code = 2;
|
||||||
} else if (put_idx > buff->get_idx) {
|
} else if (put_idx > buff->get_idx) {
|
||||||
|
/* Data does not wrap around ring buffer. Return full data */
|
||||||
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
|
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
|
||||||
*len = put_idx - buff->get_idx;
|
*len = put_idx - buff->get_idx;
|
||||||
buff->get_idx += *len;
|
buff->get_idx += *len;
|
||||||
|
ret_code = 1;
|
||||||
} else {
|
} else {
|
||||||
/* No new data */
|
/* No new data */
|
||||||
*len = 0;
|
*len = 0;
|
||||||
@ -109,7 +141,7 @@ void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff)
|
|||||||
memset(buff, 0, sizeof(struct dma_ring_buffer_to_mem));
|
memset(buff, 0, sizeof(struct dma_ring_buffer_to_mem));
|
||||||
}
|
}
|
||||||
|
|
||||||
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg)
|
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg)
|
||||||
{
|
{
|
||||||
if (!dma_buffer || !dma_stream || !data_buffer || !dest_reg)
|
if (!dma_buffer || !dma_stream || !data_buffer || !dest_reg)
|
||||||
return -1000;
|
return -1000;
|
||||||
@ -223,7 +255,7 @@ int dma_ring_buffer_mem_to_periph_insert_data(struct dma_ring_buffer_to_periph *
|
|||||||
first_round_count = buff->element_size * (buff->buffer_count - buff->sw_put_idx);
|
first_round_count = buff->element_size * (buff->buffer_count - buff->sw_put_idx);
|
||||||
memcpy(dest_ptr, insert_ptr, first_round_count);
|
memcpy(dest_ptr, insert_ptr, first_round_count);
|
||||||
insert_ptr += first_round_count;
|
insert_ptr += first_round_count;
|
||||||
memcpy(buff->src_buffer, insert_ptr, count - first_round_count);
|
memcpy((void *)buff->src_buffer, insert_ptr, count - first_round_count);
|
||||||
|
|
||||||
/* Move put index */
|
/* Move put index */
|
||||||
buff->sw_put_idx = count - first_round_count;
|
buff->sw_put_idx = count - first_round_count;
|
||||||
@ -256,3 +288,5 @@ void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff)
|
|||||||
/* Reset the structure */
|
/* Reset the structure */
|
||||||
memset(buff, 0, sizeof(struct dma_ring_buffer_to_periph));
|
memset(buff, 0, sizeof(struct dma_ring_buffer_to_periph));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 <stm-periph/uart.h>
|
#include <stm-periph/uart.h>
|
||||||
#include <stm32/stm32f4xx.h>
|
#include <stm32/stm32f4xx.h>
|
||||||
#include <stm-periph/clock-enable-manager.h>
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
@ -87,7 +107,7 @@ void uart_send_string_with_dma(const char *string)
|
|||||||
|
|
||||||
int uart_receive_data_with_dma(const char **data, size_t *len)
|
int uart_receive_data_with_dma(const char **data, size_t *len)
|
||||||
{
|
{
|
||||||
return dma_ring_buffer_periph_to_mem_get_data(&ring_buff_rx, (const void **)data, len);
|
return dma_ring_buffer_periph_to_mem_get_data(&ring_buff_rx, (const volatile void **)data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMA2_Stream7_IRQHandler()
|
void DMA2_Stream7_IRQHandler()
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 <stm-periph/unique-id.h>
|
#include <stm-periph/unique-id.h>
|
||||||
|
|
||||||
#define LOW_WORD_ADDR (0x1FFF7A10UL)
|
#define LOW_WORD_ADDR (0x1FFF7A10UL)
|
||||||
|
@ -36,8 +36,8 @@ ENTRY(Reset_Handler)
|
|||||||
_estack = 0x20020000; /* end of 128K RAM on AHB bus*/
|
_estack = 0x20020000; /* end of 128K RAM on AHB bus*/
|
||||||
|
|
||||||
/* Generate a link error if heap and stack don't fit into RAM */
|
/* Generate a link error if heap and stack don't fit into RAM */
|
||||||
_Min_Heap_Size = 0x1500; /* required amount of heap (DEFAULT 0) */
|
_Min_Heap_Size = 0x2100; /* required amount of heap (DEFAULT 0) */
|
||||||
_Min_Stack_Size = 0x2000 ; /* required amount of stack */
|
_Min_Stack_Size = 0x3000 ; /* required amount of stack */
|
||||||
/* recommended min stack size for printf=0x2000, orig = 0x400 */
|
/* recommended min stack size for printf=0x2000, orig = 0x400 */
|
||||||
|
|
||||||
/* Specify the memory areas */
|
/* Specify the memory areas */
|
||||||
@ -162,14 +162,14 @@ SECTIONS
|
|||||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||||
._user_heap_stack (NOLOAD):
|
._user_heap_stack (NOLOAD):
|
||||||
{
|
{
|
||||||
. = ALIGN(4);
|
. = ALIGN(8);
|
||||||
PROVIDE (heap_low = .); /* for _sbrk */
|
PROVIDE (heap_low = .); /* for _sbrk */
|
||||||
PROVIDE ( end = . );
|
PROVIDE ( end = . );
|
||||||
PROVIDE ( _end = . );
|
PROVIDE ( _end = . );
|
||||||
. = . + _Min_Heap_Size;
|
. = . + _Min_Heap_Size;
|
||||||
PROVIDE (heap_top = .); /* for _sbrk */
|
PROVIDE (heap_top = .); /* for _sbrk */
|
||||||
. = . + _Min_Stack_Size;
|
. = . + _Min_Stack_Size;
|
||||||
. = ALIGN(4);
|
. = ALIGN(8);
|
||||||
} >RAM
|
} >RAM
|
||||||
|
|
||||||
/* MEMORY_bank1 section, code must be located here explicitly */
|
/* MEMORY_bank1 section, code must be located here explicitly */
|
||||||
|
@ -1,4 +1,28 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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 <stm-periph/uart.h>
|
#include <stm-periph/uart.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
char* _sbrk(int incr)
|
char* _sbrk(int incr)
|
||||||
{
|
{
|
||||||
@ -12,12 +36,16 @@ char* _sbrk(int incr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
prev_heap_end = heap_end;
|
prev_heap_end = heap_end;
|
||||||
|
|
||||||
|
|
||||||
if (heap_end + incr > &heap_top) {
|
if (heap_end + incr > &heap_top) {
|
||||||
return 0;
|
errno = ENOMEM;
|
||||||
|
return (char *)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
heap_end += incr;
|
heap_end += incr;
|
||||||
return (char*) prev_heap_end;
|
|
||||||
|
return (char *) prev_heap_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _isatty(int fd)
|
int _isatty(int fd)
|
||||||
@ -59,6 +87,6 @@ int _read(void)
|
|||||||
int _write(int fd, const void *buf, int count)
|
int _write(int fd, const void *buf, int count)
|
||||||
{
|
{
|
||||||
if (fd == 1)
|
if (fd == 1)
|
||||||
uart_send_array((char*)buf, count);
|
uart_send_array_with_dma((char*)buf, count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file systick.c
|
||||||
|
*/
|
||||||
|
|
||||||
#include <reflow-controller/systick.h>
|
#include <reflow-controller/systick.h>
|
||||||
#include <stm32/stm32f4xx.h>
|
#include <stm32/stm32f4xx.h>
|
||||||
#include <cmsis/core_cm4.h>
|
#include <cmsis/core_cm4.h>
|
||||||
@ -11,14 +35,6 @@ void systick_setup(void)
|
|||||||
SysTick_Config(SYSTICK_RELOAD);
|
SysTick_Config(SYSTICK_RELOAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Wait for x milliseconds
|
|
||||||
*
|
|
||||||
* This function is not reentrant and must not be called from an interrupt
|
|
||||||
*
|
|
||||||
* @warning Do not use in interrupt context
|
|
||||||
* @param ms wait time in ms
|
|
||||||
*/
|
|
||||||
void systick_wait_ms(uint32_t ms)
|
void systick_wait_ms(uint32_t ms)
|
||||||
{
|
{
|
||||||
wait_tick_ms = 0UL;
|
wait_tick_ms = 0UL;
|
||||||
|
75
stm-firmware/temp-converter.c
Normal file
75
stm-firmware/temp-converter.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* GDSII-Converter 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/temp-converter.h>
|
||||||
|
#include <reflow-controller/temp-converter-data.h>
|
||||||
|
#include <helper-macros/helper-macros.h>
|
||||||
|
|
||||||
|
static const float temp_lookup[(TEMP_CONVERSION_MAX_RES-TEMP_CONVERSION_MIN_RES) / TEMP_CONVERSION_RES_STEP+1] = {TEMP_CONVERSION_ARRAY_DATA};
|
||||||
|
|
||||||
|
int temp_converter_convert_resistance_to_temp(float resistance, float *temp_out)
|
||||||
|
{
|
||||||
|
int ret_val;
|
||||||
|
unsigned int i;
|
||||||
|
unsigned int lower_idx = COUNT_OF(temp_lookup) - 1;
|
||||||
|
float diff_to_low_resistance;
|
||||||
|
float diff_high_low;
|
||||||
|
float low;
|
||||||
|
|
||||||
|
/* Check pointer */
|
||||||
|
if (!temp_out)
|
||||||
|
return -1000;
|
||||||
|
|
||||||
|
if (resistance < TEMP_CONVERSION_MIN_RES) {
|
||||||
|
*temp_out = temp_lookup[0];
|
||||||
|
ret_val = -1;
|
||||||
|
goto return_ret_val;
|
||||||
|
} else if (resistance > TEMP_CONVERSION_MAX_RES) {
|
||||||
|
*temp_out = temp_lookup[COUNT_OF(temp_lookup)-1];
|
||||||
|
ret_val = 1;
|
||||||
|
goto return_ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Resistance is in range */
|
||||||
|
ret_val = 0;
|
||||||
|
|
||||||
|
/* Calculate lower index for given reistance */
|
||||||
|
for (i = 1; i < COUNT_OF(temp_lookup); i++) {
|
||||||
|
if (resistance <= TEMP_CONVERSION_MIN_RES + TEMP_CONVERSION_RES_STEP * i) {
|
||||||
|
lower_idx = i - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the lower temperature limit of the current range */
|
||||||
|
low = temp_lookup[lower_idx];
|
||||||
|
|
||||||
|
/* Difference to higher limit */
|
||||||
|
diff_high_low = temp_lookup[lower_idx+1] - low;
|
||||||
|
|
||||||
|
/* Resistance difference to lower limit's resistance value */
|
||||||
|
diff_to_low_resistance = resistance - (float)(TEMP_CONVERSION_MIN_RES + TEMP_CONVERSION_RES_STEP * lower_idx);
|
||||||
|
|
||||||
|
/* Calculate output temperature */
|
||||||
|
*temp_out = (diff_to_low_resistance / TEMP_CONVERSION_RES_STEP) * diff_high_low + low;
|
||||||
|
|
||||||
|
return_ret_val:
|
||||||
|
return ret_val;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user