Add deactivated PT1000 measurement as error flag, startcode for calibration routine
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include <reflow-controller/adc-meas.h>
|
||||
#include <reflow-controller/adc-meas.h>
|
||||
#include <stm32/stm32f4xx.h>
|
||||
#include <cmsis/core_cm4.h>
|
||||
#include <stm-periph/stm32-gpio-macros.h>
|
||||
@@ -11,13 +11,16 @@ static bool calibration_active;
|
||||
static float filter_alpha;
|
||||
static volatile float pt1000_res_raw_lf;
|
||||
static volatile bool filter_ready;
|
||||
static volatile enum adc_pt1000_error pt1000_error;
|
||||
static volatile uint8_t * volatile streaming_flag_ptr = NULL;
|
||||
static volatile enum adc_pt1000_error pt1000_error = ADC_PT1000_INACTIVE;
|
||||
static volatile int * volatile streaming_flag_ptr = NULL;
|
||||
static uint32_t filter_startup_cnt;
|
||||
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];
|
||||
|
||||
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)
|
||||
|
||||
static inline void adc_pt1000_stop_sample_frequency_timer()
|
||||
@@ -49,7 +52,7 @@ static inline void adc_pt1000_disable_adc()
|
||||
ADC1->CR2 &= ~ADC_CR2_ADON;
|
||||
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->AHB1ENR, BITMASK_TO_BITNO(ADC_PT1000_PORT_RCC_MASK));
|
||||
@@ -88,7 +91,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
|
||||
*/
|
||||
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()
|
||||
@@ -142,7 +145,7 @@ void adc_pt1000_setup_meas()
|
||||
|
||||
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)
|
||||
@@ -201,17 +204,40 @@ return_value:
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/*
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
@@ -220,7 +246,7 @@ enum adc_pt1000_error adc_pt1000_check_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()
|
||||
@@ -231,6 +257,7 @@ void adc_pt1000_disable()
|
||||
|
||||
filter_ready = false;
|
||||
pt1000_res_raw_lf = 0.0f;
|
||||
pt1000_error |= ADC_PT1000_INACTIVE;
|
||||
|
||||
if (streaming_flag_ptr) {
|
||||
*streaming_flag_ptr = -3;
|
||||
@@ -283,10 +310,6 @@ void ADC_IRQHandler(void)
|
||||
pt1000_error |= ADC_PT1000_OVERFLOW;
|
||||
/* Disable ADC in case of overrrun*/
|
||||
adc_pt1000_disable();
|
||||
if (streaming_flag_ptr) {
|
||||
*streaming_flag_ptr = -1;
|
||||
streaming_flag_ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (adc1_sr & ADC_SR_AWD) {
|
||||
@@ -295,6 +318,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()
|
||||
{
|
||||
uint32_t lisr;
|
||||
@@ -308,13 +346,15 @@ void DMA2_Stream0_IRQHandler()
|
||||
adc_val = adc_pt1000_dma_avg_pre_filter();
|
||||
adc_pt1000_raw_reading_hf = adc_val;
|
||||
|
||||
if (streaming_flag_ptr)
|
||||
append_stream_buffer(adc_val);
|
||||
|
||||
/* Call moving average filter */
|
||||
adc_pt1000_filter(adc_val);
|
||||
}
|
||||
|
||||
if (lisr & DMA_LISR_TEIF0) {
|
||||
/* Wait for watchdog to kick in */
|
||||
while(1);
|
||||
adc_pt1000_disable();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user